@@ -780,31 +780,28 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
780780 // }
781781 // ```
782782 if let Some ( def_id) = def_id. as_local ( ) {
783- let opaque_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
784783 let parent_def_id = self . infcx . defining_use_anchor ;
785784 let def_scope_default = || {
785+ let opaque_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
786786 let opaque_parent_hir_id = tcx. hir ( ) . get_parent_item ( opaque_hir_id) ;
787787 parent_def_id == tcx. hir ( ) . local_def_id ( opaque_parent_hir_id)
788788 } ;
789- let ( in_definition_scope, origin) =
790- match tcx. hir ( ) . expect_item ( opaque_hir_id) . kind {
791- // Anonymous `impl Trait`
792- hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
793- impl_trait_fn : Some ( parent) ,
794- origin,
795- ..
796- } ) => ( parent == parent_def_id. to_def_id ( ) , origin) ,
797- // Named `type Foo = impl Bar;`
798- hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
799- impl_trait_fn : None ,
800- origin,
801- ..
802- } ) => (
803- may_define_opaque_type ( tcx, parent_def_id, opaque_hir_id) ,
804- origin,
805- ) ,
806- _ => ( def_scope_default ( ) , hir:: OpaqueTyOrigin :: TyAlias ) ,
807- } ;
789+ let ( in_definition_scope, origin) = match tcx. hir ( ) . expect_item ( def_id) . kind
790+ {
791+ // Anonymous `impl Trait`
792+ hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
793+ impl_trait_fn : Some ( parent) ,
794+ origin,
795+ ..
796+ } ) => ( parent == parent_def_id. to_def_id ( ) , origin) ,
797+ // Named `type Foo = impl Bar;`
798+ hir:: ItemKind :: OpaqueTy ( hir:: OpaqueTy {
799+ impl_trait_fn : None ,
800+ origin,
801+ ..
802+ } ) => ( may_define_opaque_type ( tcx, parent_def_id, def_id) , origin) ,
803+ _ => ( def_scope_default ( ) , hir:: OpaqueTyOrigin :: TyAlias ) ,
804+ } ;
808805 if in_definition_scope {
809806 let opaque_type_key =
810807 OpaqueTypeKey { def_id : def_id. to_def_id ( ) , substs } ;
@@ -937,8 +934,9 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
937934/// Here, `def_id` is the `LocalDefId` of the defining use of the opaque type (e.g., `f1` or `f2`),
938935/// and `opaque_hir_id` is the `HirId` of the definition of the opaque type `Baz`.
939936/// For the above example, this function returns `true` for `f1` and `false` for `f2`.
940- fn may_define_opaque_type ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , opaque_hir_id : hir :: HirId ) -> bool {
937+ fn may_define_opaque_type ( tcx : TyCtxt < ' _ > , def_id : LocalDefId , opaque_def_id : LocalDefId ) -> bool {
941938 let mut hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
939+ let opaque_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( opaque_def_id) ;
942940
943941 // Named opaque types can be defined by any siblings or children of siblings.
944942 let scope = tcx. hir ( ) . get_defining_scope ( opaque_hir_id) ;
0 commit comments