@@ -839,17 +839,15 @@ fn convert_variant(
839
839
adt_kind,
840
840
parent_did. to_def_id ( ) ,
841
841
recovered,
842
- adt_kind == AdtKind :: Struct && tcx. has_attr ( parent_did. to_def_id ( ) , sym:: non_exhaustive)
843
- || variant_did. map_or ( false , |variant_did| {
844
- tcx. has_attr ( variant_did. to_def_id ( ) , sym:: non_exhaustive)
845
- } ) ,
842
+ adt_kind == AdtKind :: Struct && tcx. has_attr ( parent_did, sym:: non_exhaustive)
843
+ || variant_did
844
+ . map_or ( false , |variant_did| tcx. has_attr ( variant_did, sym:: non_exhaustive) ) ,
846
845
)
847
846
}
848
847
849
- fn adt_def ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> ty:: AdtDef < ' _ > {
848
+ fn adt_def ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: AdtDef < ' _ > {
850
849
use rustc_hir:: * ;
851
850
852
- let def_id = def_id. expect_local ( ) ;
853
851
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
854
852
let Node :: Item ( item) = tcx. hir ( ) . get ( hir_id) else {
855
853
bug ! ( ) ;
@@ -908,8 +906,8 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtDef<'_> {
908
906
tcx. mk_adt_def ( def_id. to_def_id ( ) , kind, variants, repr)
909
907
}
910
908
911
- fn trait_def ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> ty:: TraitDef {
912
- let item = tcx. hir ( ) . expect_item ( def_id. expect_local ( ) ) ;
909
+ fn trait_def ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: TraitDef {
910
+ let item = tcx. hir ( ) . expect_item ( def_id) ;
913
911
914
912
let ( is_auto, unsafety, items) = match item. kind {
915
913
hir:: ItemKind :: Trait ( is_auto, unsafety, .., items) => {
@@ -1036,7 +1034,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
1036
1034
} ) ;
1037
1035
1038
1036
ty:: TraitDef {
1039
- def_id,
1037
+ def_id : def_id . to_def_id ( ) ,
1040
1038
unsafety,
1041
1039
paren_sugar,
1042
1040
has_auto_impl : is_auto,
@@ -1091,11 +1089,10 @@ pub fn get_infer_ret_ty<'hir>(output: &'hir hir::FnRetTy<'hir>) -> Option<&'hir
1091
1089
}
1092
1090
1093
1091
#[ instrument( level = "debug" , skip( tcx) ) ]
1094
- fn fn_sig ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> ty:: EarlyBinder < ty:: PolyFnSig < ' _ > > {
1092
+ fn fn_sig ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: EarlyBinder < ty:: PolyFnSig < ' _ > > {
1095
1093
use rustc_hir:: Node :: * ;
1096
1094
use rustc_hir:: * ;
1097
1095
1098
- let def_id = def_id. expect_local ( ) ;
1099
1096
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
1100
1097
1101
1098
let icx = ItemCtxt :: new ( tcx, def_id. to_def_id ( ) ) ;
@@ -1338,9 +1335,12 @@ fn suggest_impl_trait<'tcx>(
1338
1335
None
1339
1336
}
1340
1337
1341
- fn impl_trait_ref ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1342
- let icx = ItemCtxt :: new ( tcx, def_id) ;
1343
- let impl_ = tcx. hir ( ) . expect_item ( def_id. expect_local ( ) ) . expect_impl ( ) ;
1338
+ fn impl_trait_ref (
1339
+ tcx : TyCtxt < ' _ > ,
1340
+ def_id : LocalDefId ,
1341
+ ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1342
+ let icx = ItemCtxt :: new ( tcx, def_id. to_def_id ( ) ) ;
1343
+ let impl_ = tcx. hir ( ) . expect_item ( def_id) . expect_impl ( ) ;
1344
1344
impl_
1345
1345
. of_trait
1346
1346
. as_ref ( )
@@ -1380,9 +1380,9 @@ fn check_impl_constness(
1380
1380
}
1381
1381
}
1382
1382
1383
- fn impl_polarity ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> ty:: ImplPolarity {
1383
+ fn impl_polarity ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: ImplPolarity {
1384
1384
let is_rustc_reservation = tcx. has_attr ( def_id, sym:: rustc_reservation_impl) ;
1385
- let item = tcx. hir ( ) . expect_item ( def_id. expect_local ( ) ) ;
1385
+ let item = tcx. hir ( ) . expect_item ( def_id) ;
1386
1386
match & item. kind {
1387
1387
hir:: ItemKind :: Impl ( hir:: Impl {
1388
1388
polarity : hir:: ImplPolarity :: Negative ( span) ,
@@ -1515,31 +1515,28 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
1515
1515
fty
1516
1516
}
1517
1517
1518
- fn is_foreign_item ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
1519
- match tcx. hir ( ) . get_if_local ( def_id) {
1520
- Some ( Node :: ForeignItem ( ..) ) => true ,
1521
- Some ( _) => false ,
1522
- _ => bug ! ( "is_foreign_item applied to non-local def-id {:?}" , def_id) ,
1518
+ fn is_foreign_item ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> bool {
1519
+ match tcx. hir ( ) . get_by_def_id ( def_id) {
1520
+ Node :: ForeignItem ( ..) => true ,
1521
+ _ => false ,
1523
1522
}
1524
1523
}
1525
1524
1526
- fn generator_kind ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Option < hir:: GeneratorKind > {
1527
- match tcx. hir ( ) . get_if_local ( def_id) {
1528
- Some ( Node :: Expr ( & rustc_hir:: Expr {
1525
+ fn generator_kind ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> Option < hir:: GeneratorKind > {
1526
+ match tcx. hir ( ) . get_by_def_id ( def_id) {
1527
+ Node :: Expr ( & rustc_hir:: Expr {
1529
1528
kind : rustc_hir:: ExprKind :: Closure ( & rustc_hir:: Closure { body, .. } ) ,
1530
1529
..
1531
- } ) ) => tcx. hir ( ) . body ( body) . generator_kind ( ) ,
1532
- Some ( _) => None ,
1533
- _ => bug ! ( "generator_kind applied to non-local def-id {:?}" , def_id) ,
1530
+ } ) => tcx. hir ( ) . body ( body) . generator_kind ( ) ,
1531
+ _ => None ,
1534
1532
}
1535
1533
}
1536
1534
1537
- fn is_type_alias_impl_trait < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> bool {
1538
- match tcx. hir ( ) . get_if_local ( def_id) {
1539
- Some ( Node :: Item ( hir:: Item { kind : hir:: ItemKind :: OpaqueTy ( opaque) , .. } ) ) => {
1535
+ fn is_type_alias_impl_trait < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> bool {
1536
+ match tcx. hir ( ) . get_by_def_id ( def_id) {
1537
+ Node :: Item ( hir:: Item { kind : hir:: ItemKind :: OpaqueTy ( opaque) , .. } ) => {
1540
1538
matches ! ( opaque. origin, hir:: OpaqueTyOrigin :: TyAlias )
1541
1539
}
1542
- Some ( _) => bug ! ( "tried getting opaque_ty_origin for non-opaque: {:?}" , def_id) ,
1543
- _ => bug ! ( "tried getting opaque_ty_origin for non-local def-id {:?}" , def_id) ,
1540
+ _ => bug ! ( "tried getting opaque_ty_origin for non-opaque: {:?}" , def_id) ,
1544
1541
}
1545
1542
}
0 commit comments