@@ -373,28 +373,14 @@ impl<'tcx> InferCtxt<'tcx> {
373
373
/// in its defining scope.
374
374
#[ instrument( skip( self ) , level = "trace" , ret) ]
375
375
pub fn opaque_type_origin ( & self , def_id : LocalDefId ) -> Option < OpaqueTyOrigin > {
376
- let opaque_hir_id = self . tcx . local_def_id_to_hir_id ( def_id) ;
377
- let parent_def_id = match self . defining_use_anchor {
376
+ let defined_opaque_types = match self . defining_use_anchor {
378
377
DefiningAnchor :: Bubble | DefiningAnchor :: Error => return None ,
379
378
DefiningAnchor :: Bind ( bind) => bind,
380
379
} ;
381
380
382
381
let origin = self . tcx . opaque_type_origin ( def_id) ;
383
- let in_definition_scope = match origin {
384
- // Async `impl Trait`
385
- hir:: OpaqueTyOrigin :: AsyncFn ( parent) => parent == parent_def_id,
386
- // Anonymous `impl Trait`
387
- hir:: OpaqueTyOrigin :: FnReturn ( parent) => parent == parent_def_id,
388
- // Named `type Foo = impl Bar;`
389
- hir:: OpaqueTyOrigin :: TyAlias { in_assoc_ty } => {
390
- if in_assoc_ty {
391
- self . tcx . opaque_types_defined_by ( parent_def_id) . contains ( & def_id)
392
- } else {
393
- may_define_opaque_type ( self . tcx , parent_def_id, opaque_hir_id)
394
- }
395
- }
396
- } ;
397
- in_definition_scope. then_some ( origin)
382
+
383
+ defined_opaque_types. contains ( & def_id) . then_some ( origin)
398
384
}
399
385
}
400
386
@@ -652,43 +638,3 @@ impl<'tcx> InferCtxt<'tcx> {
652
638
}
653
639
}
654
640
}
655
-
656
- /// Returns `true` if `opaque_hir_id` is a sibling or a child of a sibling of `def_id`.
657
- ///
658
- /// Example:
659
- /// ```ignore UNSOLVED (is this a bug?)
660
- /// # #![feature(type_alias_impl_trait)]
661
- /// pub mod foo {
662
- /// pub mod bar {
663
- /// pub trait Bar { /* ... */ }
664
- /// pub type Baz = impl Bar;
665
- ///
666
- /// # impl Bar for () {}
667
- /// fn f1() -> Baz { /* ... */ }
668
- /// }
669
- /// fn f2() -> bar::Baz { /* ... */ }
670
- /// }
671
- /// ```
672
- ///
673
- /// Here, `def_id` is the `LocalDefId` of the defining use of the opaque type (e.g., `f1` or `f2`),
674
- /// and `opaque_hir_id` is the `HirId` of the definition of the opaque type `Baz`.
675
- /// For the above example, this function returns `true` for `f1` and `false` for `f2`.
676
- fn may_define_opaque_type ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , opaque_hir_id : hir:: HirId ) -> bool {
677
- let mut hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
678
-
679
- // Named opaque types can be defined by any siblings or children of siblings.
680
- let scope = tcx. hir ( ) . get_defining_scope ( opaque_hir_id) ;
681
- // We walk up the node tree until we hit the root or the scope of the opaque type.
682
- while hir_id != scope && hir_id != hir:: CRATE_HIR_ID {
683
- hir_id = tcx. hir ( ) . get_parent_item ( hir_id) . into ( ) ;
684
- }
685
- // Syntactically, we are allowed to define the concrete type if:
686
- let res = hir_id == scope;
687
- trace ! (
688
- "may_define_opaque_type(def={:?}, opaque_node={:?}) = {}" ,
689
- tcx. hir_node( hir_id) ,
690
- tcx. hir_node( opaque_hir_id) ,
691
- res
692
- ) ;
693
- res
694
- }
0 commit comments