about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-11-12 21:22:16 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-11-16 18:50:23 +0300
commit857574379310d6ca70d3d44dbf00cc45b23e7eb8 (patch)
tree33abd72045300af1be8e887e552de21f29c3e401
parent9b0214d9c560c49e2836c8491aa21d3dbf9f5554 (diff)
downloadrust-857574379310d6ca70d3d44dbf00cc45b23e7eb8.tar.gz
rust-857574379310d6ca70d3d44dbf00cc45b23e7eb8.zip
rustc_plugin: Remove `Registry::register_attribute`
-rw-r--r--src/librustc/hir/def.rs6
-rw-r--r--src/librustc/session/mod.rs5
-rw-r--r--src/librustc_interface/passes.rs9
-rw-r--r--src/librustc_lint/unused.rs20
-rw-r--r--src/librustc_plugin/registry.rs13
-rw-r--r--src/librustc_resolve/diagnostics.rs9
-rw-r--r--src/librustc_resolve/lib.rs8
-rw-r--r--src/librustc_resolve/macros.rs7
-rw-r--r--src/test/ui-fulldeps/auxiliary/attr-plugin-test.rs3
-rw-r--r--src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs15
-rw-r--r--src/test/ui-fulldeps/issue-40001.rs5
-rw-r--r--src/test/ui-fulldeps/plugin-attr-register-deny.rs21
-rw-r--r--src/test/ui-fulldeps/plugin-attr-register-deny.stderr34
13 files changed, 12 insertions, 143 deletions
diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs
index 025494e3fd7..a1ad11580db 100644
--- a/src/librustc/hir/def.rs
+++ b/src/librustc/hir/def.rs
@@ -42,8 +42,6 @@ pub enum NonMacroAttrKind {
     DeriveHelper,
     /// Single-segment custom attribute registered with `#[register_attr]`.
     Registered,
-    /// Single-segment custom attribute registered by a legacy plugin (`register_attribute`).
-    LegacyPluginHelper,
 }
 
 #[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
@@ -330,7 +328,6 @@ impl NonMacroAttrKind {
             NonMacroAttrKind::Tool => "tool attribute",
             NonMacroAttrKind::DeriveHelper => "derive helper attribute",
             NonMacroAttrKind::Registered => "explicitly registered attribute",
-            NonMacroAttrKind::LegacyPluginHelper => "legacy plugin helper attribute",
         }
     }
 
@@ -345,8 +342,7 @@ impl NonMacroAttrKind {
     pub fn is_used(self) -> bool {
         match self {
             NonMacroAttrKind::Tool | NonMacroAttrKind::DeriveHelper => true,
-            NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered |
-            NonMacroAttrKind::LegacyPluginHelper => false,
+            NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered  => false,
         }
     }
 }
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index 4fbc8da9cbf..cfcdb234030 100644
--- a/src/librustc/session/mod.rs
+++ b/src/librustc/session/mod.rs
@@ -21,11 +21,10 @@ use errors::emitter::{Emitter, EmitterWriter};
 use errors::emitter::HumanReadableErrorType;
 use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
 use syntax::edition::Edition;
-use syntax::feature_gate::{self, AttributeType};
+use syntax::feature_gate;
 use errors::json::JsonEmitter;
 use syntax::source_map;
 use syntax::sess::{ParseSess, ProcessCfgMod};
-use syntax::symbol::Symbol;
 use syntax_pos::{MultiSpan, Span};
 
 use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple};
@@ -79,7 +78,6 @@ pub struct Session {
     /// in order to avoid redundantly verbose output (Issue #24690, #44953).
     pub one_time_diagnostics: Lock<FxHashSet<(DiagnosticMessageId, Option<Span>, String)>>,
     pub plugin_llvm_passes: OneThread<RefCell<Vec<String>>>,
-    pub plugin_attributes: Lock<Vec<(Symbol, AttributeType)>>,
     pub crate_types: Once<Vec<config::CrateType>>,
     /// The `crate_disambiguator` is constructed out of all the `-C metadata`
     /// arguments passed to the compiler. Its value together with the crate-name
@@ -1166,7 +1164,6 @@ fn build_session_(
         working_dir,
         one_time_diagnostics: Default::default(),
         plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
-        plugin_attributes: Lock::new(Vec::new()),
         crate_types: Once::new(),
         crate_disambiguator: Once::new(),
         features: Once::new(),
diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs
index 83b936dd7aa..86d58bfe8bd 100644
--- a/src/librustc_interface/passes.rs
+++ b/src/librustc_interface/passes.rs
@@ -240,15 +240,8 @@ pub fn register_plugins<'a>(
         }
     });
 
-    let Registry {
-        syntax_exts,
-        llvm_passes,
-        attributes,
-        ..
-    } = registry;
-
+    let Registry { syntax_exts, llvm_passes, .. } = registry;
     *sess.plugin_llvm_passes.borrow_mut() = llvm_passes;
-    *sess.plugin_attributes.borrow_mut() = attributes;
 
     Ok((krate, PluginInfo { syntax_exts }, Lrc::new(lint_store)))
 }
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs
index 642b8e3279d..9f293bdaa10 100644
--- a/src/librustc_lint/unused.rs
+++ b/src/librustc_lint/unused.rs
@@ -309,29 +309,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
             }
         }
 
-        let plugin_attributes = cx.sess().plugin_attributes.borrow();
-        for &(name, ty) in plugin_attributes.iter() {
-            if ty == AttributeType::Whitelisted && attr.check_name(name) {
-                debug!("{:?} (plugin attr) is whitelisted with ty {:?}", name, ty);
-                break;
-            }
-        }
-
-        let name = attr.name_or_empty();
         if !attr::is_used(attr) {
             debug!("emitting warning for: {:?}", attr);
             cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
             // Is it a builtin attribute that must be used at the crate level?
-            let known_crate = attr_info.map(|&&(_, ty, ..)| {
-                    ty == AttributeType::CrateLevel
-            }).unwrap_or(false);
-
-            // Has a plugin registered this attribute as one that must be used at
-            // the crate level?
-            let plugin_crate = plugin_attributes.iter()
-                .find(|&&(x, t)| name == x && AttributeType::CrateLevel == t)
-                .is_some();
-            if known_crate || plugin_crate {
+            if attr_info.map_or(false, |(_, ty, ..)| ty == &AttributeType::CrateLevel) {
                 let msg = match attr.style {
                     ast::AttrStyle::Outer => {
                         "crate-level attribute should be an inner attribute: add an exclamation \
diff --git a/src/librustc_plugin/registry.rs b/src/librustc_plugin/registry.rs
index 3f4b87a97c7..aa5ea80f0b0 100644
--- a/src/librustc_plugin/registry.rs
+++ b/src/librustc_plugin/registry.rs
@@ -7,7 +7,6 @@ use syntax_expand::base::{SyntaxExtension, SyntaxExtensionKind, NamedSyntaxExten
 use syntax_expand::base::MacroExpanderFn;
 use syntax::symbol::Symbol;
 use syntax::ast;
-use syntax::feature_gate::AttributeType;
 use syntax_pos::Span;
 
 use std::borrow::ToOwned;
@@ -39,9 +38,6 @@ pub struct Registry<'a> {
 
     #[doc(hidden)]
     pub llvm_passes: Vec<String>,
-
-    #[doc(hidden)]
-    pub attributes: Vec<(Symbol, AttributeType)>,
 }
 
 impl<'a> Registry<'a> {
@@ -54,7 +50,6 @@ impl<'a> Registry<'a> {
             krate_span,
             syntax_exts: vec![],
             llvm_passes: vec![],
-            attributes: vec![],
         }
     }
 
@@ -98,12 +93,4 @@ impl<'a> Registry<'a> {
     pub fn register_llvm_pass(&mut self, name: &str) {
         self.llvm_passes.push(name.to_owned());
     }
-
-    /// Register an attribute with an attribute type.
-    ///
-    /// `Whitelisted` attributes will additionally not trigger the `unused_attribute`
-    /// lint. `CrateLevel` attributes will not be allowed on anything other than a crate.
-    pub fn register_attribute(&mut self, name: Symbol, ty: AttributeType) {
-        self.attributes.push((name, ty));
-    }
 }
diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs
index 1ebe9b5e120..97c00c576e6 100644
--- a/src/librustc_resolve/diagnostics.rs
+++ b/src/librustc_resolve/diagnostics.rs
@@ -428,15 +428,6 @@ impl<'a> Resolver<'a> {
                         }));
                     }
                 }
-                Scope::LegacyPluginHelpers => {
-                    let res = Res::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper);
-                    if filter_fn(res) {
-                        let plugin_attributes = this.session.plugin_attributes.borrow();
-                        suggestions.extend(plugin_attributes.iter().map(|(name, _)| {
-                            TypoSuggestion::from_res(*name, res)
-                        }));
-                    }
-                }
                 Scope::ExternPrelude => {
                     suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| {
                         let res = Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX));
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 47e8cf80a05..350039736a0 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -104,7 +104,6 @@ enum Scope<'a> {
     RegisteredAttrs,
     MacroUsePrelude,
     BuiltinAttrs,
-    LegacyPluginHelpers,
     ExternPrelude,
     ToolPrelude,
     StdLibPrelude,
@@ -1462,9 +1461,6 @@ impl<'a> Resolver<'a> {
         // 4b. "Standard library prelude" part implemented through `macro-use` (closed, controlled).
         // 4c. Standard library prelude (de-facto closed, controlled).
         // 6. Language prelude: builtin attributes (closed, controlled).
-        // 4-6. Legacy plugin helpers (open, not controlled). Similar to derive helpers,
-        //    but introduced by legacy plugins using `register_attribute`. Priority is somewhere
-        //    in prelude, not sure where exactly (creates ambiguities with any other prelude names).
 
         let rust_2015 = ident.span.rust_2015();
         let (ns, is_absolute_path) = match scope_set {
@@ -1491,7 +1487,6 @@ impl<'a> Resolver<'a> {
                 Scope::RegisteredAttrs => use_prelude,
                 Scope::MacroUsePrelude => use_prelude || rust_2015,
                 Scope::BuiltinAttrs => true,
-                Scope::LegacyPluginHelpers => use_prelude || rust_2015,
                 Scope::ExternPrelude => use_prelude || is_absolute_path,
                 Scope::ToolPrelude => use_prelude,
                 Scope::StdLibPrelude => use_prelude || ns == MacroNS,
@@ -1540,8 +1535,7 @@ impl<'a> Resolver<'a> {
                 }
                 Scope::RegisteredAttrs => Scope::MacroUsePrelude,
                 Scope::MacroUsePrelude => Scope::StdLibPrelude,
-                Scope::BuiltinAttrs => Scope::LegacyPluginHelpers,
-                Scope::LegacyPluginHelpers => break, // nowhere else to search
+                Scope::BuiltinAttrs => break, // nowhere else to search
                 Scope::ExternPrelude if is_absolute_path => break,
                 Scope::ExternPrelude => Scope::ToolPrelude,
                 Scope::ToolPrelude => Scope::StdLibPrelude,
diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs
index 2d125a459c8..a8ace56f4fc 100644
--- a/src/librustc_resolve/macros.rs
+++ b/src/librustc_resolve/macros.rs
@@ -590,13 +590,6 @@ impl<'a> Resolver<'a> {
                 } else {
                     Err(Determinacy::Determined)
                 }
-                Scope::LegacyPluginHelpers => if this.session.plugin_attributes.borrow().iter()
-                                                     .any(|(name, _)| ident.name == *name) {
-                    let res = Res::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper);
-                    ok(res, DUMMY_SP, this.arenas)
-                } else {
-                    Err(Determinacy::Determined)
-                }
                 Scope::ExternPrelude => match this.extern_prelude_get(ident, !record_used) {
                     Some(binding) => Ok((binding, Flags::empty())),
                     None => Err(Determinacy::determined(
diff --git a/src/test/ui-fulldeps/auxiliary/attr-plugin-test.rs b/src/test/ui-fulldeps/auxiliary/attr-plugin-test.rs
index 3d08c1c9eee..b17c6a93965 100644
--- a/src/test/ui-fulldeps/auxiliary/attr-plugin-test.rs
+++ b/src/test/ui-fulldeps/auxiliary/attr-plugin-test.rs
@@ -14,9 +14,6 @@ use syntax::symbol::Symbol;
 
 #[plugin_registrar]
 pub fn plugin_registrar(reg: &mut Registry) {
-    reg.register_attribute(Symbol::intern("foo"), AttributeType::Normal);
-    reg.register_attribute(Symbol::intern("bar"), AttributeType::CrateLevel);
-    reg.register_attribute(Symbol::intern("baz"), AttributeType::Whitelisted);
     reg.register_syntax_extension(
         Symbol::intern("mac"), SyntaxExtension::dummy_bang(reg.sess.edition())
     );
diff --git a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs
index 6b914f501ca..68ea10fe735 100644
--- a/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs
+++ b/src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs
@@ -5,25 +5,17 @@
 extern crate rustc;
 extern crate rustc_driver;
 extern crate syntax;
-extern crate syntax_expand;
 
 use rustc_driver::plugin::Registry;
-use syntax::attr;
-use syntax_expand::base::*;
-use syntax::feature_gate::AttributeType::Whitelisted;
-use syntax::symbol::Symbol;
-
-use rustc::hir;
-use rustc::hir::intravisit;
-use hir::Node;
+use rustc::hir::{self, intravisit, Node};
 use rustc::lint::{LateContext, LintPass, LintArray, LateLintPass, LintContext};
+use syntax::print::pprust;
 use syntax::source_map;
 
 #[plugin_registrar]
 pub fn plugin_registrar(reg: &mut Registry) {
     reg.lint_store.register_lints(&[&MISSING_WHITELISTED_ATTR]);
     reg.lint_store.register_late_pass(|| box MissingWhitelistedAttrPass);
-    reg.register_attribute(Symbol::intern("whitelisted_attr"), Whitelisted);
 }
 
 declare_lint! {
@@ -48,7 +40,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass {
             _ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id)),
         };
 
-        if !attr::contains_name(&item.attrs, Symbol::intern("whitelisted_attr")) {
+        let whitelisted = |attr| pprust::attribute_to_string(attr).contains("whitelisted_attr");
+        if !item.attrs.iter().any(whitelisted) {
             cx.span_lint(MISSING_WHITELISTED_ATTR, span,
                          "Missing 'whitelisted_attr' attribute");
         }
diff --git a/src/test/ui-fulldeps/issue-40001.rs b/src/test/ui-fulldeps/issue-40001.rs
index e0dc3d6a45b..c3f98197250 100644
--- a/src/test/ui-fulldeps/issue-40001.rs
+++ b/src/test/ui-fulldeps/issue-40001.rs
@@ -2,8 +2,9 @@
 // aux-build:issue-40001-plugin.rs
 // ignore-stage1
 
-#![feature(plugin)]
+#![feature(plugin, register_tool)]
 #![plugin(issue_40001_plugin)] //~ WARNING compiler plugins are deprecated
+#![register_tool(plugin)]
 
-#[whitelisted_attr]
+#[plugin::whitelisted_attr]
 fn main() {}
diff --git a/src/test/ui-fulldeps/plugin-attr-register-deny.rs b/src/test/ui-fulldeps/plugin-attr-register-deny.rs
deleted file mode 100644
index dd7c009388e..00000000000
--- a/src/test/ui-fulldeps/plugin-attr-register-deny.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-// aux-build:attr-plugin-test.rs
-// ignore-stage1
-
-#![feature(plugin)]
-#![plugin(attr_plugin_test)]
-//~^ WARN use of deprecated attribute `plugin`
-#![deny(unused_attributes)]
-
-#[baz]
-fn baz() { } // no error
-
-#[foo]
-pub fn main() {
-     //~^^ ERROR unused
-    #[bar]
-    fn inner() {}
-    //~^^ ERROR crate
-    //~^^^ ERROR unused
-    baz();
-    inner();
-}
diff --git a/src/test/ui-fulldeps/plugin-attr-register-deny.stderr b/src/test/ui-fulldeps/plugin-attr-register-deny.stderr
deleted file mode 100644
index 8d95d6ff2d8..00000000000
--- a/src/test/ui-fulldeps/plugin-attr-register-deny.stderr
+++ /dev/null
@@ -1,34 +0,0 @@
-warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
-  --> $DIR/plugin-attr-register-deny.rs:5:1
-   |
-LL | #![plugin(attr_plugin_test)]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: may be removed in a future compiler version
-   |
-   = note: `#[warn(deprecated)]` on by default
-
-error: unused attribute
-  --> $DIR/plugin-attr-register-deny.rs:15:5
-   |
-LL |     #[bar]
-   |     ^^^^^^
-   |
-note: lint level defined here
-  --> $DIR/plugin-attr-register-deny.rs:7:9
-   |
-LL | #![deny(unused_attributes)]
-   |         ^^^^^^^^^^^^^^^^^
-
-error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
-  --> $DIR/plugin-attr-register-deny.rs:15:5
-   |
-LL |     #[bar]
-   |     ^^^^^^
-
-error: unused attribute
-  --> $DIR/plugin-attr-register-deny.rs:12:1
-   |
-LL | #[foo]
-   | ^^^^^^
-
-error: aborting due to 3 previous errors
-