mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Remove has_default
from FieldId
This commit is contained in:
parent
e5c38558f5
commit
8aa6c09fce
@ -519,7 +519,6 @@ pub type LocalModuleId = Idx<nameres::ModuleData>;
|
||||
pub struct FieldId {
|
||||
pub parent: VariantId,
|
||||
pub local_id: LocalFieldId,
|
||||
pub has_default: bool,
|
||||
}
|
||||
|
||||
impl FieldId {
|
||||
|
@ -1167,11 +1167,9 @@ impl InferenceContext<'_> {
|
||||
};
|
||||
let mut p = place.clone();
|
||||
self.current_capture_span_stack.push(MirSpan::PatId(arg));
|
||||
let has_default = vd.fields()[local_id].has_default;
|
||||
p.projections.push(ProjectionElem::Field(Either::Left(FieldId {
|
||||
parent: variant,
|
||||
local_id,
|
||||
has_default,
|
||||
})));
|
||||
self.consume_with_pat(p, arg);
|
||||
self.current_capture_span_stack.pop();
|
||||
@ -1221,13 +1219,12 @@ impl InferenceContext<'_> {
|
||||
.iter()
|
||||
.zip(fields.clone())
|
||||
.chain(ar.iter().rev().zip(fields.rev()));
|
||||
for (&arg, (i, d)) in it {
|
||||
for (&arg, (i, _)) in it {
|
||||
let mut p = place.clone();
|
||||
self.current_capture_span_stack.push(MirSpan::PatId(arg));
|
||||
p.projections.push(ProjectionElem::Field(Either::Left(FieldId {
|
||||
parent: variant,
|
||||
local_id: i,
|
||||
has_default: d.has_default,
|
||||
})));
|
||||
self.consume_with_pat(p, arg);
|
||||
self.current_capture_span_stack.pop();
|
||||
|
@ -1748,15 +1748,13 @@ impl InferenceContext<'_> {
|
||||
TyKind::Adt(AdtId(hir_def::AdtId::StructId(s)), parameters) => {
|
||||
let vd = &self.db.struct_data(*s).variant_data;
|
||||
let local_id = vd.field(name)?;
|
||||
let has_default = vd.fields()[local_id].has_default;
|
||||
let field = FieldId { parent: (*s).into(), local_id, has_default };
|
||||
let field = FieldId { parent: (*s).into(), local_id };
|
||||
(field, parameters.clone())
|
||||
}
|
||||
TyKind::Adt(AdtId(hir_def::AdtId::UnionId(u)), parameters) => {
|
||||
let vd = &self.db.union_data(*u).variant_data;
|
||||
let local_id = vd.field(name)?;
|
||||
let has_default = vd.fields()[local_id].has_default;
|
||||
let field = FieldId { parent: (*u).into(), local_id, has_default };
|
||||
let field = FieldId { parent: (*u).into(), local_id };
|
||||
(field, parameters.clone())
|
||||
}
|
||||
_ => return None,
|
||||
|
@ -872,13 +872,10 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
||||
None => {
|
||||
let local_id =
|
||||
LocalFieldId::from_raw(RawIdx::from(i as u32));
|
||||
let has_default =
|
||||
variant_data.fields()[local_id].has_default;
|
||||
let p = sp.project(
|
||||
ProjectionElem::Field(Either::Left(FieldId {
|
||||
parent: variant_id,
|
||||
local_id,
|
||||
has_default,
|
||||
})),
|
||||
&mut self.result.projection_store,
|
||||
);
|
||||
@ -900,12 +897,10 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
||||
};
|
||||
let local_id =
|
||||
variant_data.field(name).ok_or(MirLowerError::UnresolvedField)?;
|
||||
let has_default = variant_data.fields()[local_id].has_default;
|
||||
let place = place.project(
|
||||
PlaceElem::Field(Either::Left(FieldId {
|
||||
parent: union_id.into(),
|
||||
local_id,
|
||||
has_default,
|
||||
})),
|
||||
&mut self.result.projection_store,
|
||||
);
|
||||
|
@ -632,12 +632,10 @@ impl MirLowerCtx<'_> {
|
||||
.map(|x| {
|
||||
let field_id =
|
||||
variant_data.field(&x.name).ok_or(MirLowerError::UnresolvedField)?;
|
||||
let has_default = variant_data.fields()[field_id].has_default;
|
||||
Ok((
|
||||
PlaceElem::Field(Either::Left(FieldId {
|
||||
parent: v,
|
||||
local_id: field_id,
|
||||
has_default,
|
||||
})),
|
||||
x.pat,
|
||||
))
|
||||
@ -646,12 +644,8 @@ impl MirLowerCtx<'_> {
|
||||
self.pattern_match_adt(current, current_else, it.into_iter(), cond_place, mode)?
|
||||
}
|
||||
AdtPatternShape::Tuple { args, ellipsis } => {
|
||||
let fields = variant_data.fields().iter().map(|(x, d)| {
|
||||
PlaceElem::Field(Either::Left(FieldId {
|
||||
parent: v,
|
||||
local_id: x,
|
||||
has_default: d.has_default,
|
||||
}))
|
||||
let fields = variant_data.fields().iter().map(|(x, _)| {
|
||||
PlaceElem::Field(Either::Left(FieldId { parent: v, local_id: x }))
|
||||
});
|
||||
self.pattern_match_tuple_like(
|
||||
current,
|
||||
|
@ -143,7 +143,7 @@ fn check_impl(
|
||||
let vd = db.variant_data(variant_id);
|
||||
defs.extend(vd.fields().iter().filter_map(|(local_id, fd)| {
|
||||
if fd.has_default {
|
||||
let field = FieldId { parent: variant_id, local_id, has_default: true };
|
||||
let field = FieldId { parent: variant_id, local_id };
|
||||
Some(DefWithBodyId::FieldId(field))
|
||||
} else {
|
||||
None
|
||||
@ -161,7 +161,7 @@ fn check_impl(
|
||||
let vd = db.variant_data(variant_id);
|
||||
defs.extend(vd.fields().iter().filter_map(|(local_id, fd)| {
|
||||
if fd.has_default {
|
||||
let field = FieldId { parent: variant_id, local_id, has_default: true };
|
||||
let field = FieldId { parent: variant_id, local_id };
|
||||
Some(DefWithBodyId::FieldId(field))
|
||||
} else {
|
||||
None
|
||||
@ -433,7 +433,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
|
||||
let vd = db.variant_data(variant_id);
|
||||
defs.extend(vd.fields().iter().filter_map(|(local_id, fd)| {
|
||||
if fd.has_default {
|
||||
let field = FieldId { parent: variant_id, local_id, has_default: true };
|
||||
let field = FieldId { parent: variant_id, local_id };
|
||||
Some(DefWithBodyId::FieldId(field))
|
||||
} else {
|
||||
None
|
||||
@ -451,7 +451,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
|
||||
let vd = db.variant_data(variant_id);
|
||||
defs.extend(vd.fields().iter().filter_map(|(local_id, fd)| {
|
||||
if fd.has_default {
|
||||
let field = FieldId { parent: variant_id, local_id, has_default: true };
|
||||
let field = FieldId { parent: variant_id, local_id };
|
||||
Some(DefWithBodyId::FieldId(field))
|
||||
} else {
|
||||
None
|
||||
|
@ -252,8 +252,8 @@ impl HirDisplay for Struct {
|
||||
f.write_char('(')?;
|
||||
let mut it = variant_data.fields().iter().peekable();
|
||||
|
||||
while let Some((id, d)) = it.next() {
|
||||
let field = Field { parent: (*self).into(), id, has_default: d.has_default };
|
||||
while let Some((id, _)) = it.next() {
|
||||
let field = Field { parent: (*self).into(), id };
|
||||
write_visibility(module_id, field.visibility(f.db), f)?;
|
||||
field.ty(f.db).hir_fmt(f)?;
|
||||
if it.peek().is_some() {
|
||||
|
@ -237,13 +237,13 @@ impl From<VariantDef> for VariantId {
|
||||
|
||||
impl From<Field> for FieldId {
|
||||
fn from(def: Field) -> Self {
|
||||
FieldId { parent: def.parent.into(), local_id: def.id, has_default: def.has_default }
|
||||
FieldId { parent: def.parent.into(), local_id: def.id }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FieldId> for Field {
|
||||
fn from(def: FieldId) -> Self {
|
||||
Field { parent: def.parent.into(), id: def.local_id, has_default: def.has_default }
|
||||
Field { parent: def.parent.into(), id: def.local_id }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,18 +415,24 @@ impl ModuleDef {
|
||||
def.diagnostics(db, &mut acc);
|
||||
}
|
||||
|
||||
let fields = match self {
|
||||
ModuleDef::Adt(Adt::Struct(it)) => Some(it.fields(db)),
|
||||
ModuleDef::Adt(Adt::Union(it)) => Some(it.fields(db)),
|
||||
ModuleDef::Variant(it) => Some(it.fields(db)),
|
||||
let vd: Option<(VariantDef, Arc<VariantData>)> = match self {
|
||||
ModuleDef::Adt(Adt::Struct(it)) => {
|
||||
Some((it.into(), db.struct_data(it.id).variant_data.clone()))
|
||||
}
|
||||
ModuleDef::Adt(Adt::Union(it)) => {
|
||||
Some((it.into(), db.union_data(it.id).variant_data.clone()))
|
||||
}
|
||||
ModuleDef::Variant(it) => {
|
||||
Some((it.into(), db.enum_variant_data(it.id).variant_data.clone()))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let Some(fields) = fields {
|
||||
for field in fields {
|
||||
if !field.has_default {
|
||||
if let Some((parent, vd)) = vd {
|
||||
for (id, fd) in vd.fields().iter() {
|
||||
if !fd.has_default {
|
||||
continue;
|
||||
}
|
||||
let def: DefWithBody = field.into();
|
||||
let def: DefWithBody = DefWithBody::Field(Field { parent, id });
|
||||
def.diagnostics(db, &mut acc, style_lints);
|
||||
}
|
||||
}
|
||||
@ -1252,7 +1258,6 @@ impl From<&Field> for DefWithBodyId {
|
||||
pub struct Field {
|
||||
pub(crate) parent: VariantDef,
|
||||
pub(crate) id: LocalFieldId,
|
||||
pub(crate) has_default: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
|
||||
@ -1418,7 +1423,7 @@ impl Struct {
|
||||
.variant_data
|
||||
.fields()
|
||||
.iter()
|
||||
.map(|(id, d)| Field { parent: self.into(), id, has_default: d.has_default })
|
||||
.map(|(id, _)| Field { parent: self.into(), id })
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -1480,7 +1485,7 @@ impl Union {
|
||||
.variant_data
|
||||
.fields()
|
||||
.iter()
|
||||
.map(|(id, d)| Field { parent: self.into(), id, has_default: d.has_default })
|
||||
.map(|(id, _)| Field { parent: self.into(), id })
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -1610,7 +1615,7 @@ impl Variant {
|
||||
self.variant_data(db)
|
||||
.fields()
|
||||
.iter()
|
||||
.map(|(id, d)| Field { parent: self.into(), id, has_default: d.has_default })
|
||||
.map(|(id, _)| Field { parent: self.into(), id })
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -5166,13 +5171,10 @@ impl Type {
|
||||
_ => return Vec::new(),
|
||||
};
|
||||
|
||||
let var_data = db.variant_data(variant_id);
|
||||
let fields = var_data.fields();
|
||||
db.field_types(variant_id)
|
||||
.iter()
|
||||
.map(|(local_id, ty)| {
|
||||
let has_default = fields[local_id].has_default;
|
||||
let def = Field { parent: variant_id.into(), id: local_id, has_default };
|
||||
let def = Field { parent: variant_id.into(), id: local_id };
|
||||
let ty = ty.clone().substitute(Interner, substs);
|
||||
(def, self.derived(ty))
|
||||
})
|
||||
|
@ -160,11 +160,7 @@ impl ChildBySource for VariantId {
|
||||
let arena_map = arena_map.as_ref();
|
||||
let parent = *self;
|
||||
for (local_id, source) in arena_map.value.iter() {
|
||||
let has_default = match source {
|
||||
Either::Left(_) => false,
|
||||
Either::Right(rec) => rec.expr().is_some(),
|
||||
};
|
||||
let id = FieldId { parent, local_id, has_default };
|
||||
let id = FieldId { parent, local_id };
|
||||
match source.clone() {
|
||||
Either::Left(source) => res[keys::TUPLE_FIELD].insert(AstPtr::new(&source), id),
|
||||
Either::Right(source) => res[keys::RECORD_FIELD].insert(AstPtr::new(&source), id),
|
||||
|
@ -630,10 +630,8 @@ impl SourceAnalyzer {
|
||||
let (adt, subst) = self.infer.as_ref()?.type_of_expr_or_pat(expr_id)?.as_adt()?;
|
||||
let variant = self.infer.as_ref()?.variant_resolution_for_expr_or_pat(expr_id)?;
|
||||
let variant_data = variant.variant_data(db.upcast());
|
||||
let fields = variant_data.fields();
|
||||
let local_id = variant_data.field(&local_name)?;
|
||||
let field =
|
||||
FieldId { parent: variant, local_id, has_default: fields[local_id].has_default };
|
||||
let field = FieldId { parent: variant, local_id };
|
||||
let field_ty =
|
||||
db.field_types(variant).get(field.local_id)?.clone().substitute(Interner, subst);
|
||||
Some((
|
||||
@ -654,10 +652,8 @@ impl SourceAnalyzer {
|
||||
let pat_id = self.pat_id(&record_pat.into())?;
|
||||
let variant = self.infer.as_ref()?.variant_resolution_for_pat(pat_id)?;
|
||||
let variant_data = variant.variant_data(db.upcast());
|
||||
let fields = variant_data.fields();
|
||||
let local_id = variant_data.field(&field_name)?;
|
||||
let field =
|
||||
FieldId { parent: variant, local_id, has_default: fields[local_id].has_default };
|
||||
let field = FieldId { parent: variant, local_id };
|
||||
let (adt, subst) = self.infer.as_ref()?.type_of_pat.get(pat_id)?.as_adt()?;
|
||||
let field_ty =
|
||||
db.field_types(variant).get(field.local_id)?.clone().substitute(Interner, subst);
|
||||
@ -1066,17 +1062,11 @@ impl SourceAnalyzer {
|
||||
missing_fields: Vec<LocalFieldId>,
|
||||
) -> Vec<(Field, Type)> {
|
||||
let field_types = db.field_types(variant);
|
||||
let var_data = db.variant_data(variant);
|
||||
let fields = var_data.fields();
|
||||
|
||||
missing_fields
|
||||
.into_iter()
|
||||
.map(|local_id| {
|
||||
let field = FieldId {
|
||||
parent: variant,
|
||||
local_id,
|
||||
has_default: fields[local_id].has_default,
|
||||
};
|
||||
let field = FieldId { parent: variant, local_id };
|
||||
let ty = field_types[local_id].clone().substitute(Interner, substs);
|
||||
(field.into(), Type::new_with_resolver_inner(db, &self.resolver, ty))
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user