Skip to content

Commit 8575743

Browse files
committed
rustc_plugin: Remove Registry::register_attribute
1 parent 9b0214d commit 8575743

File tree

13 files changed

+12
-143
lines changed

13 files changed

+12
-143
lines changed

src/librustc/hir/def.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ pub enum NonMacroAttrKind {
4242
DeriveHelper,
4343
/// Single-segment custom attribute registered with `#[register_attr]`.
4444
Registered,
45-
/// Single-segment custom attribute registered by a legacy plugin (`register_attribute`).
46-
LegacyPluginHelper,
4745
}
4846

4947
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
@@ -330,7 +328,6 @@ impl NonMacroAttrKind {
330328
NonMacroAttrKind::Tool => "tool attribute",
331329
NonMacroAttrKind::DeriveHelper => "derive helper attribute",
332330
NonMacroAttrKind::Registered => "explicitly registered attribute",
333-
NonMacroAttrKind::LegacyPluginHelper => "legacy plugin helper attribute",
334331
}
335332
}
336333

@@ -345,8 +342,7 @@ impl NonMacroAttrKind {
345342
pub fn is_used(self) -> bool {
346343
match self {
347344
NonMacroAttrKind::Tool | NonMacroAttrKind::DeriveHelper => true,
348-
NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered |
349-
NonMacroAttrKind::LegacyPluginHelper => false,
345+
NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered => false,
350346
}
351347
}
352348
}

src/librustc/session/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ use errors::emitter::{Emitter, EmitterWriter};
2121
use errors::emitter::HumanReadableErrorType;
2222
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
2323
use syntax::edition::Edition;
24-
use syntax::feature_gate::{self, AttributeType};
24+
use syntax::feature_gate;
2525
use errors::json::JsonEmitter;
2626
use syntax::source_map;
2727
use syntax::sess::{ParseSess, ProcessCfgMod};
28-
use syntax::symbol::Symbol;
2928
use syntax_pos::{MultiSpan, Span};
3029

3130
use rustc_target::spec::{PanicStrategy, RelroLevel, Target, TargetTriple};
@@ -79,7 +78,6 @@ pub struct Session {
7978
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
8079
pub one_time_diagnostics: Lock<FxHashSet<(DiagnosticMessageId, Option<Span>, String)>>,
8180
pub plugin_llvm_passes: OneThread<RefCell<Vec<String>>>,
82-
pub plugin_attributes: Lock<Vec<(Symbol, AttributeType)>>,
8381
pub crate_types: Once<Vec<config::CrateType>>,
8482
/// The `crate_disambiguator` is constructed out of all the `-C metadata`
8583
/// arguments passed to the compiler. Its value together with the crate-name
@@ -1166,7 +1164,6 @@ fn build_session_(
11661164
working_dir,
11671165
one_time_diagnostics: Default::default(),
11681166
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
1169-
plugin_attributes: Lock::new(Vec::new()),
11701167
crate_types: Once::new(),
11711168
crate_disambiguator: Once::new(),
11721169
features: Once::new(),

src/librustc_interface/passes.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,8 @@ pub fn register_plugins<'a>(
240240
}
241241
});
242242

243-
let Registry {
244-
syntax_exts,
245-
llvm_passes,
246-
attributes,
247-
..
248-
} = registry;
249-
243+
let Registry { syntax_exts, llvm_passes, .. } = registry;
250244
*sess.plugin_llvm_passes.borrow_mut() = llvm_passes;
251-
*sess.plugin_attributes.borrow_mut() = attributes;
252245

253246
Ok((krate, PluginInfo { syntax_exts }, Lrc::new(lint_store)))
254247
}

src/librustc_lint/unused.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -309,29 +309,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
309309
}
310310
}
311311

312-
let plugin_attributes = cx.sess().plugin_attributes.borrow();
313-
for &(name, ty) in plugin_attributes.iter() {
314-
if ty == AttributeType::Whitelisted && attr.check_name(name) {
315-
debug!("{:?} (plugin attr) is whitelisted with ty {:?}", name, ty);
316-
break;
317-
}
318-
}
319-
320-
let name = attr.name_or_empty();
321312
if !attr::is_used(attr) {
322313
debug!("emitting warning for: {:?}", attr);
323314
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
324315
// Is it a builtin attribute that must be used at the crate level?
325-
let known_crate = attr_info.map(|&&(_, ty, ..)| {
326-
ty == AttributeType::CrateLevel
327-
}).unwrap_or(false);
328-
329-
// Has a plugin registered this attribute as one that must be used at
330-
// the crate level?
331-
let plugin_crate = plugin_attributes.iter()
332-
.find(|&&(x, t)| name == x && AttributeType::CrateLevel == t)
333-
.is_some();
334-
if known_crate || plugin_crate {
316+
if attr_info.map_or(false, |(_, ty, ..)| ty == &AttributeType::CrateLevel) {
335317
let msg = match attr.style {
336318
ast::AttrStyle::Outer => {
337319
"crate-level attribute should be an inner attribute: add an exclamation \

src/librustc_plugin/registry.rs

-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use syntax_expand::base::{SyntaxExtension, SyntaxExtensionKind, NamedSyntaxExten
77
use syntax_expand::base::MacroExpanderFn;
88
use syntax::symbol::Symbol;
99
use syntax::ast;
10-
use syntax::feature_gate::AttributeType;
1110
use syntax_pos::Span;
1211

1312
use std::borrow::ToOwned;
@@ -39,9 +38,6 @@ pub struct Registry<'a> {
3938

4039
#[doc(hidden)]
4140
pub llvm_passes: Vec<String>,
42-
43-
#[doc(hidden)]
44-
pub attributes: Vec<(Symbol, AttributeType)>,
4541
}
4642

4743
impl<'a> Registry<'a> {
@@ -54,7 +50,6 @@ impl<'a> Registry<'a> {
5450
krate_span,
5551
syntax_exts: vec![],
5652
llvm_passes: vec![],
57-
attributes: vec![],
5853
}
5954
}
6055

@@ -98,12 +93,4 @@ impl<'a> Registry<'a> {
9893
pub fn register_llvm_pass(&mut self, name: &str) {
9994
self.llvm_passes.push(name.to_owned());
10095
}
101-
102-
/// Register an attribute with an attribute type.
103-
///
104-
/// `Whitelisted` attributes will additionally not trigger the `unused_attribute`
105-
/// lint. `CrateLevel` attributes will not be allowed on anything other than a crate.
106-
pub fn register_attribute(&mut self, name: Symbol, ty: AttributeType) {
107-
self.attributes.push((name, ty));
108-
}
10996
}

src/librustc_resolve/diagnostics.rs

-9
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,6 @@ impl<'a> Resolver<'a> {
428428
}));
429429
}
430430
}
431-
Scope::LegacyPluginHelpers => {
432-
let res = Res::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper);
433-
if filter_fn(res) {
434-
let plugin_attributes = this.session.plugin_attributes.borrow();
435-
suggestions.extend(plugin_attributes.iter().map(|(name, _)| {
436-
TypoSuggestion::from_res(*name, res)
437-
}));
438-
}
439-
}
440431
Scope::ExternPrelude => {
441432
suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| {
442433
let res = Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX));

src/librustc_resolve/lib.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ enum Scope<'a> {
104104
RegisteredAttrs,
105105
MacroUsePrelude,
106106
BuiltinAttrs,
107-
LegacyPluginHelpers,
108107
ExternPrelude,
109108
ToolPrelude,
110109
StdLibPrelude,
@@ -1462,9 +1461,6 @@ impl<'a> Resolver<'a> {
14621461
// 4b. "Standard library prelude" part implemented through `macro-use` (closed, controlled).
14631462
// 4c. Standard library prelude (de-facto closed, controlled).
14641463
// 6. Language prelude: builtin attributes (closed, controlled).
1465-
// 4-6. Legacy plugin helpers (open, not controlled). Similar to derive helpers,
1466-
// but introduced by legacy plugins using `register_attribute`. Priority is somewhere
1467-
// in prelude, not sure where exactly (creates ambiguities with any other prelude names).
14681464

14691465
let rust_2015 = ident.span.rust_2015();
14701466
let (ns, is_absolute_path) = match scope_set {
@@ -1491,7 +1487,6 @@ impl<'a> Resolver<'a> {
14911487
Scope::RegisteredAttrs => use_prelude,
14921488
Scope::MacroUsePrelude => use_prelude || rust_2015,
14931489
Scope::BuiltinAttrs => true,
1494-
Scope::LegacyPluginHelpers => use_prelude || rust_2015,
14951490
Scope::ExternPrelude => use_prelude || is_absolute_path,
14961491
Scope::ToolPrelude => use_prelude,
14971492
Scope::StdLibPrelude => use_prelude || ns == MacroNS,
@@ -1540,8 +1535,7 @@ impl<'a> Resolver<'a> {
15401535
}
15411536
Scope::RegisteredAttrs => Scope::MacroUsePrelude,
15421537
Scope::MacroUsePrelude => Scope::StdLibPrelude,
1543-
Scope::BuiltinAttrs => Scope::LegacyPluginHelpers,
1544-
Scope::LegacyPluginHelpers => break, // nowhere else to search
1538+
Scope::BuiltinAttrs => break, // nowhere else to search
15451539
Scope::ExternPrelude if is_absolute_path => break,
15461540
Scope::ExternPrelude => Scope::ToolPrelude,
15471541
Scope::ToolPrelude => Scope::StdLibPrelude,

src/librustc_resolve/macros.rs

-7
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,6 @@ impl<'a> Resolver<'a> {
590590
} else {
591591
Err(Determinacy::Determined)
592592
}
593-
Scope::LegacyPluginHelpers => if this.session.plugin_attributes.borrow().iter()
594-
.any(|(name, _)| ident.name == *name) {
595-
let res = Res::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper);
596-
ok(res, DUMMY_SP, this.arenas)
597-
} else {
598-
Err(Determinacy::Determined)
599-
}
600593
Scope::ExternPrelude => match this.extern_prelude_get(ident, !record_used) {
601594
Some(binding) => Ok((binding, Flags::empty())),
602595
None => Err(Determinacy::determined(

src/test/ui-fulldeps/auxiliary/attr-plugin-test.rs

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ use syntax::symbol::Symbol;
1414

1515
#[plugin_registrar]
1616
pub fn plugin_registrar(reg: &mut Registry) {
17-
reg.register_attribute(Symbol::intern("foo"), AttributeType::Normal);
18-
reg.register_attribute(Symbol::intern("bar"), AttributeType::CrateLevel);
19-
reg.register_attribute(Symbol::intern("baz"), AttributeType::Whitelisted);
2017
reg.register_syntax_extension(
2118
Symbol::intern("mac"), SyntaxExtension::dummy_bang(reg.sess.edition())
2219
);

src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,17 @@
55
extern crate rustc;
66
extern crate rustc_driver;
77
extern crate syntax;
8-
extern crate syntax_expand;
98

109
use rustc_driver::plugin::Registry;
11-
use syntax::attr;
12-
use syntax_expand::base::*;
13-
use syntax::feature_gate::AttributeType::Whitelisted;
14-
use syntax::symbol::Symbol;
15-
16-
use rustc::hir;
17-
use rustc::hir::intravisit;
18-
use hir::Node;
10+
use rustc::hir::{self, intravisit, Node};
1911
use rustc::lint::{LateContext, LintPass, LintArray, LateLintPass, LintContext};
12+
use syntax::print::pprust;
2013
use syntax::source_map;
2114

2215
#[plugin_registrar]
2316
pub fn plugin_registrar(reg: &mut Registry) {
2417
reg.lint_store.register_lints(&[&MISSING_WHITELISTED_ATTR]);
2518
reg.lint_store.register_late_pass(|| box MissingWhitelistedAttrPass);
26-
reg.register_attribute(Symbol::intern("whitelisted_attr"), Whitelisted);
2719
}
2820

2921
declare_lint! {
@@ -48,7 +40,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass {
4840
_ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id)),
4941
};
5042

51-
if !attr::contains_name(&item.attrs, Symbol::intern("whitelisted_attr")) {
43+
let whitelisted = |attr| pprust::attribute_to_string(attr).contains("whitelisted_attr");
44+
if !item.attrs.iter().any(whitelisted) {
5245
cx.span_lint(MISSING_WHITELISTED_ATTR, span,
5346
"Missing 'whitelisted_attr' attribute");
5447
}

src/test/ui-fulldeps/issue-40001.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// aux-build:issue-40001-plugin.rs
33
// ignore-stage1
44

5-
#![feature(plugin)]
5+
#![feature(plugin, register_tool)]
66
#![plugin(issue_40001_plugin)] //~ WARNING compiler plugins are deprecated
7+
#![register_tool(plugin)]
78

8-
#[whitelisted_attr]
9+
#[plugin::whitelisted_attr]
910
fn main() {}

src/test/ui-fulldeps/plugin-attr-register-deny.rs

-21
This file was deleted.

src/test/ui-fulldeps/plugin-attr-register-deny.stderr

-34
This file was deleted.

0 commit comments

Comments
 (0)