@@ -51,7 +51,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
51
51
return InferOk { value : ty, obligations : vec ! [ ] } ;
52
52
}
53
53
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
+ } ;
55
59
let value = ty. fold_with ( & mut ty:: fold:: BottomUpFolder {
56
60
tcx : self . tcx ,
57
61
lt_op : |lt| lt,
@@ -96,6 +100,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
96
100
let ( a, b) = if a_is_expected { ( a, b) } else { ( b, a) } ;
97
101
let process = |a : Ty < ' tcx > , b : Ty < ' tcx > | match * a. kind ( ) {
98
102
ty:: Opaque ( def_id, substs) if def_id. is_local ( ) => {
103
+ let def_id = def_id. expect_local ( ) ;
99
104
let origin = if self . defining_use_anchor . is_some ( ) {
100
105
// Check that this is `impl Trait` type is
101
106
// declared by `parent_def_id` -- i.e., one whose
@@ -141,7 +146,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
141
146
// no one encounters it in practice.
142
147
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
143
148
// 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 ) )
145
151
{
146
152
self . tcx
147
153
. sess
@@ -399,8 +405,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
399
405
}
400
406
401
407
#[ 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 > {
404
409
let opaque_hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
405
410
let parent_def_id = self . defining_use_anchor ?;
406
411
let item_kind = & self . tcx . hir ( ) . expect_item ( def_id) . kind ;
@@ -409,7 +414,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
409
414
span_bug ! (
410
415
span,
411
416
"weird opaque type: {:#?}, {:#?}" ,
412
- opaque_def_id ,
417
+ def_id ,
413
418
item_kind
414
419
)
415
420
} ;
@@ -428,12 +433,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
428
433
}
429
434
430
435
#[ 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 {
433
437
let origin = match self . tcx . hir ( ) . expect_item ( def_id) . kind {
434
438
hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { origin, .. } ) => origin,
435
439
ref itemkind => {
436
- span_bug ! ( span, "weird opaque type: {:?}, {:#?}" , opaque_def_id , itemkind)
440
+ span_bug ! ( span, "weird opaque type: {:?}, {:#?}" , def_id , itemkind)
437
441
}
438
442
} ;
439
443
trace ! ( ?origin) ;
@@ -557,7 +561,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
557
561
obligations = self . at ( & cause, param_env) . eq ( prev, hidden_ty) ?. obligations ;
558
562
}
559
563
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 ( ) ) ;
561
565
562
566
for predicate in item_bounds. transpose_iter ( ) . map ( |e| e. map_bound ( |( p, _) | * p) ) {
563
567
debug ! ( ?predicate) ;
@@ -579,7 +583,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
579
583
}
580
584
// Replace all other mentions of the same opaque type with the hidden type,
581
585
// 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
+ {
583
589
hidden_ty
584
590
}
585
591
_ => ty,
0 commit comments