@@ -368,28 +368,14 @@ impl<'tcx> InferCtxt<'tcx> {
368368 /// in its defining scope.
369369 #[ instrument( skip( self ) , level = "trace" , ret) ]
370370 pub fn opaque_type_origin ( & self , def_id : LocalDefId ) -> Option < OpaqueTyOrigin > {
371- let opaque_hir_id = self . tcx . local_def_id_to_hir_id ( def_id) ;
372- let parent_def_id = match self . defining_use_anchor {
371+ let defined_opaque_types = match self . defining_use_anchor {
373372 DefiningAnchor :: Bubble | DefiningAnchor :: Error => return None ,
374373 DefiningAnchor :: Bind ( bind) => bind,
375374 } ;
376375
377376 let origin = self . tcx . opaque_type_origin ( def_id) ;
378- let in_definition_scope = match origin {
379- // Async `impl Trait`
380- hir:: OpaqueTyOrigin :: AsyncFn ( parent) => parent == parent_def_id,
381- // Anonymous `impl Trait`
382- hir:: OpaqueTyOrigin :: FnReturn ( parent) => parent == parent_def_id,
383- // Named `type Foo = impl Bar;`
384- hir:: OpaqueTyOrigin :: TyAlias { in_assoc_ty } => {
385- if in_assoc_ty {
386- self . tcx . opaque_types_defined_by ( parent_def_id) . contains ( & def_id)
387- } else {
388- may_define_opaque_type ( self . tcx , parent_def_id, opaque_hir_id)
389- }
390- }
391- } ;
392- in_definition_scope. then_some ( origin)
377+
378+ defined_opaque_types. contains ( & def_id) . then_some ( origin)
393379 }
394380}
395381
@@ -638,43 +624,3 @@ impl<'tcx> InferCtxt<'tcx> {
638624 }
639625 }
640626}
641-
642- /// Returns `true` if `opaque_hir_id` is a sibling or a child of a sibling of `def_id`.
643- ///
644- /// Example:
645- /// ```ignore UNSOLVED (is this a bug?)
646- /// # #![feature(type_alias_impl_trait)]
647- /// pub mod foo {
648- /// pub mod bar {
649- /// pub trait Bar { /* ... */ }
650- /// pub type Baz = impl Bar;
651- ///
652- /// # impl Bar for () {}
653- /// fn f1() -> Baz { /* ... */ }
654- /// }
655- /// fn f2() -> bar::Baz { /* ... */ }
656- /// }
657- /// ```
658- ///
659- /// Here, `def_id` is the `LocalDefId` of the defining use of the opaque type (e.g., `f1` or `f2`),
660- /// and `opaque_hir_id` is the `HirId` of the definition of the opaque type `Baz`.
661- /// For the above example, this function returns `true` for `f1` and `false` for `f2`.
662- fn may_define_opaque_type ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , opaque_hir_id : hir:: HirId ) -> bool {
663- let mut hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
664-
665- // Named opaque types can be defined by any siblings or children of siblings.
666- let scope = tcx. hir ( ) . get_defining_scope ( opaque_hir_id) ;
667- // We walk up the node tree until we hit the root or the scope of the opaque type.
668- while hir_id != scope && hir_id != hir:: CRATE_HIR_ID {
669- hir_id = tcx. hir ( ) . get_parent_item ( hir_id) . into ( ) ;
670- }
671- // Syntactically, we are allowed to define the concrete type if:
672- let res = hir_id == scope;
673- trace ! (
674- "may_define_opaque_type(def={:?}, opaque_node={:?}) = {}" ,
675- tcx. hir_node( hir_id) ,
676- tcx. hir_node( opaque_hir_id) ,
677- res
678- ) ;
679- res
680- }
0 commit comments