mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 10:58:02 +00:00
Fix erroneous diagnostic incorrect_generics_len when there are generics on enum variant used through type alias
This commit is contained in:
parent
378ea41d07
commit
797ba9c7cb
2 changed files with 34 additions and 8 deletions
|
|
@ -95,14 +95,23 @@ impl<'db> InferenceContext<'_, 'db> {
|
||||||
return Some(ValuePathResolution::NonGeneric(ty));
|
return Some(ValuePathResolution::NonGeneric(ty));
|
||||||
};
|
};
|
||||||
|
|
||||||
let substs = self.with_body_ty_lowering(|ctx| {
|
let substs = if self_subst.is_some_and(|it| !it.is_empty())
|
||||||
let mut path_ctx = ctx.at_path(path, id);
|
&& matches!(value_def, ValueTyDefId::EnumVariantId(_))
|
||||||
let last_segment = path.segments().len().checked_sub(1);
|
{
|
||||||
if let Some(last_segment) = last_segment {
|
// This is something like `TypeAlias::<Args>::EnumVariant`. Do not call `substs_from_path()`,
|
||||||
path_ctx.set_current_segment(last_segment)
|
// as it'll try to re-lower the previous segment assuming it refers to the enum, but it refers
|
||||||
}
|
// to the type alias and they may have different generics.
|
||||||
path_ctx.substs_from_path(value_def, true, false)
|
self.types.empty_args
|
||||||
});
|
} else {
|
||||||
|
self.with_body_ty_lowering(|ctx| {
|
||||||
|
let mut path_ctx = ctx.at_path(path, id);
|
||||||
|
let last_segment = path.segments().len().checked_sub(1);
|
||||||
|
if let Some(last_segment) = last_segment {
|
||||||
|
path_ctx.set_current_segment(last_segment)
|
||||||
|
}
|
||||||
|
path_ctx.substs_from_path(value_def, true, false)
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
let parent_substs_len = self_subst.map_or(0, |it| it.len());
|
let parent_substs_len = self_subst.map_or(0, |it| it.len());
|
||||||
let substs = GenericArgs::fill_rest(
|
let substs = GenericArgs::fill_rest(
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,23 @@ impl WithSignals for Player {
|
||||||
fn __signals_from_external(&self) -> Self::SignalCollection<'_, Self> {
|
fn __signals_from_external(&self) -> Self::SignalCollection<'_, Self> {
|
||||||
Self::SignalCollection { _v: self }
|
Self::SignalCollection { _v: self }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn enum_type_alias_default_param() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
//- minicore: result
|
||||||
|
|
||||||
|
struct Error;
|
||||||
|
|
||||||
|
type Result<T, E = Error> = core::result::Result<T, E>;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = Result::<()>::Ok(());
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue