mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 05:13:35 +00:00
Back out "Handle missing fields diagnostics"
This backs out commit e6a103ae50.
This commit is contained in:
parent
f3451d54d6
commit
35f6123059
11 changed files with 12 additions and 59 deletions
|
|
@ -85,7 +85,6 @@ pub struct FieldData {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub type_ref: TypeRefId,
|
pub type_ref: TypeRefId,
|
||||||
pub visibility: RawVisibility,
|
pub visibility: RawVisibility,
|
||||||
pub has_default: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn repr_from_value(
|
fn repr_from_value(
|
||||||
|
|
@ -479,6 +478,5 @@ fn lower_field(
|
||||||
name: field.name.clone(),
|
name: field.name.clone(),
|
||||||
type_ref: field.type_ref,
|
type_ref: field.type_ref,
|
||||||
visibility: item_tree[override_visibility.unwrap_or(field.visibility)].clone(),
|
visibility: item_tree[override_visibility.unwrap_or(field.visibility)].clone(),
|
||||||
has_default: field.has_default,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -603,10 +603,9 @@ impl ExprCollector<'_> {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let spread = nfl.spread().map(|s| self.collect_expr(s));
|
let spread = nfl.spread().map(|s| self.collect_expr(s));
|
||||||
let ellipsis = nfl.dotdot_token().is_some();
|
Expr::RecordLit { path, fields, spread }
|
||||||
Expr::RecordLit { path, fields, spread, ellipsis }
|
|
||||||
} else {
|
} else {
|
||||||
Expr::RecordLit { path, fields: Box::default(), spread: None, ellipsis: false }
|
Expr::RecordLit { path, fields: Box::default(), spread: None }
|
||||||
};
|
};
|
||||||
|
|
||||||
self.alloc_expr(record_lit, syntax_ptr)
|
self.alloc_expr(record_lit, syntax_ptr)
|
||||||
|
|
|
||||||
|
|
@ -398,7 +398,7 @@ impl Printer<'_> {
|
||||||
self.print_expr(*expr);
|
self.print_expr(*expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::RecordLit { path, fields, spread, ellipsis: _ } => {
|
Expr::RecordLit { path, fields, spread } => {
|
||||||
match path {
|
match path {
|
||||||
Some(path) => self.print_path(path),
|
Some(path) => self.print_path(path),
|
||||||
None => w!(self, "<EFBFBD>"),
|
None => w!(self, "<EFBFBD>"),
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,6 @@ pub enum Expr {
|
||||||
path: Option<Box<Path>>,
|
path: Option<Box<Path>>,
|
||||||
fields: Box<[RecordLitField]>,
|
fields: Box<[RecordLitField]>,
|
||||||
spread: Option<ExprId>,
|
spread: Option<ExprId>,
|
||||||
ellipsis: bool,
|
|
||||||
},
|
},
|
||||||
Field {
|
Field {
|
||||||
expr: ExprId,
|
expr: ExprId,
|
||||||
|
|
|
||||||
|
|
@ -1007,7 +1007,6 @@ pub struct Field {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub type_ref: TypeRefId,
|
pub type_ref: TypeRefId,
|
||||||
pub visibility: RawVisibilityId,
|
pub visibility: RawVisibilityId,
|
||||||
pub has_default: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
|
|
|
||||||
|
|
@ -319,9 +319,8 @@ impl<'a> Ctx<'a> {
|
||||||
};
|
};
|
||||||
let visibility = self.lower_visibility(field);
|
let visibility = self.lower_visibility(field);
|
||||||
let type_ref = TypeRef::from_ast_opt(body_ctx, field.ty());
|
let type_ref = TypeRef::from_ast_opt(body_ctx, field.ty());
|
||||||
let has_default = field.expr().is_some();
|
|
||||||
|
|
||||||
Field { name, type_ref, visibility, has_default }
|
Field { name, type_ref, visibility }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_tuple_field(
|
fn lower_tuple_field(
|
||||||
|
|
@ -333,7 +332,7 @@ impl<'a> Ctx<'a> {
|
||||||
let name = Name::new_tuple_field(idx);
|
let name = Name::new_tuple_field(idx);
|
||||||
let visibility = self.lower_visibility(field);
|
let visibility = self.lower_visibility(field);
|
||||||
let type_ref = TypeRef::from_ast_opt(body_ctx, field.ty());
|
let type_ref = TypeRef::from_ast_opt(body_ctx, field.ty());
|
||||||
Field { name, type_ref, visibility, has_default: false }
|
Field { name, type_ref, visibility }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_union(&mut self, union: &ast::Union) -> Option<FileItemTreeId<Union>> {
|
fn lower_union(&mut self, union: &ast::Union) -> Option<FileItemTreeId<Union>> {
|
||||||
|
|
|
||||||
|
|
@ -135,9 +135,7 @@ impl Printer<'_> {
|
||||||
self.whitespace();
|
self.whitespace();
|
||||||
w!(self, "{{");
|
w!(self, "{{");
|
||||||
self.indented(|this| {
|
self.indented(|this| {
|
||||||
for (idx, Field { name, type_ref, visibility, has_default: _ }) in
|
for (idx, Field { name, type_ref, visibility }) in fields.iter().enumerate() {
|
||||||
fields.iter().enumerate()
|
|
||||||
{
|
|
||||||
this.print_attrs_of(
|
this.print_attrs_of(
|
||||||
AttrOwner::Field(parent, Idx::from_raw(RawIdx::from(idx as u32))),
|
AttrOwner::Field(parent, Idx::from_raw(RawIdx::from(idx as u32))),
|
||||||
"\n",
|
"\n",
|
||||||
|
|
@ -153,9 +151,7 @@ impl Printer<'_> {
|
||||||
FieldsShape::Tuple => {
|
FieldsShape::Tuple => {
|
||||||
w!(self, "(");
|
w!(self, "(");
|
||||||
self.indented(|this| {
|
self.indented(|this| {
|
||||||
for (idx, Field { name, type_ref, visibility, has_default: _ }) in
|
for (idx, Field { name, type_ref, visibility }) in fields.iter().enumerate() {
|
||||||
fields.iter().enumerate()
|
|
||||||
{
|
|
||||||
this.print_attrs_of(
|
this.print_attrs_of(
|
||||||
AttrOwner::Field(parent, Idx::from_raw(RawIdx::from(idx as u32))),
|
AttrOwner::Field(parent, Idx::from_raw(RawIdx::from(idx as u32))),
|
||||||
"\n",
|
"\n",
|
||||||
|
|
|
||||||
|
|
@ -547,8 +547,8 @@ pub fn record_literal_missing_fields(
|
||||||
id: ExprId,
|
id: ExprId,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
|
) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
|
||||||
let (fields, exhaustive, ellipsis) = match expr {
|
let (fields, exhaustive) = match expr {
|
||||||
Expr::RecordLit { fields, spread, ellipsis, .. } => (fields, spread.is_none(), *ellipsis),
|
Expr::RecordLit { fields, spread, .. } => (fields, spread.is_none()),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -563,13 +563,7 @@ pub fn record_literal_missing_fields(
|
||||||
let missed_fields: Vec<LocalFieldId> = variant_data
|
let missed_fields: Vec<LocalFieldId> = variant_data
|
||||||
.fields()
|
.fields()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(f, d)| {
|
.filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) })
|
||||||
if (ellipsis && d.has_default) || specified_fields.contains(&d.name) {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(f)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
if missed_fields.is_empty() {
|
if missed_fields.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ impl InferenceContext<'_> {
|
||||||
Expr::Become { expr } => {
|
Expr::Become { expr } => {
|
||||||
self.infer_mut_expr(*expr, Mutability::Not);
|
self.infer_mut_expr(*expr, Mutability::Not);
|
||||||
}
|
}
|
||||||
Expr::RecordLit { path: _, fields, spread, ellipsis: _ } => {
|
Expr::RecordLit { path: _, fields, spread } => {
|
||||||
self.infer_mut_not_expr_iter(fields.iter().map(|it| it.expr).chain(*spread))
|
self.infer_mut_not_expr_iter(fields.iter().map(|it| it.expr).chain(*spread))
|
||||||
}
|
}
|
||||||
&Expr::Index { base, index } => {
|
&Expr::Index { base, index } => {
|
||||||
|
|
|
||||||
|
|
@ -823,7 +823,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
||||||
}
|
}
|
||||||
Expr::Become { .. } => not_supported!("tail-calls"),
|
Expr::Become { .. } => not_supported!("tail-calls"),
|
||||||
Expr::Yield { .. } => not_supported!("yield"),
|
Expr::Yield { .. } => not_supported!("yield"),
|
||||||
Expr::RecordLit { fields, path, spread, ellipsis: _ } => {
|
Expr::RecordLit { fields, path, spread } => {
|
||||||
let spread_place = match spread {
|
let spread_place = match spread {
|
||||||
&Some(it) => {
|
&Some(it) => {
|
||||||
let Some((p, c)) = self.lower_expr_as_place(current, it, true)? else {
|
let Some((p, c)) = self.lower_expr_as_place(current, it, true)? else {
|
||||||
|
|
|
||||||
|
|
@ -846,35 +846,4 @@ pub struct Claims {
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn default_field_values() {
|
|
||||||
check_diagnostics(
|
|
||||||
r#"
|
|
||||||
struct F {
|
|
||||||
field1: i32 = 4,
|
|
||||||
field2: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn f() {
|
|
||||||
let _f = F {
|
|
||||||
field2: true,
|
|
||||||
..
|
|
||||||
};
|
|
||||||
|
|
||||||
let _f = F {
|
|
||||||
//^ 💡 error: missing structure fields:
|
|
||||||
//| - field1
|
|
||||||
field2: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
let _f = F {
|
|
||||||
//^ 💡 error: missing structure fields:
|
|
||||||
//| - field2
|
|
||||||
..
|
|
||||||
};
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue