@@ -104,10 +104,11 @@ declare_lint! {
104104declare_lint_pass ! ( BoxPointers => [ BOX_POINTERS ] ) ;
105105
106106impl BoxPointers {
107- fn check_heap_type ( & self , cx : & LateContext < ' _ , ' _ > , span : Span , ty : Ty < ' _ > ) {
107+ fn check_heap_type ( & self , cx : & LateContext < ' _ , ' _ > , hir_id : hir :: HirId , ty : Ty < ' _ > ) {
108108 for leaf in ty. walk ( ) {
109109 if let GenericArgKind :: Type ( leaf_ty) = leaf. unpack ( ) {
110110 if leaf_ty. is_box ( ) {
111+ let span = cx. tcx . hir ( ) . span ( hir_id) ;
111112 cx. struct_span_lint ( BOX_POINTERS , span, |lint| {
112113 lint. build ( & format ! ( "type uses owned (Box type) pointers: {}" , ty) ) . emit ( )
113114 } ) ;
@@ -126,7 +127,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
126127 | hir:: ItemKind :: Struct ( ..)
127128 | hir:: ItemKind :: Union ( ..) => {
128129 let def_id = cx. tcx . hir ( ) . local_def_id ( it. hir_id ) ;
129- self . check_heap_type ( cx, it. span , cx. tcx . type_of ( def_id) )
130+ self . check_heap_type ( cx, it. hir_id , cx. tcx . type_of ( def_id) )
130131 }
131132 _ => ( ) ,
132133 }
@@ -136,8 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
136137 hir:: ItemKind :: Struct ( ref struct_def, _) | hir:: ItemKind :: Union ( ref struct_def, _) => {
137138 for struct_field in struct_def. fields ( ) {
138139 let def_id = cx. tcx . hir ( ) . local_def_id ( struct_field. hir_id ) ;
139- let span = cx. tcx . hir ( ) . span ( struct_field. hir_id ) ;
140- self . check_heap_type ( cx, span, cx. tcx . type_of ( def_id) ) ;
140+ self . check_heap_type ( cx, struct_field. hir_id , cx. tcx . type_of ( def_id) ) ;
141141 }
142142 }
143143 _ => ( ) ,
@@ -146,7 +146,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
146146
147147 fn check_expr ( & mut self , cx : & LateContext < ' _ , ' _ > , e : & hir:: Expr < ' _ > ) {
148148 let ty = cx. tables . node_type ( e. hir_id ) ;
149- self . check_heap_type ( cx, e. span , ty) ;
149+ self . check_heap_type ( cx, e. hir_id , ty) ;
150150 }
151151}
152152
@@ -351,9 +351,8 @@ impl MissingDoc {
351351 fn check_missing_docs_attrs (
352352 & self ,
353353 cx : & LateContext < ' _ , ' _ > ,
354- id : Option < hir:: HirId > ,
354+ id : hir:: HirId ,
355355 attrs : & [ ast:: Attribute ] ,
356- sp : Span ,
357356 article : & ' static str ,
358357 desc : & ' static str ,
359358 ) {
@@ -371,14 +370,15 @@ impl MissingDoc {
371370 // Only check publicly-visible items, using the result from the privacy pass.
372371 // It's an option so the crate root can also use this function (it doesn't
373372 // have a `NodeId`).
374- if let Some ( id ) = id {
373+ if id != hir :: CRATE_HIR_ID {
375374 if !cx. access_levels . is_exported ( id) {
376375 return ;
377376 }
378377 }
379378
380379 let has_doc = attrs. iter ( ) . any ( |a| has_doc ( a) ) ;
381380 if !has_doc {
381+ let sp = cx. tcx . hir ( ) . span ( id) ;
382382 cx. struct_span_lint (
383383 MISSING_DOCS ,
384384 cx. tcx . sess . source_map ( ) . guess_head_span ( sp) ,
@@ -408,7 +408,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
408408 }
409409
410410 fn check_crate ( & mut self , cx : & LateContext < ' _ , ' _ > , krate : & hir:: Crate < ' _ > ) {
411- self . check_missing_docs_attrs ( cx, None , & krate. item . attrs , krate . item . span , "the" , "crate" ) ;
411+ self . check_missing_docs_attrs ( cx, hir :: CRATE_HIR_ID , & krate. item . attrs , "the" , "crate" ) ;
412412
413413 for macro_def in krate. exported_macros {
414414 let has_doc = macro_def. attrs . iter ( ) . any ( |a| has_doc ( a) ) ;
@@ -467,7 +467,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
467467 let def_id = cx. tcx . hir ( ) . local_def_id ( it. hir_id ) ;
468468 let ( article, desc) = cx. tcx . article_and_description ( def_id. to_def_id ( ) ) ;
469469
470- self . check_missing_docs_attrs ( cx, Some ( it. hir_id ) , & it. attrs , it . span , article, desc) ;
470+ self . check_missing_docs_attrs ( cx, it. hir_id , & it. attrs , article, desc) ;
471471 }
472472
473473 fn check_trait_item ( & mut self , cx : & LateContext < ' _ , ' _ > , trait_item : & hir:: TraitItem < ' _ > ) {
@@ -478,14 +478,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
478478 let def_id = cx. tcx . hir ( ) . local_def_id ( trait_item. hir_id ) ;
479479 let ( article, desc) = cx. tcx . article_and_description ( def_id. to_def_id ( ) ) ;
480480
481- self . check_missing_docs_attrs (
482- cx,
483- Some ( trait_item. hir_id ) ,
484- & trait_item. attrs ,
485- trait_item. span ,
486- article,
487- desc,
488- ) ;
481+ self . check_missing_docs_attrs ( cx, trait_item. hir_id , & trait_item. attrs , article, desc) ;
489482 }
490483
491484 fn check_impl_item ( & mut self , cx : & LateContext < ' _ , ' _ > , impl_item : & hir:: ImplItem < ' _ > ) {
@@ -496,26 +489,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
496489
497490 let def_id = cx. tcx . hir ( ) . local_def_id ( impl_item. hir_id ) ;
498491 let ( article, desc) = cx. tcx . article_and_description ( def_id. to_def_id ( ) ) ;
499- self . check_missing_docs_attrs (
500- cx,
501- Some ( impl_item. hir_id ) ,
502- & impl_item. attrs ,
503- impl_item. span ,
504- article,
505- desc,
506- ) ;
492+ self . check_missing_docs_attrs ( cx, impl_item. hir_id , & impl_item. attrs , article, desc) ;
507493 }
508494
509495 fn check_struct_field ( & mut self , cx : & LateContext < ' _ , ' _ > , sf : & hir:: StructField < ' _ > ) {
510496 if !sf. is_positional ( ) {
511- let span = cx. tcx . hir ( ) . span ( sf. hir_id ) ;
512- self . check_missing_docs_attrs ( cx, Some ( sf. hir_id ) , & sf. attrs , span, "a" , "struct field" )
497+ self . check_missing_docs_attrs ( cx, sf. hir_id , & sf. attrs , "a" , "struct field" )
513498 }
514499 }
515500
516501 fn check_variant ( & mut self , cx : & LateContext < ' _ , ' _ > , v : & hir:: Variant < ' _ > ) {
517- let span = cx. tcx . hir ( ) . span ( v. id ) ;
518- self . check_missing_docs_attrs ( cx, Some ( v. id ) , & v. attrs , span, "a" , "variant" ) ;
502+ self . check_missing_docs_attrs ( cx, v. id , & v. attrs , "a" , "variant" ) ;
519503 }
520504}
521505
@@ -965,12 +949,12 @@ impl UnreachablePub {
965949 what : & str ,
966950 id : hir:: HirId ,
967951 vis : & hir:: Visibility < ' _ > ,
968- span : Span ,
969952 exportable : bool ,
970953 ) {
971954 let mut applicability = Applicability :: MachineApplicable ;
972955 match vis. node {
973956 hir:: VisibilityKind :: Public if !cx. access_levels . is_reachable ( id) => {
957+ let span = cx. tcx . hir ( ) . span ( id) ;
974958 if span. from_expansion ( ) {
975959 applicability = Applicability :: MaybeIncorrect ;
976960 }
@@ -1003,31 +987,23 @@ impl UnreachablePub {
1003987
1004988impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for UnreachablePub {
1005989 fn check_item ( & mut self , cx : & LateContext < ' _ , ' _ > , item : & hir:: Item < ' _ > ) {
1006- self . perform_lint ( cx, "item" , item. hir_id , & item. vis , item . span , true ) ;
990+ self . perform_lint ( cx, "item" , item. hir_id , & item. vis , true ) ;
1007991 }
1008992
1009993 fn check_foreign_item (
1010994 & mut self ,
1011995 cx : & LateContext < ' _ , ' _ > ,
1012996 foreign_item : & hir:: ForeignItem < ' tcx > ,
1013997 ) {
1014- self . perform_lint (
1015- cx,
1016- "item" ,
1017- foreign_item. hir_id ,
1018- & foreign_item. vis ,
1019- foreign_item. span ,
1020- true ,
1021- ) ;
998+ self . perform_lint ( cx, "item" , foreign_item. hir_id , & foreign_item. vis , true ) ;
1022999 }
10231000
10241001 fn check_struct_field ( & mut self , cx : & LateContext < ' _ , ' _ > , field : & hir:: StructField < ' _ > ) {
1025- let span = cx. tcx . hir ( ) . span ( field. hir_id ) ;
1026- self . perform_lint ( cx, "field" , field. hir_id , & field. vis , span, false ) ;
1002+ self . perform_lint ( cx, "field" , field. hir_id , & field. vis , false ) ;
10271003 }
10281004
10291005 fn check_impl_item ( & mut self , cx : & LateContext < ' _ , ' _ > , impl_item : & hir:: ImplItem < ' _ > ) {
1030- self . perform_lint ( cx, "item" , impl_item. hir_id , & impl_item. vis , impl_item . span , false ) ;
1006+ self . perform_lint ( cx, "item" , impl_item. hir_id , & impl_item. vis , false ) ;
10311007 }
10321008}
10331009
0 commit comments