Skip to content

Commit e1d871e

Browse files
committed
Remove built-in derive macros Send and Sync
1 parent a96ba96 commit e1d871e

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

src/librustc_resolve/macros.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,12 @@ impl<'a> Resolver<'a> {
10221022

10231023
fn suggest_macro_name(&mut self, name: Symbol, kind: MacroKind,
10241024
err: &mut DiagnosticBuilder<'a>, span: Span) {
1025+
if kind == MacroKind::Derive && (name.as_str() == "Send" || name.as_str() == "Sync") {
1026+
let msg = format!("unsafe traits like `{}` should be implemented explicitly", name);
1027+
err.span_note(span, &msg);
1028+
return;
1029+
}
1030+
10251031
// First check if this is a locally-defined bang macro.
10261032
let suggestion = if let MacroKind::Bang = kind {
10271033
find_best_match_for_name(

src/libsyntax_ext/deriving/bounds.rs

-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ use syntax::ast::MetaItem;
66
use syntax::ext::base::{Annotatable, ExtCtxt};
77
use syntax_pos::Span;
88

9-
pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt<'_>,
10-
span: Span,
11-
_: &MetaItem,
12-
_: &Annotatable,
13-
_: &mut dyn FnMut(Annotatable)) {
14-
cx.span_err(span, "this unsafe trait should be implemented explicitly");
15-
}
16-
179
pub fn expand_deriving_copy(cx: &mut ExtCtxt<'_>,
1810
span: Span,
1911
mitem: &MetaItem,

src/libsyntax_ext/deriving/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ derive_traits! {
111111

112112
"Default" => default::expand_deriving_default,
113113

114-
"Send" => bounds::expand_deriving_unsafe_bound,
115-
"Sync" => bounds::expand_deriving_unsafe_bound,
116114
"Copy" => bounds::expand_deriving_copy,
117115

118116
// deprecated
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#[derive(Send)]
2-
//~^ ERROR this unsafe trait should be implemented explicitly
2+
//~^ ERROR cannot find derive macro `Send` in this scope
33
struct Test;
44

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

99
pub fn main() {}

src/test/ui/derives/deriving-bounds.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
error: this unsafe trait should be implemented explicitly
1+
error: cannot find derive macro `Send` in this scope
2+
--> $DIR/deriving-bounds.rs:1:10
3+
|
4+
LL | #[derive(Send)]
5+
| ^^^^
6+
|
7+
note: unsafe traits like `Send` should be implemented explicitly
28
--> $DIR/deriving-bounds.rs:1:10
39
|
410
LL | #[derive(Send)]
511
| ^^^^
612

7-
error: this unsafe trait should be implemented explicitly
13+
error: cannot find derive macro `Sync` in this scope
14+
--> $DIR/deriving-bounds.rs:5:10
15+
|
16+
LL | #[derive(Sync)]
17+
| ^^^^
18+
|
19+
note: unsafe traits like `Sync` should be implemented explicitly
820
--> $DIR/deriving-bounds.rs:5:10
921
|
1022
LL | #[derive(Sync)]

src/test/ui/issues/issue-33571.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[derive(Clone,
2-
Sync, //~ ERROR this unsafe trait should be implemented explicitly
2+
Sync, //~ ERROR cannot find derive macro `Sync` in this scope
33
Copy)]
44
enum Foo {}
55

src/test/ui/issues/issue-33571.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
error: this unsafe trait should be implemented explicitly
1+
error: cannot find derive macro `Sync` in this scope
2+
--> $DIR/issue-33571.rs:2:10
3+
|
4+
LL | Sync,
5+
| ^^^^
6+
|
7+
note: unsafe traits like `Sync` should be implemented explicitly
28
--> $DIR/issue-33571.rs:2:10
39
|
410
LL | Sync,

0 commit comments

Comments
 (0)