@@ -104,10 +104,11 @@ declare_lint! {
104
104
declare_lint_pass ! ( BoxPointers => [ BOX_POINTERS ] ) ;
105
105
106
106
impl 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 < ' _ > ) {
108
108
for leaf in ty. walk ( ) {
109
109
if let GenericArgKind :: Type ( leaf_ty) = leaf. unpack ( ) {
110
110
if leaf_ty. is_box ( ) {
111
+ let span = cx. tcx . hir ( ) . span ( hir_id) ;
111
112
cx. struct_span_lint ( BOX_POINTERS , span, |lint| {
112
113
lint. build ( & format ! ( "type uses owned (Box type) pointers: {}" , ty) ) . emit ( )
113
114
} ) ;
@@ -126,7 +127,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
126
127
| hir:: ItemKind :: Struct ( ..)
127
128
| hir:: ItemKind :: Union ( ..) => {
128
129
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) )
130
131
}
131
132
_ => ( ) ,
132
133
}
@@ -136,8 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
136
137
hir:: ItemKind :: Struct ( ref struct_def, _) | hir:: ItemKind :: Union ( ref struct_def, _) => {
137
138
for struct_field in struct_def. fields ( ) {
138
139
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) ) ;
141
141
}
142
142
}
143
143
_ => ( ) ,
@@ -146,7 +146,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers {
146
146
147
147
fn check_expr ( & mut self , cx : & LateContext < ' _ , ' _ > , e : & hir:: Expr < ' _ > ) {
148
148
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) ;
150
150
}
151
151
}
152
152
@@ -351,9 +351,8 @@ impl MissingDoc {
351
351
fn check_missing_docs_attrs (
352
352
& self ,
353
353
cx : & LateContext < ' _ , ' _ > ,
354
- id : Option < hir:: HirId > ,
354
+ id : hir:: HirId ,
355
355
attrs : & [ ast:: Attribute ] ,
356
- sp : Span ,
357
356
article : & ' static str ,
358
357
desc : & ' static str ,
359
358
) {
@@ -371,14 +370,15 @@ impl MissingDoc {
371
370
// Only check publicly-visible items, using the result from the privacy pass.
372
371
// It's an option so the crate root can also use this function (it doesn't
373
372
// have a `NodeId`).
374
- if let Some ( id ) = id {
373
+ if id != hir :: CRATE_HIR_ID {
375
374
if !cx. access_levels . is_exported ( id) {
376
375
return ;
377
376
}
378
377
}
379
378
380
379
let has_doc = attrs. iter ( ) . any ( |a| has_doc ( a) ) ;
381
380
if !has_doc {
381
+ let sp = cx. tcx . hir ( ) . span ( id) ;
382
382
cx. struct_span_lint (
383
383
MISSING_DOCS ,
384
384
cx. tcx . sess . source_map ( ) . guess_head_span ( sp) ,
@@ -408,7 +408,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
408
408
}
409
409
410
410
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" ) ;
412
412
413
413
for macro_def in krate. exported_macros {
414
414
let has_doc = macro_def. attrs . iter ( ) . any ( |a| has_doc ( a) ) ;
@@ -467,7 +467,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
467
467
let def_id = cx. tcx . hir ( ) . local_def_id ( it. hir_id ) ;
468
468
let ( article, desc) = cx. tcx . article_and_description ( def_id. to_def_id ( ) ) ;
469
469
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) ;
471
471
}
472
472
473
473
fn check_trait_item ( & mut self , cx : & LateContext < ' _ , ' _ > , trait_item : & hir:: TraitItem < ' _ > ) {
@@ -478,14 +478,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
478
478
let def_id = cx. tcx . hir ( ) . local_def_id ( trait_item. hir_id ) ;
479
479
let ( article, desc) = cx. tcx . article_and_description ( def_id. to_def_id ( ) ) ;
480
480
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) ;
489
482
}
490
483
491
484
fn check_impl_item ( & mut self , cx : & LateContext < ' _ , ' _ > , impl_item : & hir:: ImplItem < ' _ > ) {
@@ -496,26 +489,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
496
489
497
490
let def_id = cx. tcx . hir ( ) . local_def_id ( impl_item. hir_id ) ;
498
491
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) ;
507
493
}
508
494
509
495
fn check_struct_field ( & mut self , cx : & LateContext < ' _ , ' _ > , sf : & hir:: StructField < ' _ > ) {
510
496
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" )
513
498
}
514
499
}
515
500
516
501
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" ) ;
519
503
}
520
504
}
521
505
@@ -965,12 +949,12 @@ impl UnreachablePub {
965
949
what : & str ,
966
950
id : hir:: HirId ,
967
951
vis : & hir:: Visibility < ' _ > ,
968
- span : Span ,
969
952
exportable : bool ,
970
953
) {
971
954
let mut applicability = Applicability :: MachineApplicable ;
972
955
match vis. node {
973
956
hir:: VisibilityKind :: Public if !cx. access_levels . is_reachable ( id) => {
957
+ let span = cx. tcx . hir ( ) . span ( id) ;
974
958
if span. from_expansion ( ) {
975
959
applicability = Applicability :: MaybeIncorrect ;
976
960
}
@@ -1003,31 +987,23 @@ impl UnreachablePub {
1003
987
1004
988
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for UnreachablePub {
1005
989
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 ) ;
1007
991
}
1008
992
1009
993
fn check_foreign_item (
1010
994
& mut self ,
1011
995
cx : & LateContext < ' _ , ' _ > ,
1012
996
foreign_item : & hir:: ForeignItem < ' tcx > ,
1013
997
) {
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 ) ;
1022
999
}
1023
1000
1024
1001
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 ) ;
1027
1003
}
1028
1004
1029
1005
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 ) ;
1031
1007
}
1032
1008
}
1033
1009
0 commit comments