@@ -57,9 +57,7 @@ impl<'tcx> InferCtxt<'tcx> {
57
57
}
58
58
let mut obligations = vec ! [ ] ;
59
59
let replace_opaque_type = |def_id : DefId | {
60
- def_id
61
- . as_local ( )
62
- . map_or ( false , |def_id| self . opaque_type_origin ( def_id, span) . is_some ( ) )
60
+ def_id. as_local ( ) . map_or ( false , |def_id| self . opaque_type_origin ( def_id) . is_some ( ) )
63
61
} ;
64
62
let value = value. fold_with ( & mut BottomUpFolder {
65
63
tcx : self . tcx ,
@@ -144,9 +142,9 @@ impl<'tcx> InferCtxt<'tcx> {
144
142
// let x = || foo(); // returns the Opaque assoc with `foo`
145
143
// }
146
144
// ```
147
- self . opaque_type_origin ( def_id, cause . span ) ?
145
+ self . opaque_type_origin ( def_id) ?
148
146
}
149
- DefiningAnchor :: Bubble => self . opaque_ty_origin_unchecked ( def_id, cause . span ) ,
147
+ DefiningAnchor :: Bubble => self . opaque_type_origin_unchecked ( def_id) ,
150
148
DefiningAnchor :: Error => return None ,
151
149
} ;
152
150
if let ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id : b_def_id, .. } ) = * b. kind ( ) {
@@ -155,9 +153,8 @@ impl<'tcx> InferCtxt<'tcx> {
155
153
// no one encounters it in practice.
156
154
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
157
155
// where it is of no concern, so we only check for TAITs.
158
- if let Some ( OpaqueTyOrigin :: TyAlias ) = b_def_id
159
- . as_local ( )
160
- . and_then ( |b_def_id| self . opaque_type_origin ( b_def_id, cause. span ) )
156
+ if let Some ( OpaqueTyOrigin :: TyAlias ) =
157
+ b_def_id. as_local ( ) . and_then ( |b_def_id| self . opaque_type_origin ( b_def_id) )
161
158
{
162
159
self . tcx . sess . emit_err ( OpaqueHiddenTypeDiag {
163
160
span : cause. span ,
@@ -371,24 +368,18 @@ impl<'tcx> InferCtxt<'tcx> {
371
368
} ) ;
372
369
}
373
370
371
+ /// Returns the origin of the opaque type `def_id` if we're currently
372
+ /// in its defining scope.
374
373
#[ instrument( skip( self ) , level = "trace" , ret) ]
375
- pub fn opaque_type_origin ( & self , def_id : LocalDefId , span : Span ) -> Option < OpaqueTyOrigin > {
374
+ pub fn opaque_type_origin ( & self , def_id : LocalDefId ) -> Option < OpaqueTyOrigin > {
376
375
let opaque_hir_id = self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
377
376
let parent_def_id = match self . defining_use_anchor {
378
377
DefiningAnchor :: Bubble | DefiningAnchor :: Error => return None ,
379
378
DefiningAnchor :: Bind ( bind) => bind,
380
379
} ;
381
- let item_kind = & self . tcx . hir ( ) . expect_item ( def_id) . kind ;
382
-
383
- let hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { origin, .. } ) = item_kind else {
384
- span_bug ! (
385
- span,
386
- "weird opaque type: {:#?}, {:#?}" ,
387
- def_id,
388
- item_kind
389
- )
390
- } ;
391
- let in_definition_scope = match * origin {
380
+
381
+ let origin = self . opaque_type_origin_unchecked ( def_id) ;
382
+ let in_definition_scope = match origin {
392
383
// Async `impl Trait`
393
384
hir:: OpaqueTyOrigin :: AsyncFn ( parent) => parent == parent_def_id,
394
385
// Anonymous `impl Trait`
@@ -398,16 +389,17 @@ impl<'tcx> InferCtxt<'tcx> {
398
389
may_define_opaque_type ( self . tcx , parent_def_id, opaque_hir_id)
399
390
}
400
391
} ;
401
- trace ! ( ?origin) ;
402
- in_definition_scope. then_some ( * origin)
392
+ in_definition_scope. then_some ( origin)
403
393
}
404
394
395
+ /// Returns the origin of the opaque type `def_id` even if we are not in its
396
+ /// defining scope.
405
397
#[ instrument( skip( self ) , level = "trace" , ret) ]
406
- fn opaque_ty_origin_unchecked ( & self , def_id : LocalDefId , span : Span ) -> OpaqueTyOrigin {
398
+ fn opaque_type_origin_unchecked ( & self , def_id : LocalDefId ) -> OpaqueTyOrigin {
407
399
match self . tcx . hir ( ) . expect_item ( def_id) . kind {
408
400
hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy { origin, .. } ) => origin,
409
401
ref itemkind => {
410
- span_bug ! ( span , "weird opaque type: {:?}, {:#?}" , def_id, itemkind)
402
+ bug ! ( "weird opaque type: {:?}, {:#?}" , def_id, itemkind)
411
403
}
412
404
}
413
405
}
0 commit comments