rustc_plugin: Remove Registry::register_attribute
This commit is contained in:
parent
9b0214d9c5
commit
8575743793
13 changed files with 12 additions and 143 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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)))
|
||||
}
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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())
|
||||
);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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
|
||||
|
Loading…
Add table
Reference in a new issue