@@ -11,7 +11,8 @@ use syntax::ast::{Attribute, MetaItem, MetaItemKind};
1111use syntax_pos:: { Span , sym} ;
1212use rustc_data_structures:: fx:: { FxHashSet , FxHashMap } ;
1313use rustc_macros:: HashStable ;
14- use errors:: DiagnosticId ;
14+
15+ use rustc_error_codes:: * ;
1516
1617#[ derive( HashStable ) ]
1718pub struct LibFeatures {
@@ -98,15 +99,16 @@ impl LibFeatureCollector<'tcx> {
9899 ( Some ( since) , _, false ) => {
99100 if let Some ( prev_since) = self . lib_features . stable . get ( & feature) {
100101 if * prev_since != since {
101- let msg = format ! (
102- "feature `{}` is declared stable since {}, \
103- but was previously declared stable since {}",
104- feature,
105- since,
106- prev_since,
102+ self . span_feature_error (
103+ span,
104+ & format ! (
105+ "feature `{}` is declared stable since {}, \
106+ but was previously declared stable since {}",
107+ feature,
108+ since,
109+ prev_since,
110+ ) ,
107111 ) ;
108- self . tcx . sess . struct_span_err_with_code ( span, & msg,
109- DiagnosticId :: Error ( "E0711" . into ( ) ) ) . emit ( ) ;
110112 return ;
111113 }
112114 }
@@ -117,17 +119,27 @@ impl LibFeatureCollector<'tcx> {
117119 self . lib_features . unstable . insert ( feature) ;
118120 }
119121 ( Some ( _) , _, true ) | ( None , true , _) => {
120- let msg = format ! (
121- "feature `{}` is declared {}, but was previously declared {}" ,
122- feature,
123- if since. is_some( ) { "stable" } else { "unstable" } ,
124- if since. is_none( ) { "stable" } else { "unstable" } ,
122+ self . span_feature_error (
123+ span,
124+ & format ! (
125+ "feature `{}` is declared {}, but was previously declared {}" ,
126+ feature,
127+ if since. is_some( ) { "stable" } else { "unstable" } ,
128+ if since. is_none( ) { "stable" } else { "unstable" } ,
129+ ) ,
125130 ) ;
126- self . tcx . sess . struct_span_err_with_code ( span, & msg,
127- DiagnosticId :: Error ( "E0711" . into ( ) ) ) . emit ( ) ;
128131 }
129132 }
130133 }
134+
135+ fn span_feature_error ( & self , span : Span , msg : & str ) {
136+ struct_span_err ! (
137+ self . tcx. sess,
138+ span,
139+ E0711 ,
140+ "{}" , & msg,
141+ ) . emit ( ) ;
142+ }
131143}
132144
133145impl Visitor < ' tcx > for LibFeatureCollector < ' tcx > {
0 commit comments