Skip to content

Commit fd55f5c

Browse files
authored
Rollup merge of rust-lang#66344 - petrochenkov:noregattr, r=matthewjasper
rustc_plugin: Remove `Registry::register_attribute` Legacy plugins cannot register inert attributes anymore. The preferred replacement is to use `register_tool` ([tracking issue](rust-lang#66079)). ```rust #![register_tool(servo)] #[servo::must_root] struct S; ``` The more direct replacement is `register_attribute` ([tracking issue](rust-lang#66080)) ```rust #![register_attr(must_root)] #[must_root] struct S; ``` , but it requires registering each attribute individually rather than registering the tool once, and is more likely to be removed rather than stabilized.
2 parents b25e706 + 8575743 commit fd55f5c

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
@@ -437,15 +437,6 @@ impl<'a> Resolver<'a> {
437437
}));
438438
}
439439
}
440-
Scope::LegacyPluginHelpers => {
441-
let res = Res::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper);
442-
if filter_fn(res) {
443-
let plugin_attributes = this.session.plugin_attributes.borrow();
444-
suggestions.extend(plugin_attributes.iter().map(|(name, _)| {
445-
TypoSuggestion::from_res(*name, res)
446-
}));
447-
}
448-
}
449440
Scope::ExternPrelude => {
450441
suggestions.extend(this.extern_prelude.iter().filter_map(|(ident, _)| {
451442
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
@@ -105,7 +105,6 @@ enum Scope<'a> {
105105
RegisteredAttrs,
106106
MacroUsePrelude,
107107
BuiltinAttrs,
108-
LegacyPluginHelpers,
109108
ExternPrelude,
110109
ToolPrelude,
111110
StdLibPrelude,
@@ -1466,9 +1465,6 @@ impl<'a> Resolver<'a> {
14661465
// 4b. "Standard library prelude" part implemented through `macro-use` (closed, controlled).
14671466
// 4c. Standard library prelude (de-facto closed, controlled).
14681467
// 6. Language prelude: builtin attributes (closed, controlled).
1469-
// 4-6. Legacy plugin helpers (open, not controlled). Similar to derive helpers,
1470-
// but introduced by legacy plugins using `register_attribute`. Priority is somewhere
1471-
// in prelude, not sure where exactly (creates ambiguities with any other prelude names).
14721468

14731469
let rust_2015 = ident.span.rust_2015();
14741470
let (ns, macro_kind, is_absolute_path) = match scope_set {
@@ -1498,7 +1494,6 @@ impl<'a> Resolver<'a> {
14981494
Scope::RegisteredAttrs => use_prelude,
14991495
Scope::MacroUsePrelude => use_prelude || rust_2015,
15001496
Scope::BuiltinAttrs => true,
1501-
Scope::LegacyPluginHelpers => use_prelude || rust_2015,
15021497
Scope::ExternPrelude => use_prelude || is_absolute_path,
15031498
Scope::ToolPrelude => use_prelude,
15041499
Scope::StdLibPrelude => use_prelude || ns == MacroNS,
@@ -1558,8 +1553,7 @@ impl<'a> Resolver<'a> {
15581553
}
15591554
Scope::RegisteredAttrs => Scope::MacroUsePrelude,
15601555
Scope::MacroUsePrelude => Scope::StdLibPrelude,
1561-
Scope::BuiltinAttrs => Scope::LegacyPluginHelpers,
1562-
Scope::LegacyPluginHelpers => break, // nowhere else to search
1556+
Scope::BuiltinAttrs => break, // nowhere else to search
15631557
Scope::ExternPrelude if is_absolute_path => break,
15641558
Scope::ExternPrelude => Scope::ToolPrelude,
15651559
Scope::ToolPrelude => Scope::StdLibPrelude,

src/librustc_resolve/macros.rs

-7
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,6 @@ impl<'a> Resolver<'a> {
613613
} else {
614614
Err(Determinacy::Determined)
615615
}
616-
Scope::LegacyPluginHelpers => if this.session.plugin_attributes.borrow().iter()
617-
.any(|(name, _)| ident.name == *name) {
618-
let res = Res::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper);
619-
ok(res, DUMMY_SP, this.arenas)
620-
} else {
621-
Err(Determinacy::Determined)
622-
}
623616
Scope::ExternPrelude => match this.extern_prelude_get(ident, !record_used) {
624617
Some(binding) => Ok((binding, Flags::empty())),
625618
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)