@@ -53,18 +53,18 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
53
53
& mut self ,
54
54
hir_id : HirId ,
55
55
attrs : & [ Attribute ] ,
56
- item_sp : Span ,
57
56
kind : AnnotationKind ,
58
57
visit_children : F ,
59
58
) where
60
59
F : FnOnce ( & mut Self ) ,
61
60
{
62
61
if !self . tcx . features ( ) . staged_api {
63
- self . forbid_staged_api_attrs ( hir_id, attrs, item_sp , kind, visit_children) ;
62
+ self . forbid_staged_api_attrs ( hir_id, attrs, kind, visit_children) ;
64
63
return ;
65
64
}
66
65
67
66
// This crate explicitly wants staged API.
67
+ let item_sp = self . tcx . hir ( ) . span ( hir_id) ;
68
68
69
69
debug ! ( "annotate(id = {:?}, attrs = {:?})" , hir_id, attrs) ;
70
70
if let Some ( ..) = attr:: find_deprecation ( & self . tcx . sess . parse_sess , attrs, item_sp) {
@@ -198,7 +198,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
198
198
& mut self ,
199
199
hir_id : HirId ,
200
200
attrs : & [ Attribute ] ,
201
- item_sp : Span ,
202
201
kind : AnnotationKind ,
203
202
visit_children : impl FnOnce ( & mut Self ) ,
204
203
) {
@@ -232,6 +231,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
232
231
}
233
232
}
234
233
234
+ let item_sp = self . tcx . hir ( ) . span ( hir_id) ;
235
235
if let Some ( depr) = attr:: find_deprecation ( & self . tcx . sess . parse_sess , attrs, item_sp) {
236
236
if kind == AnnotationKind :: Prohibited {
237
237
self . tcx . sess . span_err ( item_sp, "This deprecation annotation is useless" ) ;
@@ -280,57 +280,54 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
280
280
}
281
281
hir:: ItemKind :: Struct ( ref sd, _) => {
282
282
if let Some ( ctor_hir_id) = sd. ctor_hir_id ( ) {
283
- self . annotate ( ctor_hir_id, & i. attrs , i . span , AnnotationKind :: Required , |_| { } )
283
+ self . annotate ( ctor_hir_id, & i. attrs , AnnotationKind :: Required , |_| { } )
284
284
}
285
285
}
286
286
_ => { }
287
287
}
288
288
289
- self . annotate ( i. hir_id , & i. attrs , i . span , kind, |v| intravisit:: walk_item ( v, i) ) ;
289
+ self . annotate ( i. hir_id , & i. attrs , kind, |v| intravisit:: walk_item ( v, i) ) ;
290
290
self . in_trait_impl = orig_in_trait_impl;
291
291
}
292
292
293
293
fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
294
- self . annotate ( ti. hir_id , & ti. attrs , ti . span , AnnotationKind :: Required , |v| {
294
+ self . annotate ( ti. hir_id , & ti. attrs , AnnotationKind :: Required , |v| {
295
295
intravisit:: walk_trait_item ( v, ti) ;
296
296
} ) ;
297
297
}
298
298
299
299
fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
300
300
let kind =
301
301
if self . in_trait_impl { AnnotationKind :: Prohibited } else { AnnotationKind :: Required } ;
302
- self . annotate ( ii. hir_id , & ii. attrs , ii . span , kind, |v| {
302
+ self . annotate ( ii. hir_id , & ii. attrs , kind, |v| {
303
303
intravisit:: walk_impl_item ( v, ii) ;
304
304
} ) ;
305
305
}
306
306
307
307
fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > , g : & ' tcx Generics < ' tcx > , item_id : HirId ) {
308
- let span = self . tcx . hir ( ) . span ( var. id ) ;
309
- self . annotate ( var. id , & var. attrs , span, AnnotationKind :: Required , |v| {
308
+ self . annotate ( var. id , & var. attrs , AnnotationKind :: Required , |v| {
310
309
if let Some ( ctor_hir_id) = var. data . ctor_hir_id ( ) {
311
- v. annotate ( ctor_hir_id, & var. attrs , span , AnnotationKind :: Required , |_| { } ) ;
310
+ v. annotate ( ctor_hir_id, & var. attrs , AnnotationKind :: Required , |_| { } ) ;
312
311
}
313
312
314
313
intravisit:: walk_variant ( v, var, g, item_id)
315
314
} )
316
315
}
317
316
318
317
fn visit_struct_field ( & mut self , s : & ' tcx StructField < ' tcx > ) {
319
- let span = self . tcx . hir ( ) . span ( s. hir_id ) ;
320
- self . annotate ( s. hir_id , & s. attrs , span, AnnotationKind :: Required , |v| {
318
+ self . annotate ( s. hir_id , & s. attrs , AnnotationKind :: Required , |v| {
321
319
intravisit:: walk_struct_field ( v, s) ;
322
320
} ) ;
323
321
}
324
322
325
323
fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
326
- self . annotate ( i. hir_id , & i. attrs , i . span , AnnotationKind :: Required , |v| {
324
+ self . annotate ( i. hir_id , & i. attrs , AnnotationKind :: Required , |v| {
327
325
intravisit:: walk_foreign_item ( v, i) ;
328
326
} ) ;
329
327
}
330
328
331
329
fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef < ' tcx > ) {
332
- let span = self . tcx . hir ( ) . span ( md. hir_id ) ;
333
- self . annotate ( md. hir_id , & md. attrs , span, AnnotationKind :: Required , |_| { } ) ;
330
+ self . annotate ( md. hir_id , & md. attrs , AnnotationKind :: Required , |_| { } ) ;
334
331
}
335
332
}
336
333
@@ -340,13 +337,14 @@ struct MissingStabilityAnnotations<'a, 'tcx> {
340
337
}
341
338
342
339
impl < ' a , ' tcx > MissingStabilityAnnotations < ' a , ' tcx > {
343
- fn check_missing_stability ( & self , hir_id : HirId , span : Span ) {
340
+ fn check_missing_stability ( & self , hir_id : HirId ) {
344
341
let stab = self . tcx . stability ( ) . local_stability ( hir_id) ;
345
342
let is_error =
346
343
!self . tcx . sess . opts . test && stab. is_none ( ) && self . access_levels . is_reachable ( hir_id) ;
347
344
if is_error {
348
345
let def_id = self . tcx . hir ( ) . local_def_id ( hir_id) ;
349
346
let descr = self . tcx . def_kind ( def_id) . descr ( def_id. to_def_id ( ) ) ;
347
+ let span = self . tcx . hir ( ) . span ( hir_id) ;
350
348
self . tcx . sess . span_err ( span, & format ! ( "{} has missing stability attribute" , descr) ) ;
351
349
}
352
350
}
@@ -367,45 +365,42 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
367
365
// optional. They inherit stability from their parents when unannotated.
368
366
hir:: ItemKind :: Impl { of_trait : None , .. } | hir:: ItemKind :: ForeignMod ( ..) => { }
369
367
370
- _ => self . check_missing_stability ( i. hir_id , i . span ) ,
368
+ _ => self . check_missing_stability ( i. hir_id ) ,
371
369
}
372
370
373
371
intravisit:: walk_item ( self , i)
374
372
}
375
373
376
374
fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
377
- self . check_missing_stability ( ti. hir_id , ti . span ) ;
375
+ self . check_missing_stability ( ti. hir_id ) ;
378
376
intravisit:: walk_trait_item ( self , ti) ;
379
377
}
380
378
381
379
fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
382
380
let impl_def_id = self . tcx . hir ( ) . local_def_id ( self . tcx . hir ( ) . get_parent_item ( ii. hir_id ) ) ;
383
381
if self . tcx . impl_trait_ref ( impl_def_id) . is_none ( ) {
384
- self . check_missing_stability ( ii. hir_id , ii . span ) ;
382
+ self . check_missing_stability ( ii. hir_id ) ;
385
383
}
386
384
intravisit:: walk_impl_item ( self , ii) ;
387
385
}
388
386
389
387
fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > , g : & ' tcx Generics < ' tcx > , item_id : HirId ) {
390
- let span = self . tcx . hir ( ) . span ( var. id ) ;
391
- self . check_missing_stability ( var. id , span) ;
388
+ self . check_missing_stability ( var. id ) ;
392
389
intravisit:: walk_variant ( self , var, g, item_id) ;
393
390
}
394
391
395
392
fn visit_struct_field ( & mut self , s : & ' tcx StructField < ' tcx > ) {
396
- let span = self . tcx . hir ( ) . span ( s. hir_id ) ;
397
- self . check_missing_stability ( s. hir_id , span) ;
393
+ self . check_missing_stability ( s. hir_id ) ;
398
394
intravisit:: walk_struct_field ( self , s) ;
399
395
}
400
396
401
397
fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
402
- self . check_missing_stability ( i. hir_id , i . span ) ;
398
+ self . check_missing_stability ( i. hir_id ) ;
403
399
intravisit:: walk_foreign_item ( self , i) ;
404
400
}
405
401
406
402
fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef < ' tcx > ) {
407
- let span = self . tcx . hir ( ) . span ( md. hir_id ) ;
408
- self . check_missing_stability ( md. hir_id , span) ;
403
+ self . check_missing_stability ( md. hir_id ) ;
409
404
}
410
405
}
411
406
@@ -465,13 +460,9 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
465
460
annotator. parent_stab = Some ( stability) ;
466
461
}
467
462
468
- annotator. annotate (
469
- hir:: CRATE_HIR_ID ,
470
- & krate. item . attrs ,
471
- krate. item . span ,
472
- AnnotationKind :: Required ,
473
- |v| intravisit:: walk_crate ( v, krate) ,
474
- ) ;
463
+ annotator. annotate ( hir:: CRATE_HIR_ID , & krate. item . attrs , AnnotationKind :: Required , |v| {
464
+ intravisit:: walk_crate ( v, krate)
465
+ } ) ;
475
466
}
476
467
index
477
468
}
@@ -593,7 +584,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
593
584
if tcx. stability ( ) . staged_api [ & LOCAL_CRATE ] {
594
585
let krate = tcx. hir ( ) . krate ( ) ;
595
586
let mut missing = MissingStabilityAnnotations { tcx, access_levels } ;
596
- missing. check_missing_stability ( hir:: CRATE_HIR_ID , krate . item . span ) ;
587
+ missing. check_missing_stability ( hir:: CRATE_HIR_ID ) ;
597
588
intravisit:: walk_crate ( & mut missing, krate) ;
598
589
krate. visit_all_item_likes ( & mut missing. as_deep_visitor ( ) ) ;
599
590
}
0 commit comments