about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-12-22 06:03:19 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-12-23 05:49:34 +0000
commitc12fc66a9d643a6942d0bf4175d1a046e8d808de (patch)
treea0b9495755b4ffbcc95f2d8b603b7ee355873166
parent164619a8cfe6d376d25bd3a6a9a5f2856c8de64d (diff)
downloadrust-c12fc66a9d643a6942d0bf4175d1a046e8d808de.tar.gz
rust-c12fc66a9d643a6942d0bf4175d1a046e8d808de.zip
Allow legacy custom derive authors to disable warnings in downstream crates.
-rw-r--r--src/librustc_driver/driver.rs2
-rw-r--r--src/librustc_plugin/registry.rs18
-rw-r--r--src/librustc_resolve/lib.rs2
-rw-r--r--src/librustc_resolve/macros.rs4
-rw-r--r--src/libsyntax/ext/base.rs2
-rw-r--r--src/libsyntax_ext/deriving/mod.rs4
-rw-r--r--src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin.rs2
7 files changed, 32 insertions, 2 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs
index 360933c6b66..8da9a23f4fa 100644
--- a/src/librustc_driver/driver.rs
+++ b/src/librustc_driver/driver.rs
@@ -592,6 +592,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
         }
     });
 
+    let whitelisted_legacy_custom_derives = registry.take_whitelisted_custom_derives();
     let Registry { syntax_exts, early_lint_passes, late_lint_passes, lint_groups,
                    llvm_passes, attributes, mir_passes, .. } = registry;
 
@@ -631,6 +632,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
     let resolver_arenas = Resolver::arenas();
     let mut resolver =
         Resolver::new(sess, &krate, make_glob_map, &mut crate_loader, &resolver_arenas);
+    resolver.whitelisted_legacy_custom_derives = whitelisted_legacy_custom_derives;
     syntax_ext::register_builtins(&mut resolver, syntax_exts, sess.features.borrow().quote);
 
     krate = time(time_passes, "expansion", || {
diff --git a/src/librustc_plugin/registry.rs b/src/librustc_plugin/registry.rs
index fe2f9713d1b..3700d0295e9 100644
--- a/src/librustc_plugin/registry.rs
+++ b/src/librustc_plugin/registry.rs
@@ -64,6 +64,8 @@ pub struct Registry<'a> {
 
     #[doc(hidden)]
     pub attributes: Vec<(String, AttributeType)>,
+
+    whitelisted_custom_derives: Vec<ast::Name>,
 }
 
 impl<'a> Registry<'a> {
@@ -80,6 +82,7 @@ impl<'a> Registry<'a> {
             llvm_passes: vec![],
             attributes: vec![],
             mir_passes: Vec::new(),
+            whitelisted_custom_derives: Vec::new(),
         }
     }
 
@@ -115,6 +118,21 @@ impl<'a> Registry<'a> {
         }));
     }
 
+    /// This can be used in place of `register_syntax_extension` to register legacy custom derives
+    /// (i.e. attribute syntax extensions whose name begins with `derive_`). Legacy custom
+    /// derives defined by this function do not trigger deprecation warnings when used.
+    #[unstable(feature = "rustc_private", issue = "27812")]
+    #[rustc_deprecated(since = "1.15.0", reason = "replaced by macros 1.1 (RFC 1861)")]
+    pub fn register_custom_derive(&mut self, name: ast::Name, extension: SyntaxExtension) {
+        assert!(name.as_str().starts_with("derive_"));
+        self.whitelisted_custom_derives.push(name);
+        self.register_syntax_extension(name, extension);
+    }
+
+    pub fn take_whitelisted_custom_derives(&mut self) -> Vec<ast::Name> {
+        ::std::mem::replace(&mut self.whitelisted_custom_derives, Vec::new())
+    }
+
     /// Register a macro of the usual kind.
     ///
     /// This is a convenience wrapper for `register_syntax_extension`.
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index f73227681c5..fa9e67bb40a 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -1111,6 +1111,7 @@ pub struct Resolver<'a> {
     lexical_macro_resolutions: Vec<(Name, &'a Cell<LegacyScope<'a>>)>,
     macro_map: FxHashMap<DefId, Rc<SyntaxExtension>>,
     macro_exports: Vec<Export>,
+    pub whitelisted_legacy_custom_derives: Vec<Name>,
 
     // Maps the `Mark` of an expansion to its containing module or block.
     invocations: FxHashMap<Mark, &'a InvocationData<'a>>,
@@ -1292,6 +1293,7 @@ impl<'a> Resolver<'a> {
             macro_exports: Vec::new(),
             invocations: invocations,
             name_already_seen: FxHashMap(),
+            whitelisted_legacy_custom_derives: Vec::new(),
         }
     }
 
diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs
index 204d1127fc4..cdff84c8b8a 100644
--- a/src/librustc_resolve/macros.rs
+++ b/src/librustc_resolve/macros.rs
@@ -123,6 +123,10 @@ impl<'a> base::Resolver for Resolver<'a> {
         EliminateCrateVar(self).fold_item(item).expect_one("")
     }
 
+    fn is_whitelisted_legacy_custom_derive(&self, name: Name) -> bool {
+        self.whitelisted_legacy_custom_derives.contains(&name)
+    }
+
     fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion) {
         let invocation = self.invocations[&mark];
         self.collect_def_ids(invocation, expansion);
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 8e63f73fdaa..68d261c64f8 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -516,6 +516,7 @@ pub trait Resolver {
     fn next_node_id(&mut self) -> ast::NodeId;
     fn get_module_scope(&mut self, id: ast::NodeId) -> Mark;
     fn eliminate_crate_var(&mut self, item: P<ast::Item>) -> P<ast::Item>;
+    fn is_whitelisted_legacy_custom_derive(&self, name: Name) -> bool;
 
     fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion);
     fn add_ext(&mut self, ident: ast::Ident, ext: Rc<SyntaxExtension>);
@@ -539,6 +540,7 @@ impl Resolver for DummyResolver {
     fn next_node_id(&mut self) -> ast::NodeId { ast::DUMMY_NODE_ID }
     fn get_module_scope(&mut self, _id: ast::NodeId) -> Mark { Mark::root() }
     fn eliminate_crate_var(&mut self, item: P<ast::Item>) -> P<ast::Item> { item }
+    fn is_whitelisted_legacy_custom_derive(&self, _name: Name) -> bool { false }
 
     fn visit_expansion(&mut self, _invoc: Mark, _expansion: &Expansion) {}
     fn add_ext(&mut self, _ident: ast::Ident, _ext: Rc<SyntaxExtension>) {}
diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs
index 535d7de19e3..0511b0d252b 100644
--- a/src/libsyntax_ext/deriving/mod.rs
+++ b/src/libsyntax_ext/deriving/mod.rs
@@ -175,8 +175,10 @@ pub fn expand_derive(cx: &mut ExtCtxt,
                                            feature_gate::GateIssue::Language,
                                            feature_gate::EXPLAIN_CUSTOM_DERIVE);
         } else {
-            cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE);
             let name = Symbol::intern(&format!("derive_{}", tname));
+            if !cx.resolver.is_whitelisted_legacy_custom_derive(name) {
+                cx.span_warn(titem.span, feature_gate::EXPLAIN_DEPR_CUSTOM_DERIVE);
+            }
             let mitem = cx.meta_word(titem.span, name);
             new_attributes.push(cx.attribute(mitem.span, mitem));
         }
diff --git a/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin.rs b/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin.rs
index 07f7d6bad7b..e46e4fb3766 100644
--- a/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin.rs
+++ b/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin.rs
@@ -31,7 +31,7 @@ use rustc_plugin::Registry;
 
 #[plugin_registrar]
 pub fn plugin_registrar(reg: &mut Registry) {
-    reg.register_syntax_extension(
+    reg.register_custom_derive(
         Symbol::intern("derive_TotalSum"),
         MultiDecorator(box expand));
 }