@@ -95,14 +95,23 @@ impl<'db> InferenceContext<'_, 'db> {
9595 return Some ( ValuePathResolution :: NonGeneric ( ty) ) ;
9696 } ;
9797
98- let substs = self . with_body_ty_lowering ( |ctx| {
99- let mut path_ctx = ctx. at_path ( path, id) ;
100- let last_segment = path. segments ( ) . len ( ) . checked_sub ( 1 ) ;
101- if let Some ( last_segment) = last_segment {
102- path_ctx. set_current_segment ( last_segment)
103- }
104- path_ctx. substs_from_path ( value_def, true , false )
105- } ) ;
98+ let substs = if self_subst. is_some_and ( |it| !it. is_empty ( ) )
99+ && matches ! ( value_def, ValueTyDefId :: EnumVariantId ( _) )
100+ {
101+ // This is something like `TypeAlias::<Args>::EnumVariant`. Do not call `substs_from_path()`,
102+ // as it'll try to re-lower the previous segment assuming it refers to the enum, but it refers
103+ // to the type alias and they may have different generics.
104+ self . types . empty_args
105+ } else {
106+ self . with_body_ty_lowering ( |ctx| {
107+ let mut path_ctx = ctx. at_path ( path, id) ;
108+ let last_segment = path. segments ( ) . len ( ) . checked_sub ( 1 ) ;
109+ if let Some ( last_segment) = last_segment {
110+ path_ctx. set_current_segment ( last_segment)
111+ }
112+ path_ctx. substs_from_path ( value_def, true , false )
113+ } )
114+ } ;
106115
107116 let parent_substs_len = self_subst. map_or ( 0 , |it| it. len ( ) ) ;
108117 let substs = GenericArgs :: fill_rest (
0 commit comments