11use super :: { active:: { ACTIVE_FEATURES , Features } , Feature , State as FeatureState } ;
22use super :: accepted:: ACCEPTED_FEATURES ;
33use 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
66use crate :: ast:: {
77 self , AssocTyConstraint , AssocTyConstraintKind , NodeId , GenericParam , GenericParamKind ,
@@ -33,9 +33,8 @@ pub enum Stability {
3333}
3434
3535struct Context < ' a > {
36- features : & ' a Features ,
3736 parse_sess : & ' a ParseSess ,
38- plugin_attributes : & ' a [ ( Symbol , AttributeType ) ] ,
37+ features : & ' a Features ,
3938}
4039
4140macro_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
12092pub 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
874845pub 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