@@ -51,7 +51,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
5151 return InferOk { value : ty, obligations : vec ! [ ] } ;
5252 }
5353 let mut obligations = vec ! [ ] ;
54- let replace_opaque_type = |def_id| self . opaque_type_origin ( def_id, span) . is_some ( ) ;
54+ let replace_opaque_type = |def_id : DefId | {
55+ def_id
56+ . as_local ( )
57+ . map_or ( false , |def_id| self . opaque_type_origin ( def_id, span) . is_some ( ) )
58+ } ;
5559 let value = ty. fold_with ( & mut ty:: fold:: BottomUpFolder {
5660 tcx : self . tcx ,
5761 lt_op : |lt| lt,
@@ -96,6 +100,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
96100 let ( a, b) = if a_is_expected { ( a, b) } else { ( b, a) } ;
97101 let process = |a : Ty < ' tcx > , b : Ty < ' tcx > | match * a. kind ( ) {
98102 ty:: Opaque ( def_id, substs) if def_id. is_local ( ) => {
103+ let def_id = def_id. expect_local ( ) ;
99104 let origin = if self . defining_use_anchor . is_some ( ) {
100105 // Check that this is `impl Trait` type is
101106 // declared by `parent_def_id` -- i.e., one whose
@@ -141,7 +146,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
141146 // no one encounters it in practice.
142147 // It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
143148 // where it is of no concern, so we only check for TAITs.
144- if let Some ( OpaqueTyOrigin :: TyAlias ) = self . opaque_type_origin ( did2, cause. span )
149+ if let Some ( OpaqueTyOrigin :: TyAlias ) =
150+ did2. as_local ( ) . and_then ( |did2| self . opaque_type_origin ( did2, cause. span ) )
145151 {
146152 self . tcx
147153 . sess
@@ -399,8 +405,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
399405 }
400406
401407 #[ instrument( skip( self ) , level = "trace" ) ]
402- pub fn opaque_type_origin ( & self , opaque_def_id : DefId , span : Span ) -> Option < OpaqueTyOrigin > {
403- let def_id = opaque_def_id. as_local ( ) ?;
408+ pub fn opaque_type_origin ( & self , def_id : LocalDefId , span : Span ) -> Option < OpaqueTyOrigin > {
404409 let opaque_hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
405410 let parent_def_id = self . defining_use_anchor ?;
406411 let item_kind = & self . tcx . hir ( ) . expect_item ( def_id) . kind ;
@@ -409,7 +414,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
409414 span_bug ! (
410415 span,
411416 "weird opaque type: {:#?}, {:#?}" ,
412- opaque_def_id ,
417+ def_id ,
413418 item_kind
414419 )
415420 } ;
@@ -428,12 +433,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
428433 }
429434
430435 #[ instrument( skip( self ) , level = "trace" ) ]
431- fn opaque_ty_origin_unchecked ( & self , opaque_def_id : DefId , span : Span ) -> OpaqueTyOrigin {
432- let def_id = opaque_def_id. as_local ( ) . unwrap ( ) ;
436+ fn opaque_ty_origin_unchecked ( & self , def_id : LocalDefId , span : Span ) -> OpaqueTyOrigin {
433437 let origin = match self . tcx . hir ( ) . expect_item ( def_id) . kind {
434438 hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { origin, .. } ) => origin,
435439 ref itemkind => {
436- span_bug ! ( span, "weird opaque type: {:?}, {:#?}" , opaque_def_id , itemkind)
440+ span_bug ! ( span, "weird opaque type: {:?}, {:#?}" , def_id , itemkind)
437441 }
438442 } ;
439443 trace ! ( ?origin) ;
@@ -557,7 +561,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
557561 obligations = self . at ( & cause, param_env) . eq ( prev, hidden_ty) ?. obligations ;
558562 }
559563
560- let item_bounds = tcx. bound_explicit_item_bounds ( def_id) ;
564+ let item_bounds = tcx. bound_explicit_item_bounds ( def_id. to_def_id ( ) ) ;
561565
562566 for predicate in item_bounds. transpose_iter ( ) . map ( |e| e. map_bound ( |( p, _) | * p) ) {
563567 debug ! ( ?predicate) ;
@@ -579,7 +583,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
579583 }
580584 // Replace all other mentions of the same opaque type with the hidden type,
581585 // as the bounds must hold on the hidden type after all.
582- ty:: Opaque ( def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
586+ ty:: Opaque ( def_id2, substs2)
587+ if def_id. to_def_id ( ) == def_id2 && substs == substs2 =>
588+ {
583589 hidden_ty
584590 }
585591 _ => ty,
0 commit comments