mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-16 07:03:57 +00:00
Auto merge of #13339 - lowr:patch/change-generic-param-order, r=Veykril
fix: treat enum variants as generic item on their own Fixup for #13335 It turns out I tried to merge two procedures into one utility function without noticing the incompatibility. This time I *did* run analysis-stats on the four crates and confirmed it doesn't crash and this patch doesn't cause regression.
This commit is contained in:
commit
974caaff8f
2 changed files with 12 additions and 10 deletions
|
@ -192,9 +192,7 @@ impl TyBuilder<()> {
|
||||||
parent_subst: Option<Substitution>,
|
parent_subst: Option<Substitution>,
|
||||||
) -> TyBuilder<()> {
|
) -> TyBuilder<()> {
|
||||||
let generics = generics(db.upcast(), def.into());
|
let generics = generics(db.upcast(), def.into());
|
||||||
// FIXME: this assertion should hold but some adjustment around
|
assert!(generics.parent_generics().is_some() == parent_subst.is_some());
|
||||||
// `ValueTyDefId::EnumVariantId` is needed.
|
|
||||||
// assert!(generics.parent_generics().is_some() == parent_subst.is_some());
|
|
||||||
let params = generics
|
let params = generics
|
||||||
.iter_self()
|
.iter_self()
|
||||||
.map(|(id, data)| match data {
|
.map(|(id, data)| match data {
|
||||||
|
|
|
@ -653,9 +653,13 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
infer_args: bool,
|
infer_args: bool,
|
||||||
) -> Substitution {
|
) -> Substitution {
|
||||||
let last = path.segments().last().expect("path should have at least one segment");
|
let last = path.segments().last().expect("path should have at least one segment");
|
||||||
let generic_def = resolved.to_generic_def_id();
|
let (segment, generic_def) = match resolved {
|
||||||
let segment = match resolved {
|
ValueTyDefId::FunctionId(it) => (last, Some(it.into())),
|
||||||
ValueTyDefId::EnumVariantId(_) => {
|
ValueTyDefId::StructId(it) => (last, Some(it.into())),
|
||||||
|
ValueTyDefId::UnionId(it) => (last, Some(it.into())),
|
||||||
|
ValueTyDefId::ConstId(it) => (last, Some(it.into())),
|
||||||
|
ValueTyDefId::StaticId(_) => (last, None),
|
||||||
|
ValueTyDefId::EnumVariantId(var) => {
|
||||||
// the generic args for an enum variant may be either specified
|
// the generic args for an enum variant may be either specified
|
||||||
// on the segment referring to the enum, or on the segment
|
// on the segment referring to the enum, or on the segment
|
||||||
// referring to the variant. So `Option::<T>::None` and
|
// referring to the variant. So `Option::<T>::None` and
|
||||||
|
@ -663,12 +667,12 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
// preferred). See also `def_ids_for_path_segments` in rustc.
|
// preferred). See also `def_ids_for_path_segments` in rustc.
|
||||||
let len = path.segments().len();
|
let len = path.segments().len();
|
||||||
let penultimate = len.checked_sub(2).and_then(|idx| path.segments().get(idx));
|
let penultimate = len.checked_sub(2).and_then(|idx| path.segments().get(idx));
|
||||||
match penultimate {
|
let segment = match penultimate {
|
||||||
Some(segment) if segment.args_and_bindings.is_some() => segment,
|
Some(segment) if segment.args_and_bindings.is_some() => segment,
|
||||||
_ => last,
|
_ => last,
|
||||||
}
|
};
|
||||||
|
(segment, Some(var.parent.into()))
|
||||||
}
|
}
|
||||||
_ => last,
|
|
||||||
};
|
};
|
||||||
self.substs_from_path_segment(segment, generic_def, infer_args, None)
|
self.substs_from_path_segment(segment, generic_def, infer_args, None)
|
||||||
}
|
}
|
||||||
|
@ -1660,7 +1664,7 @@ impl ValueTyDefId {
|
||||||
Self::FunctionId(id) => Some(id.into()),
|
Self::FunctionId(id) => Some(id.into()),
|
||||||
Self::StructId(id) => Some(id.into()),
|
Self::StructId(id) => Some(id.into()),
|
||||||
Self::UnionId(id) => Some(id.into()),
|
Self::UnionId(id) => Some(id.into()),
|
||||||
Self::EnumVariantId(var) => Some(var.parent.into()),
|
Self::EnumVariantId(var) => Some(var.into()),
|
||||||
Self::ConstId(id) => Some(id.into()),
|
Self::ConstId(id) => Some(id.into()),
|
||||||
Self::StaticId(_) => None,
|
Self::StaticId(_) => None,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue