]> git.lizzy.rs Git - rust.git/commitdiff
Remove built-in derive macros `Send` and `Sync`
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 23 Jun 2019 12:14:04 +0000 (15:14 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 23 Jun 2019 12:33:39 +0000 (15:33 +0300)
src/librustc_resolve/macros.rs
src/libsyntax_ext/deriving/bounds.rs
src/libsyntax_ext/deriving/mod.rs
src/test/ui/derives/deriving-bounds.rs
src/test/ui/derives/deriving-bounds.stderr
src/test/ui/issues/issue-33571.rs
src/test/ui/issues/issue-33571.stderr

index 5623016c2e5e7e988b50879cd3e73cf065ac87ba..392a46a262f5038c2b59e0dcfebf7c1f137678ef 100644 (file)
@@ -1022,6 +1022,12 @@ fn prohibit_imported_non_macro_attrs(&self, binding: Option<&'a NameBinding<'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(
index c7b805e0bdca6bf0dd8f23bf89760f4c83e6f359..d5b8a00c75b834ad8862ba66c0d4a2adc99eca66 100644 (file)
@@ -6,14 +6,6 @@
 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,
index e75eff2e85714a48e4ea71778d11ab3fccde832b..aa9913d436cfa81afc3bc77c9f61afaac46b860a 100644 (file)
@@ -111,8 +111,6 @@ pub fn register_builtin_derives(resolver: &mut dyn Resolver, edition: Edition) {
 
     "Default" => default::expand_deriving_default,
 
-    "Send" => bounds::expand_deriving_unsafe_bound,
-    "Sync" => bounds::expand_deriving_unsafe_bound,
     "Copy" => bounds::expand_deriving_copy,
 
     // deprecated
index 607cfa1bb2cd78d2f836636cc324890927cebd61..52659bd11e0808cf090d2fa33fd427a45a881e7a 100644 (file)
@@ -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() {}
index deb84fd99bd2a339e4add5a527e3089f1b7369f7..99976da72da1d5adaeb57940b08ee554f41f3015 100644 (file)
@@ -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)]
index 223bbc3ff5e2190f35519ca5b3ee1665fe1f9fbc..147fb3fa8cf330bd527e56b9a39da7b557aabb2d 100644 (file)
@@ -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 {}
 
index 5d83a08e9075748b37a5c9e72f5de12b393ab04a..78e7202077498ee7b01967e62d73e5f55fa7563e 100644 (file)
@@ -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,