@@ -38,7 +38,7 @@ use rustc_feature::{deprecated_attributes, AttributeGate, AttributeTemplate, Att
38
38
use rustc_feature:: { GateIssue , Stability } ;
39
39
use rustc_hir as hir;
40
40
use rustc_hir:: def:: { DefKind , Res } ;
41
- use rustc_hir:: def_id:: { DefId , LocalDefId , LocalDefIdSet } ;
41
+ use rustc_hir:: def_id:: { DefId , LocalDefId , LocalDefIdSet , CRATE_DEF_ID } ;
42
42
use rustc_hir:: { ForeignItemKind , GenericParamKind , PatKind } ;
43
43
use rustc_hir:: { HirId , Node } ;
44
44
use rustc_index:: vec:: Idx ;
@@ -511,7 +511,7 @@ impl MissingDoc {
511
511
fn check_missing_docs_attrs (
512
512
& self ,
513
513
cx : & LateContext < ' _ > ,
514
- id : hir :: HirId ,
514
+ def_id : LocalDefId ,
515
515
sp : Span ,
516
516
article : & ' static str ,
517
517
desc : & ' static str ,
@@ -530,13 +530,13 @@ impl MissingDoc {
530
530
// Only check publicly-visible items, using the result from the privacy pass.
531
531
// It's an option so the crate root can also use this function (it doesn't
532
532
// have a `NodeId`).
533
- if id != hir :: CRATE_HIR_ID {
534
- if !cx. access_levels . is_exported ( id ) {
533
+ if def_id != CRATE_DEF_ID {
534
+ if !cx. access_levels . is_exported ( def_id ) {
535
535
return ;
536
536
}
537
537
}
538
538
539
- let attrs = cx. tcx . hir ( ) . attrs ( id ) ;
539
+ let attrs = cx. tcx . get_attrs ( def_id . to_def_id ( ) ) ;
540
540
let has_doc = attrs. iter ( ) . any ( |a| has_doc ( cx. sess ( ) , a) ) ;
541
541
if !has_doc {
542
542
cx. struct_span_lint (
@@ -568,12 +568,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
568
568
}
569
569
570
570
fn check_crate ( & mut self , cx : & LateContext < ' _ > , krate : & hir:: Crate < ' _ > ) {
571
- self . check_missing_docs_attrs ( cx, hir :: CRATE_HIR_ID , krate. module ( ) . inner , "the" , "crate" ) ;
571
+ self . check_missing_docs_attrs ( cx, CRATE_DEF_ID , krate. module ( ) . inner , "the" , "crate" ) ;
572
572
573
573
for macro_def in krate. exported_macros ( ) {
574
574
// Non exported macros should be skipped, since `missing_docs` only
575
575
// applies to externally visible items.
576
- if !cx. access_levels . is_exported ( macro_def. hir_id ( ) ) {
576
+ if !cx. access_levels . is_exported ( macro_def. def_id ) {
577
577
continue ;
578
578
}
579
579
@@ -632,7 +632,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
632
632
633
633
let ( article, desc) = cx. tcx . article_and_description ( it. def_id . to_def_id ( ) ) ;
634
634
635
- self . check_missing_docs_attrs ( cx, it. hir_id ( ) , it. span , article, desc) ;
635
+ self . check_missing_docs_attrs ( cx, it. def_id , it. span , article, desc) ;
636
636
}
637
637
638
638
fn check_trait_item ( & mut self , cx : & LateContext < ' _ > , trait_item : & hir:: TraitItem < ' _ > ) {
@@ -642,7 +642,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
642
642
643
643
let ( article, desc) = cx. tcx . article_and_description ( trait_item. def_id . to_def_id ( ) ) ;
644
644
645
- self . check_missing_docs_attrs ( cx, trait_item. hir_id ( ) , trait_item. span , article, desc) ;
645
+ self . check_missing_docs_attrs ( cx, trait_item. def_id , trait_item. span , article, desc) ;
646
646
}
647
647
648
648
fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & hir:: ImplItem < ' _ > ) {
@@ -652,22 +652,23 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
652
652
}
653
653
654
654
let ( article, desc) = cx. tcx . article_and_description ( impl_item. def_id . to_def_id ( ) ) ;
655
- self . check_missing_docs_attrs ( cx, impl_item. hir_id ( ) , impl_item. span , article, desc) ;
655
+ self . check_missing_docs_attrs ( cx, impl_item. def_id , impl_item. span , article, desc) ;
656
656
}
657
657
658
658
fn check_foreign_item ( & mut self , cx : & LateContext < ' _ > , foreign_item : & hir:: ForeignItem < ' _ > ) {
659
659
let ( article, desc) = cx. tcx . article_and_description ( foreign_item. def_id . to_def_id ( ) ) ;
660
- self . check_missing_docs_attrs ( cx, foreign_item. hir_id ( ) , foreign_item. span , article, desc) ;
660
+ self . check_missing_docs_attrs ( cx, foreign_item. def_id , foreign_item. span , article, desc) ;
661
661
}
662
662
663
663
fn check_field_def ( & mut self , cx : & LateContext < ' _ > , sf : & hir:: FieldDef < ' _ > ) {
664
664
if !sf. is_positional ( ) {
665
- self . check_missing_docs_attrs ( cx, sf. hir_id , sf. span , "a" , "struct field" )
665
+ let def_id = cx. tcx . hir ( ) . local_def_id ( sf. hir_id ) ;
666
+ self . check_missing_docs_attrs ( cx, def_id, sf. span , "a" , "struct field" )
666
667
}
667
668
}
668
669
669
670
fn check_variant ( & mut self , cx : & LateContext < ' _ > , v : & hir:: Variant < ' _ > ) {
670
- self . check_missing_docs_attrs ( cx, v. id , v. span , "a" , "variant" ) ;
671
+ self . check_missing_docs_attrs ( cx, cx . tcx . hir ( ) . local_def_id ( v. id ) , v. span , "a" , "variant" ) ;
671
672
}
672
673
}
673
674
@@ -709,7 +710,7 @@ declare_lint_pass!(MissingCopyImplementations => [MISSING_COPY_IMPLEMENTATIONS])
709
710
710
711
impl < ' tcx > LateLintPass < ' tcx > for MissingCopyImplementations {
711
712
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & hir:: Item < ' _ > ) {
712
- if !cx. access_levels . is_reachable ( item. hir_id ( ) ) {
713
+ if !cx. access_levels . is_reachable ( item. def_id ) {
713
714
return ;
714
715
}
715
716
let ( def, ty) = match item. kind {
@@ -796,7 +797,7 @@ impl_lint_pass!(MissingDebugImplementations => [MISSING_DEBUG_IMPLEMENTATIONS]);
796
797
797
798
impl < ' tcx > LateLintPass < ' tcx > for MissingDebugImplementations {
798
799
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & hir:: Item < ' _ > ) {
799
- if !cx. access_levels . is_reachable ( item. hir_id ( ) ) {
800
+ if !cx. access_levels . is_reachable ( item. def_id ) {
800
801
return ;
801
802
}
802
803
@@ -1314,14 +1315,14 @@ impl UnreachablePub {
1314
1315
& self ,
1315
1316
cx : & LateContext < ' _ > ,
1316
1317
what : & str ,
1317
- id : hir :: HirId ,
1318
+ def_id : LocalDefId ,
1318
1319
vis : & hir:: Visibility < ' _ > ,
1319
1320
span : Span ,
1320
1321
exportable : bool ,
1321
1322
) {
1322
1323
let mut applicability = Applicability :: MachineApplicable ;
1323
1324
match vis. node {
1324
- hir:: VisibilityKind :: Public if !cx. access_levels . is_reachable ( id ) => {
1325
+ hir:: VisibilityKind :: Public if !cx. access_levels . is_reachable ( def_id ) => {
1325
1326
if span. from_expansion ( ) {
1326
1327
applicability = Applicability :: MaybeIncorrect ;
1327
1328
}
@@ -1354,26 +1355,27 @@ impl UnreachablePub {
1354
1355
1355
1356
impl < ' tcx > LateLintPass < ' tcx > for UnreachablePub {
1356
1357
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & hir:: Item < ' _ > ) {
1357
- self . perform_lint ( cx, "item" , item. hir_id ( ) , & item. vis , item. span , true ) ;
1358
+ self . perform_lint ( cx, "item" , item. def_id , & item. vis , item. span , true ) ;
1358
1359
}
1359
1360
1360
1361
fn check_foreign_item ( & mut self , cx : & LateContext < ' _ > , foreign_item : & hir:: ForeignItem < ' tcx > ) {
1361
1362
self . perform_lint (
1362
1363
cx,
1363
1364
"item" ,
1364
- foreign_item. hir_id ( ) ,
1365
+ foreign_item. def_id ,
1365
1366
& foreign_item. vis ,
1366
1367
foreign_item. span ,
1367
1368
true ,
1368
1369
) ;
1369
1370
}
1370
1371
1371
1372
fn check_field_def ( & mut self , cx : & LateContext < ' _ > , field : & hir:: FieldDef < ' _ > ) {
1372
- self . perform_lint ( cx, "field" , field. hir_id , & field. vis , field. span , false ) ;
1373
+ let def_id = cx. tcx . hir ( ) . local_def_id ( field. hir_id ) ;
1374
+ self . perform_lint ( cx, "field" , def_id, & field. vis , field. span , false ) ;
1373
1375
}
1374
1376
1375
1377
fn check_impl_item ( & mut self , cx : & LateContext < ' _ > , impl_item : & hir:: ImplItem < ' _ > ) {
1376
- self . perform_lint ( cx, "item" , impl_item. hir_id ( ) , & impl_item. vis , impl_item. span , false ) ;
1378
+ self . perform_lint ( cx, "item" , impl_item. def_id , & impl_item. vis , impl_item. span , false ) ;
1377
1379
}
1378
1380
}
1379
1381
0 commit comments