Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_plugin: Remove Registry::register_attribute #66344

Merged
merged 1 commit into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/librustc/hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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",
}
}

Expand All @@ -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,
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 1 addition & 8 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down
20 changes: 1 addition & 19 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
13 changes: 0 additions & 13 deletions src/librustc_plugin/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Expand All @@ -54,7 +50,6 @@ impl<'a> Registry<'a> {
krate_span,
syntax_exts: vec![],
llvm_passes: vec![],
attributes: vec![],
}
}

Expand Down Expand Up @@ -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));
}
}
9 changes: 0 additions & 9 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 1 addition & 7 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ enum Scope<'a> {
RegisteredAttrs,
MacroUsePrelude,
BuiltinAttrs,
LegacyPluginHelpers,
ExternPrelude,
ToolPrelude,
StdLibPrelude,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 0 additions & 3 deletions src/test/ui-fulldeps/auxiliary/attr-plugin-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
Expand Down
15 changes: 4 additions & 11 deletions src/test/ui-fulldeps/auxiliary/issue-40001-plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand All @@ -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");
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/ui-fulldeps/issue-40001.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
21 changes: 0 additions & 21 deletions src/test/ui-fulldeps/plugin-attr-register-deny.rs

This file was deleted.

34 changes: 0 additions & 34 deletions src/test/ui-fulldeps/plugin-attr-register-deny.stderr

This file was deleted.