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