@@ -11,7 +11,8 @@ use syntax::ast::{Attribute, MetaItem, MetaItemKind};
11
11
use syntax_pos:: { Span , sym} ;
12
12
use rustc_data_structures:: fx:: { FxHashSet , FxHashMap } ;
13
13
use rustc_macros:: HashStable ;
14
- use errors:: DiagnosticId ;
14
+
15
+ use rustc_error_codes:: * ;
15
16
16
17
#[ derive( HashStable ) ]
17
18
pub struct LibFeatures {
@@ -98,15 +99,16 @@ impl LibFeatureCollector<'tcx> {
98
99
( Some ( since) , _, false ) => {
99
100
if let Some ( prev_since) = self . lib_features . stable . get ( & feature) {
100
101
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
+ ) ,
107
111
) ;
108
- self . tcx . sess . struct_span_err_with_code ( span, & msg,
109
- DiagnosticId :: Error ( "E0711" . into ( ) ) ) . emit ( ) ;
110
112
return ;
111
113
}
112
114
}
@@ -117,17 +119,27 @@ impl LibFeatureCollector<'tcx> {
117
119
self . lib_features . unstable . insert ( feature) ;
118
120
}
119
121
( 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
+ ) ,
125
130
) ;
126
- self . tcx . sess . struct_span_err_with_code ( span, & msg,
127
- DiagnosticId :: Error ( "E0711" . into ( ) ) ) . emit ( ) ;
128
131
}
129
132
}
130
133
}
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
+ }
131
143
}
132
144
133
145
impl Visitor < ' tcx > for LibFeatureCollector < ' tcx > {
0 commit comments