@@ -53,18 +53,18 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
5353 & mut self ,
5454 hir_id : HirId ,
5555 attrs : & [ Attribute ] ,
56- item_sp : Span ,
5756 kind : AnnotationKind ,
5857 visit_children : F ,
5958 ) where
6059 F : FnOnce ( & mut Self ) ,
6160 {
6261 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) ;
6463 return ;
6564 }
6665
6766 // This crate explicitly wants staged API.
67+ let item_sp = self . tcx . hir ( ) . span ( hir_id) ;
6868
6969 debug ! ( "annotate(id = {:?}, attrs = {:?})" , hir_id, attrs) ;
7070 if let Some ( ..) = attr:: find_deprecation ( & self . tcx . sess . parse_sess , attrs, item_sp) {
@@ -198,7 +198,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
198198 & mut self ,
199199 hir_id : HirId ,
200200 attrs : & [ Attribute ] ,
201- item_sp : Span ,
202201 kind : AnnotationKind ,
203202 visit_children : impl FnOnce ( & mut Self ) ,
204203 ) {
@@ -232,6 +231,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
232231 }
233232 }
234233
234+ let item_sp = self . tcx . hir ( ) . span ( hir_id) ;
235235 if let Some ( depr) = attr:: find_deprecation ( & self . tcx . sess . parse_sess , attrs, item_sp) {
236236 if kind == AnnotationKind :: Prohibited {
237237 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> {
280280 }
281281 hir:: ItemKind :: Struct ( ref sd, _) => {
282282 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 , |_| { } )
284284 }
285285 }
286286 _ => { }
287287 }
288288
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) ) ;
290290 self . in_trait_impl = orig_in_trait_impl;
291291 }
292292
293293 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| {
295295 intravisit:: walk_trait_item ( v, ti) ;
296296 } ) ;
297297 }
298298
299299 fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
300300 let kind =
301301 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| {
303303 intravisit:: walk_impl_item ( v, ii) ;
304304 } ) ;
305305 }
306306
307307 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| {
310309 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 , |_| { } ) ;
312311 }
313312
314313 intravisit:: walk_variant ( v, var, g, item_id)
315314 } )
316315 }
317316
318317 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| {
321319 intravisit:: walk_struct_field ( v, s) ;
322320 } ) ;
323321 }
324322
325323 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| {
327325 intravisit:: walk_foreign_item ( v, i) ;
328326 } ) ;
329327 }
330328
331329 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 , |_| { } ) ;
334331 }
335332}
336333
@@ -340,13 +337,14 @@ struct MissingStabilityAnnotations<'a, 'tcx> {
340337}
341338
342339impl < ' 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 ) {
344341 let stab = self . tcx . stability ( ) . local_stability ( hir_id) ;
345342 let is_error =
346343 !self . tcx . sess . opts . test && stab. is_none ( ) && self . access_levels . is_reachable ( hir_id) ;
347344 if is_error {
348345 let def_id = self . tcx . hir ( ) . local_def_id ( hir_id) ;
349346 let descr = self . tcx . def_kind ( def_id) . descr ( def_id. to_def_id ( ) ) ;
347+ let span = self . tcx . hir ( ) . span ( hir_id) ;
350348 self . tcx . sess . span_err ( span, & format ! ( "{} has missing stability attribute" , descr) ) ;
351349 }
352350 }
@@ -367,45 +365,42 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
367365 // optional. They inherit stability from their parents when unannotated.
368366 hir:: ItemKind :: Impl { of_trait : None , .. } | hir:: ItemKind :: ForeignMod ( ..) => { }
369367
370- _ => self . check_missing_stability ( i. hir_id , i . span ) ,
368+ _ => self . check_missing_stability ( i. hir_id ) ,
371369 }
372370
373371 intravisit:: walk_item ( self , i)
374372 }
375373
376374 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 ) ;
378376 intravisit:: walk_trait_item ( self , ti) ;
379377 }
380378
381379 fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
382380 let impl_def_id = self . tcx . hir ( ) . local_def_id ( self . tcx . hir ( ) . get_parent_item ( ii. hir_id ) ) ;
383381 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 ) ;
385383 }
386384 intravisit:: walk_impl_item ( self , ii) ;
387385 }
388386
389387 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 ) ;
392389 intravisit:: walk_variant ( self , var, g, item_id) ;
393390 }
394391
395392 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 ) ;
398394 intravisit:: walk_struct_field ( self , s) ;
399395 }
400396
401397 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 ) ;
403399 intravisit:: walk_foreign_item ( self , i) ;
404400 }
405401
406402 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 ) ;
409404 }
410405}
411406
@@ -465,13 +460,9 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
465460 annotator. parent_stab = Some ( stability) ;
466461 }
467462
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+ } ) ;
475466 }
476467 index
477468}
@@ -593,7 +584,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
593584 if tcx. stability ( ) . staged_api [ & LOCAL_CRATE ] {
594585 let krate = tcx. hir ( ) . krate ( ) ;
595586 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 ) ;
597588 intravisit:: walk_crate ( & mut missing, krate) ;
598589 krate. visit_all_item_likes ( & mut missing. as_deep_visitor ( ) ) ;
599590 }
0 commit comments