@@ -152,10 +152,11 @@ declare_lint! {
152
152
declare_lint_pass ! ( BoxPointers => [ BOX_POINTERS ] ) ;
153
153
154
154
impl BoxPointers {
155
- fn check_heap_type ( & self , cx : & LateContext < ' _ > , span : Span , ty : Ty < ' _ > ) {
155
+ fn check_heap_type ( & self , cx : & LateContext < ' _ > , hir_id : HirId , ty : Ty < ' _ > ) {
156
156
for leaf in ty. walk ( ) {
157
157
if let GenericArgKind :: Type ( leaf_ty) = leaf. unpack ( ) {
158
158
if leaf_ty. is_box ( ) {
159
+ let span = cx. tcx . hir ( ) . span ( hir_id) ;
159
160
cx. struct_span_lint ( BOX_POINTERS , span, |lint| {
160
161
lint. build ( & format ! ( "type uses owned (Box type) pointers: {}" , ty) ) . emit ( )
161
162
} ) ;
@@ -173,7 +174,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
173
174
| hir:: ItemKind :: Enum ( ..)
174
175
| hir:: ItemKind :: Struct ( ..)
175
176
| hir:: ItemKind :: Union ( ..) => {
176
- self . check_heap_type ( cx, it. span , cx. tcx . type_of ( it. def_id ) )
177
+ self . check_heap_type ( cx, it. hir_id ( ) , cx. tcx . type_of ( it. def_id ) )
177
178
}
178
179
_ => ( ) ,
179
180
}
@@ -183,8 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
183
184
hir:: ItemKind :: Struct ( ref struct_def, _) | hir:: ItemKind :: Union ( ref struct_def, _) => {
184
185
for struct_field in struct_def. fields ( ) {
185
186
let def_id = cx. tcx . hir ( ) . local_def_id ( struct_field. hir_id ) ;
186
- let span = cx. tcx . hir ( ) . span ( struct_field. hir_id ) ;
187
- self . check_heap_type ( cx, span, cx. tcx . type_of ( def_id) ) ;
187
+ self . check_heap_type ( cx, struct_field. hir_id , cx. tcx . type_of ( def_id) ) ;
188
188
}
189
189
}
190
190
_ => ( ) ,
@@ -193,7 +193,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
193
193
194
194
fn check_expr ( & mut self , cx : & LateContext < ' _ > , e : & hir:: Expr < ' _ > ) {
195
195
let ty = cx. typeck_results ( ) . node_type ( e. hir_id ) ;
196
- self . check_heap_type ( cx, e. span , ty) ;
196
+ self . check_heap_type ( cx, e. hir_id , ty) ;
197
197
}
198
198
}
199
199
@@ -511,7 +511,6 @@ impl MissingDoc {
511
511
& self ,
512
512
cx : & LateContext < ' _ > ,
513
513
id : hir:: HirId ,
514
- sp : Span ,
515
514
article : & ' static str ,
516
515
desc : & ' static str ,
517
516
) {
@@ -538,6 +537,7 @@ impl MissingDoc {
538
537
let attrs = cx. tcx . hir ( ) . attrs ( id) ;
539
538
let has_doc = attrs. iter ( ) . any ( |a| has_doc ( cx. sess ( ) , a) ) ;
540
539
if !has_doc {
540
+ let sp = cx. tcx . hir ( ) . span ( id) ;
541
541
cx. struct_span_lint (
542
542
MISSING_DOCS ,
543
543
cx. tcx . sess . source_map ( ) . guess_head_span ( sp) ,
@@ -567,8 +567,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
567
567
}
568
568
569
569
fn check_crate ( & mut self , cx : & LateContext < ' _ > , krate : & hir:: Crate < ' _ > ) {
570
- let span = cx. tcx . hir ( ) . span ( hir:: CRATE_HIR_ID ) ;
571
- self . check_missing_docs_attrs ( cx, hir:: CRATE_HIR_ID , span, "the" , "crate" ) ;
570
+ self . check_missing_docs_attrs ( cx, hir:: CRATE_HIR_ID , "the" , "crate" ) ;
572
571
573
572
for macro_def in krate. exported_macros {
574
573
let attrs = cx. tcx . hir ( ) . attrs ( macro_def. hir_id ( ) ) ;
@@ -627,7 +626,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
627
626
628
627
let ( article, desc) = cx. tcx . article_and_description ( it. def_id . to_def_id ( ) ) ;
629
628
630
- self . check_missing_docs_attrs ( cx, it. hir_id ( ) , it . span , article, desc) ;
629
+ self . check_missing_docs_attrs ( cx, it. hir_id ( ) , article, desc) ;
631
630
}
632
631
633
632
fn check_trait_item ( & mut self , cx : & LateContext < ' _ > , trait_item : & hir:: TraitItem < ' _ > ) {
@@ -637,7 +636,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
637
636
638
637
let ( article, desc) = cx. tcx . article_and_description ( trait_item. def_id . to_def_id ( ) ) ;
639
638
640
- self . check_missing_docs_attrs ( cx, trait_item. hir_id ( ) , trait_item . span , article, desc) ;
639
+ self . check_missing_docs_attrs ( cx, trait_item. hir_id ( ) , article, desc) ;
641
640
}
642
641
643
642
fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & hir:: ImplItem < ' _ > ) {
@@ -647,24 +646,22 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
647
646
}
648
647
649
648
let ( article, desc) = cx. tcx . article_and_description ( impl_item. def_id . to_def_id ( ) ) ;
650
- self . check_missing_docs_attrs ( cx, impl_item. hir_id ( ) , impl_item . span , article, desc) ;
649
+ self . check_missing_docs_attrs ( cx, impl_item. hir_id ( ) , article, desc) ;
651
650
}
652
651
653
652
fn check_foreign_item ( & mut self , cx : & LateContext < ' _ > , foreign_item : & hir:: ForeignItem < ' _ > ) {
654
653
let ( article, desc) = cx. tcx . article_and_description ( foreign_item. def_id . to_def_id ( ) ) ;
655
- self . check_missing_docs_attrs ( cx, foreign_item. hir_id ( ) , foreign_item . span , article, desc) ;
654
+ self . check_missing_docs_attrs ( cx, foreign_item. hir_id ( ) , article, desc) ;
656
655
}
657
656
658
657
fn check_struct_field ( & mut self , cx : & LateContext < ' _ > , sf : & hir:: StructField < ' _ > ) {
659
658
if !sf. is_positional ( ) {
660
- let span = cx. tcx . hir ( ) . span ( sf. hir_id ) ;
661
- self . check_missing_docs_attrs ( cx, sf. hir_id , span, "a" , "struct field" )
659
+ self . check_missing_docs_attrs ( cx, sf. hir_id , "a" , "struct field" )
662
660
}
663
661
}
664
662
665
663
fn check_variant ( & mut self , cx : & LateContext < ' _ > , v : & hir:: Variant < ' _ > ) {
666
- let span = cx. tcx . hir ( ) . span ( v. id ) ;
667
- self . check_missing_docs_attrs ( cx, v. id , span, "a" , "variant" ) ;
664
+ self . check_missing_docs_attrs ( cx, v. id , "a" , "variant" ) ;
668
665
}
669
666
}
670
667
@@ -1299,12 +1296,12 @@ impl UnreachablePub {
1299
1296
what : & str ,
1300
1297
id : hir:: HirId ,
1301
1298
vis : & hir:: Visibility < ' _ > ,
1302
- span : Span ,
1303
1299
exportable : bool ,
1304
1300
) {
1305
1301
let mut applicability = Applicability :: MachineApplicable ;
1306
1302
match vis. node {
1307
1303
hir:: VisibilityKind :: Public if !cx. access_levels . is_reachable ( id) => {
1304
+ let span = cx. tcx . hir ( ) . span ( id) ;
1308
1305
if span. from_expansion ( ) {
1309
1306
applicability = Applicability :: MaybeIncorrect ;
1310
1307
}
@@ -1337,27 +1334,19 @@ impl UnreachablePub {
1337
1334
1338
1335
impl < ' tcx > LateLintPass < ' tcx > for UnreachablePub {
1339
1336
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & hir:: Item < ' _ > ) {
1340
- self . perform_lint ( cx, "item" , item. hir_id ( ) , & item. vis , item . span , true ) ;
1337
+ self . perform_lint ( cx, "item" , item. hir_id ( ) , & item. vis , true ) ;
1341
1338
}
1342
1339
1343
1340
fn check_foreign_item ( & mut self , cx : & LateContext < ' _ > , foreign_item : & hir:: ForeignItem < ' tcx > ) {
1344
- self . perform_lint (
1345
- cx,
1346
- "item" ,
1347
- foreign_item. hir_id ( ) ,
1348
- & foreign_item. vis ,
1349
- foreign_item. span ,
1350
- true ,
1351
- ) ;
1341
+ self . perform_lint ( cx, "item" , foreign_item. hir_id ( ) , & foreign_item. vis , true ) ;
1352
1342
}
1353
1343
1354
1344
fn check_struct_field ( & mut self , cx : & LateContext < ' _ > , field : & hir:: StructField < ' _ > ) {
1355
- let span = cx. tcx . hir ( ) . span ( field. hir_id ) ;
1356
- self . perform_lint ( cx, "field" , field. hir_id , & field. vis , span, false ) ;
1345
+ self . perform_lint ( cx, "field" , field. hir_id , & field. vis , false ) ;
1357
1346
}
1358
1347
1359
1348
fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & hir:: ImplItem < ' _ > ) {
1360
- self . perform_lint ( cx, "item" , impl_item. hir_id ( ) , & impl_item. vis , impl_item . span , false ) ;
1349
+ self . perform_lint ( cx, "item" , impl_item. hir_id ( ) , & impl_item. vis , false ) ;
1361
1350
}
1362
1351
}
1363
1352
0 commit comments