mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-26 17:57:19 +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));
|
||||
};
|
||||
|
||||
let substs = 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 substs = if self_subst.is_some_and(|it| !it.is_empty())
|
||||
&& matches!(value_def, ValueTyDefId::EnumVariantId(_))
|
||||
{
|
||||
// This is something like `TypeAlias::<Args>::EnumVariant`. Do not call `substs_from_path()`,
|
||||
// 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.
|
||||
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 substs = GenericArgs::fill_rest(
|
||||
|
|
|
|||
|
|
@ -203,6 +203,23 @@ impl WithSignals for Player {
|
|||
fn __signals_from_external(&self) -> Self::SignalCollection<'_, 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