Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove built-in derive macros Send and Sync #62078

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,12 @@ impl<'a> Resolver<'a> {

fn suggest_macro_name(&mut self, name: Symbol, kind: MacroKind,
err: &mut DiagnosticBuilder<'a>, span: Span) {
if kind == MacroKind::Derive && (name.as_str() == "Send" || name.as_str() == "Sync") {
let msg = format!("unsafe traits like `{}` should be implemented explicitly", name);
err.span_note(span, &msg);
return;
}

// First check if this is a locally-defined bang macro.
let suggestion = if let MacroKind::Bang = kind {
find_best_match_for_name(
Expand Down
8 changes: 0 additions & 8 deletions src/libsyntax_ext/deriving/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ use syntax::ast::MetaItem;
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax_pos::Span;

pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt<'_>,
span: Span,
_: &MetaItem,
_: &Annotatable,
_: &mut dyn FnMut(Annotatable)) {
cx.span_err(span, "this unsafe trait should be implemented explicitly");
}

pub fn expand_deriving_copy(cx: &mut ExtCtxt<'_>,
span: Span,
mitem: &MetaItem,
Expand Down
2 changes: 0 additions & 2 deletions src/libsyntax_ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ derive_traits! {

"Default" => default::expand_deriving_default,

"Send" => bounds::expand_deriving_unsafe_bound,
"Sync" => bounds::expand_deriving_unsafe_bound,
"Copy" => bounds::expand_deriving_copy,

// deprecated
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/derives/deriving-bounds.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[derive(Send)]
//~^ ERROR this unsafe trait should be implemented explicitly
//~^ ERROR cannot find derive macro `Send` in this scope
struct Test;

#[derive(Sync)]
//~^ ERROR this unsafe trait should be implemented explicitly
//~^ ERROR cannot find derive macro `Sync` in this scope
struct Test1;

pub fn main() {}
16 changes: 14 additions & 2 deletions src/test/ui/derives/deriving-bounds.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
error: this unsafe trait should be implemented explicitly
error: cannot find derive macro `Send` in this scope
--> $DIR/deriving-bounds.rs:1:10
|
LL | #[derive(Send)]
| ^^^^
|
note: unsafe traits like `Send` should be implemented explicitly
--> $DIR/deriving-bounds.rs:1:10
|
LL | #[derive(Send)]
| ^^^^

error: this unsafe trait should be implemented explicitly
error: cannot find derive macro `Sync` in this scope
--> $DIR/deriving-bounds.rs:5:10
|
LL | #[derive(Sync)]
| ^^^^
|
note: unsafe traits like `Sync` should be implemented explicitly
--> $DIR/deriving-bounds.rs:5:10
|
LL | #[derive(Sync)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-33571.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[derive(Clone,
Sync, //~ ERROR this unsafe trait should be implemented explicitly
Sync, //~ ERROR cannot find derive macro `Sync` in this scope
Copy)]
enum Foo {}

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/issues/issue-33571.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
error: this unsafe trait should be implemented explicitly
error: cannot find derive macro `Sync` in this scope
--> $DIR/issue-33571.rs:2:10
|
LL | Sync,
| ^^^^
|
note: unsafe traits like `Sync` should be implemented explicitly
--> $DIR/issue-33571.rs:2:10
|
LL | Sync,
Expand Down