@@ -70,7 +70,7 @@ use rustc_data_structures::fx::FxHashMap;
70
70
use rustc_data_structures:: unhash:: UnhashMap ;
71
71
use rustc_hir as hir;
72
72
use rustc_hir:: def:: { DefKind , Res } ;
73
- use rustc_hir:: def_id:: { CrateNum , DefId } ;
73
+ use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , CRATE_DEF_ID } ;
74
74
use rustc_hir:: hir_id:: { HirIdMap , HirIdSet } ;
75
75
use rustc_hir:: intravisit:: { walk_expr, ErasedMap , FnKind , NestedVisitorMap , Visitor } ;
76
76
use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
@@ -90,7 +90,6 @@ use rustc_middle::ty::binding::BindingMode;
90
90
use rustc_middle:: ty:: { layout:: IntegerExt , BorrowKind , DefIdTree , Ty , TyCtxt , TypeAndMut , TypeFoldable , UpvarCapture } ;
91
91
use rustc_semver:: RustcVersion ;
92
92
use rustc_session:: Session ;
93
- use rustc_span:: def_id:: LocalDefId ;
94
93
use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
95
94
use rustc_span:: source_map:: original_sp;
96
95
use rustc_span:: sym;
@@ -216,7 +215,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<
216
215
/// ```
217
216
pub fn in_constant ( cx : & LateContext < ' _ > , id : HirId ) -> bool {
218
217
let parent_id = cx. tcx . hir ( ) . get_parent_item ( id) ;
219
- match cx. tcx . hir ( ) . get ( parent_id) {
218
+ match cx. tcx . hir ( ) . get_by_def_id ( parent_id) {
220
219
Node :: Item ( & Item {
221
220
kind : ItemKind :: Const ( ..) | ItemKind :: Static ( ..) ,
222
221
..
@@ -607,12 +606,13 @@ pub fn get_trait_def_id(cx: &LateContext<'_>, path: &[&str]) -> Option<DefId> {
607
606
/// }
608
607
/// }
609
608
/// ```
610
- pub fn trait_ref_of_method < ' tcx > ( cx : & LateContext < ' tcx > , hir_id : HirId ) -> Option < & ' tcx TraitRef < ' tcx > > {
609
+ pub fn trait_ref_of_method < ' tcx > ( cx : & LateContext < ' tcx > , def_id : LocalDefId ) -> Option < & ' tcx TraitRef < ' tcx > > {
611
610
// Get the implemented trait for the current function
611
+ let hir_id = cx. tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
612
612
let parent_impl = cx. tcx . hir ( ) . get_parent_item ( hir_id) ;
613
613
if_chain ! {
614
- if parent_impl != hir :: CRATE_HIR_ID ;
615
- if let hir:: Node :: Item ( item) = cx. tcx. hir( ) . get ( parent_impl) ;
614
+ if parent_impl != CRATE_DEF_ID ;
615
+ if let hir:: Node :: Item ( item) = cx. tcx. hir( ) . get_by_def_id ( parent_impl) ;
616
616
if let hir:: ItemKind :: Impl ( impl_) = & item. kind;
617
617
then { return impl_. of_trait. as_ref( ) ; }
618
618
}
@@ -1122,14 +1122,13 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool {
1122
1122
/// Returns `true` if the expression is in the program's `#[panic_handler]`.
1123
1123
pub fn is_in_panic_handler ( cx : & LateContext < ' _ > , e : & Expr < ' _ > ) -> bool {
1124
1124
let parent = cx. tcx . hir ( ) . get_parent_item ( e. hir_id ) ;
1125
- let def_id = cx. tcx . hir ( ) . local_def_id ( parent) . to_def_id ( ) ;
1126
- Some ( def_id) == cx. tcx . lang_items ( ) . panic_impl ( )
1125
+ Some ( parent. to_def_id ( ) ) == cx. tcx . lang_items ( ) . panic_impl ( )
1127
1126
}
1128
1127
1129
1128
/// Gets the name of the item the expression is in, if available.
1130
1129
pub fn get_item_name ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> Option < Symbol > {
1131
1130
let parent_id = cx. tcx . hir ( ) . get_parent_item ( expr. hir_id ) ;
1132
- match cx. tcx . hir ( ) . find ( parent_id) {
1131
+ match cx. tcx . hir ( ) . find_by_def_id ( parent_id) {
1133
1132
Some (
1134
1133
Node :: Item ( Item { ident, .. } )
1135
1134
| Node :: TraitItem ( TraitItem { ident, .. } )
@@ -1639,7 +1638,7 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool
1639
1638
return true ;
1640
1639
}
1641
1640
prev_enclosing_node = Some ( enclosing_node) ;
1642
- enclosing_node = map. get_parent_item ( enclosing_node) ;
1641
+ enclosing_node = map. local_def_id_to_hir_id ( map . get_parent_item ( enclosing_node) ) ;
1643
1642
}
1644
1643
1645
1644
false
0 commit comments