Skip to content

Commit 966d96c

Browse files
committed
feature_gate: Remove dead code from attribute checking
Same checks are performed during name resolution, and all attributes go through name resolution now
1 parent ca3766e commit 966d96c

File tree

2 files changed

+10
-51
lines changed

2 files changed

+10
-51
lines changed

src/librustc_interface/passes.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use syntax::mut_visit::MutVisitor;
4141
use syntax::parse::{self, PResult};
4242
use syntax::util::node_count::NodeCounter;
4343
use syntax::symbol::Symbol;
44-
use syntax::feature_gate::AttributeType;
4544
use syntax_pos::FileName;
4645
use syntax_ext;
4746

@@ -219,7 +218,6 @@ impl BoxedResolver {
219218

220219
pub struct PluginInfo {
221220
syntax_exts: Vec<NamedSyntaxExtension>,
222-
attributes: Vec<(Symbol, AttributeType)>,
223221
}
224222

225223
pub fn register_plugins<'a>(
@@ -312,12 +310,9 @@ pub fn register_plugins<'a>(
312310
}
313311

314312
*sess.plugin_llvm_passes.borrow_mut() = llvm_passes;
315-
*sess.plugin_attributes.borrow_mut() = attributes.clone();
313+
*sess.plugin_attributes.borrow_mut() = attributes;
316314

317-
Ok((krate, PluginInfo {
318-
syntax_exts,
319-
attributes,
320-
}))
315+
Ok((krate, PluginInfo { syntax_exts }))
321316
}
322317

323318
fn configure_and_expand_inner<'a>(
@@ -329,7 +324,6 @@ fn configure_and_expand_inner<'a>(
329324
crate_loader: &'a mut CrateLoader<'a>,
330325
plugin_info: PluginInfo,
331326
) -> Result<(ast::Crate, Resolver<'a>)> {
332-
let attributes = plugin_info.attributes;
333327
time(sess, "pre ast expansion lint checks", || {
334328
lint::check_ast_crate(
335329
sess,
@@ -522,7 +516,6 @@ fn configure_and_expand_inner<'a>(
522516
&krate,
523517
&sess.parse_sess,
524518
&sess.features_untracked(),
525-
&attributes,
526519
sess.opts.unstable_features,
527520
);
528521
});

src/libsyntax/feature_gate/check.rs

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{active::{ACTIVE_FEATURES, Features}, Feature, State as FeatureState};
22
use super::accepted::ACCEPTED_FEATURES;
33
use super::removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
4-
use super::builtin_attrs::{AttributeGate, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
4+
use super::builtin_attrs::{AttributeGate, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
55

66
use crate::ast::{
77
self, AssocTyConstraint, AssocTyConstraintKind, NodeId, GenericParam, GenericParamKind,
@@ -33,9 +33,8 @@ pub enum Stability {
3333
}
3434

3535
struct Context<'a> {
36-
features: &'a Features,
3736
parse_sess: &'a ParseSess,
38-
plugin_attributes: &'a [(Symbol, AttributeType)],
37+
features: &'a Features,
3938
}
4039

4140
macro_rules! gate_feature_fn {
@@ -67,7 +66,6 @@ impl<'a> Context<'a> {
6766
&self,
6867
attr: &ast::Attribute,
6968
attr_info: Option<&BuiltinAttribute>,
70-
is_macro: bool
7169
) {
7270
debug!("check_attribute(attr = {:?})", attr);
7371
if let Some(&(name, ty, _template, ref gateage)) = attr_info {
@@ -87,42 +85,15 @@ impl<'a> Context<'a> {
8785
}
8886
}
8987
debug!("check_attribute: {:?} is builtin, {:?}, {:?}", attr.path, ty, gateage);
90-
return;
91-
} else {
92-
for segment in &attr.path.segments {
93-
if segment.ident.as_str().starts_with("rustc") {
94-
let msg = "attributes starting with `rustc` are \
95-
reserved for use by the `rustc` compiler";
96-
gate_feature!(self, rustc_attrs, segment.ident.span, msg);
97-
}
98-
}
99-
}
100-
for &(n, ty) in self.plugin_attributes {
101-
if attr.path == n {
102-
// Plugins can't gate attributes, so we don't check for it
103-
// unlike the code above; we only use this loop to
104-
// short-circuit to avoid the checks below.
105-
debug!("check_attribute: {:?} is registered by a plugin, {:?}", attr.path, ty);
106-
return;
107-
}
108-
}
109-
if !is_macro && !attr::is_known(attr) {
110-
// Only run the custom attribute lint during regular feature gate
111-
// checking. Macro gating runs before the plugin attributes are
112-
// registered, so we skip this in that case.
113-
let msg = format!("the attribute `{}` is currently unknown to the compiler and \
114-
may have meaning added to it in the future", attr.path);
115-
gate_feature!(self, custom_attribute, attr.span, &msg);
11688
}
11789
}
11890
}
11991

12092
pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess, features: &Features) {
121-
let cx = Context { features, parse_sess, plugin_attributes: &[] };
93+
let cx = Context { parse_sess, features };
12294
cx.check_attribute(
12395
attr,
12496
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name).map(|a| *a)),
125-
true
12697
);
12798
}
12899

@@ -321,7 +292,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
321292
});
322293

323294
// Check for gated attributes.
324-
self.context.check_attribute(attr, attr_info, false);
295+
self.context.check_attribute(attr, attr_info);
325296

326297
if attr.check_name(sym::doc) {
327298
if let Some(content) = attr.meta_item_list() {
@@ -872,21 +843,16 @@ fn active_features_up_to(edition: Edition) -> impl Iterator<Item=&'static Featur
872843
}
873844

874845
pub fn check_crate(krate: &ast::Crate,
875-
sess: &ParseSess,
846+
parse_sess: &ParseSess,
876847
features: &Features,
877-
plugin_attributes: &[(Symbol, AttributeType)],
878848
unstable: UnstableFeatures) {
879-
maybe_stage_features(&sess.span_diagnostic, krate, unstable);
880-
let ctx = Context {
881-
features,
882-
parse_sess: sess,
883-
plugin_attributes,
884-
};
849+
maybe_stage_features(&parse_sess.span_diagnostic, krate, unstable);
850+
let ctx = Context { parse_sess, features };
885851

886852
macro_rules! gate_all {
887853
($gate:ident, $msg:literal) => { gate_all!($gate, $gate, $msg); };
888854
($spans:ident, $gate:ident, $msg:literal) => {
889-
for span in &*sess.gated_spans.$spans.borrow() {
855+
for span in &*parse_sess.gated_spans.$spans.borrow() {
890856
gate_feature!(&ctx, $gate, *span, $msg);
891857
}
892858
}

0 commit comments

Comments
 (0)