@@ -163,7 +163,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
163
163
164
164
let ( stab, const_stab) = attr:: find_stability ( & self . tcx . sess , attrs, item_sp) ;
165
165
166
- let const_stab = const_stab. map ( |const_stab| {
166
+ let const_stab = const_stab. map ( |( const_stab, _ ) | {
167
167
let const_stab = self . tcx . intern_const_stability ( const_stab) ;
168
168
self . index . const_stab_map . insert ( hir_id, const_stab) ;
169
169
const_stab
@@ -193,12 +193,15 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
193
193
}
194
194
}
195
195
196
- let stab = stab. map ( |stab| {
196
+ let stab = stab. map ( |( stab, span ) | {
197
197
// Error if prohibited, or can't inherit anything from a container.
198
198
if kind == AnnotationKind :: Prohibited
199
199
|| ( kind == AnnotationKind :: Container && stab. level . is_stable ( ) && is_deprecated)
200
200
{
201
- self . tcx . sess . span_err ( item_sp, "this stability annotation is useless" ) ;
201
+ self . tcx . sess . struct_span_err ( span, "this stability annotation is useless" )
202
+ . span_label ( span, "useless stability annotation" )
203
+ . span_label ( item_sp, "the stability attribute annotates this item" )
204
+ . emit ( ) ;
202
205
}
203
206
204
207
debug ! ( "annotate: found {:?}" , stab) ;
@@ -215,26 +218,30 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
215
218
{
216
219
match stab_v. parse :: < u64 > ( ) {
217
220
Err ( _) => {
218
- self . tcx . sess . span_err ( item_sp, "invalid stability version found" ) ;
221
+ self . tcx . sess . struct_span_err ( span, "invalid stability version found" )
222
+ . span_label ( span, "invalid stability version" )
223
+ . span_label ( item_sp, "the stability attribute annotates this item" )
224
+ . emit ( ) ;
219
225
break ;
220
226
}
221
227
Ok ( stab_vp) => match dep_v. parse :: < u64 > ( ) {
222
228
Ok ( dep_vp) => match dep_vp. cmp ( & stab_vp) {
223
229
Ordering :: Less => {
224
- self . tcx . sess . span_err (
225
- item_sp ,
226
- "an API can't be stabilized after it is deprecated" ,
227
- ) ;
230
+ self . tcx . sess . struct_span_err ( span , "an API can't be stabilized after it is deprecated" )
231
+ . span_label ( span , "invalid version" )
232
+ . span_label ( item_sp , "the stability attribute annotates this item" )
233
+ . emit ( ) ;
228
234
break ;
229
235
}
230
236
Ordering :: Equal => continue ,
231
237
Ordering :: Greater => break ,
232
238
} ,
233
239
Err ( _) => {
234
240
if dep_v != "TBD" {
235
- self . tcx
236
- . sess
237
- . span_err ( item_sp, "invalid deprecation version found" ) ;
241
+ self . tcx . sess . struct_span_err ( span, "invalid deprecation version found" )
242
+ . span_label ( span, "invalid deprecation version" )
243
+ . span_label ( item_sp, "the stability attribute annotates this item" )
244
+ . emit ( ) ;
238
245
}
239
246
break ;
240
247
}
@@ -756,18 +763,13 @@ impl Visitor<'tcx> for Checker<'tcx> {
756
763
// error if all involved types and traits are stable, because
757
764
// it will have no effect.
758
765
// See: https://github.com/rust-lang/rust/issues/55436
759
- if let ( Some ( Stability { level : attr:: Unstable { .. } , .. } ) , _) =
766
+ if let ( Some ( ( Stability { level : attr:: Unstable { .. } , .. } , span ) ) , _) =
760
767
attr:: find_stability ( & self . tcx . sess , & item. attrs , item. span )
761
768
{
762
769
let mut c = CheckTraitImplStable { tcx : self . tcx , fully_stable : true } ;
763
770
c. visit_ty ( self_ty) ;
764
771
c. visit_trait_ref ( t) ;
765
772
if c. fully_stable {
766
- let span = item
767
- . attrs
768
- . iter ( )
769
- . find ( |a| a. has_name ( sym:: unstable) )
770
- . map_or ( item. span , |a| a. span ) ;
771
773
self . tcx . struct_span_lint_hir (
772
774
INEFFECTIVE_UNSTABLE_TRAIT_IMPL ,
773
775
item. hir_id ,
0 commit comments