Skip to content

Commit d039b10

Browse files
committed
Back out "Handle missing fields diagnostics"
This backs out commit e6a103ae50699db1dbb0676d075a4bcda2247939.
1 parent 10089c2 commit d039b10

File tree

11 files changed

+12
-59
lines changed

11 files changed

+12
-59
lines changed

src/tools/rust-analyzer/crates/hir-def/src/data/adt.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ pub struct FieldData {
8585
pub name: Name,
8686
pub type_ref: TypeRefId,
8787
pub visibility: RawVisibility,
88-
pub has_default: bool,
8988
}
9089

9190
fn repr_from_value(
@@ -479,6 +478,5 @@ fn lower_field(
479478
name: field.name.clone(),
480479
type_ref: field.type_ref,
481480
visibility: item_tree[override_visibility.unwrap_or(field.visibility)].clone(),
482-
has_default: field.has_default,
483481
}
484482
}

src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,9 @@ impl ExprCollector<'_> {
603603
})
604604
.collect();
605605
let spread = nfl.spread().map(|s| self.collect_expr(s));
606-
let ellipsis = nfl.dotdot_token().is_some();
607-
Expr::RecordLit { path, fields, spread, ellipsis }
606+
Expr::RecordLit { path, fields, spread }
608607
} else {
609-
Expr::RecordLit { path, fields: Box::default(), spread: None, ellipsis: false }
608+
Expr::RecordLit { path, fields: Box::default(), spread: None }
610609
};
611610

612611
self.alloc_expr(record_lit, syntax_ptr)

src/tools/rust-analyzer/crates/hir-def/src/expr_store/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl Printer<'_> {
398398
self.print_expr(*expr);
399399
}
400400
}
401-
Expr::RecordLit { path, fields, spread, ellipsis: _ } => {
401+
Expr::RecordLit { path, fields, spread } => {
402402
match path {
403403
Some(path) => self.print_path(path),
404404
None => w!(self, "�"),

src/tools/rust-analyzer/crates/hir-def/src/hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ pub enum Expr {
252252
path: Option<Box<Path>>,
253253
fields: Box<[RecordLitField]>,
254254
spread: Option<ExprId>,
255-
ellipsis: bool,
256255
},
257256
Field {
258257
expr: ExprId,

src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,6 @@ pub struct Field {
10071007
pub name: Name,
10081008
pub type_ref: TypeRefId,
10091009
pub visibility: RawVisibilityId,
1010-
pub has_default: bool,
10111010
}
10121011

10131012
#[derive(Debug, Clone, Eq, PartialEq)]

src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,8 @@ impl<'a> Ctx<'a> {
319319
};
320320
let visibility = self.lower_visibility(field);
321321
let type_ref = TypeRef::from_ast_opt(body_ctx, field.ty());
322-
let has_default = field.expr().is_some();
323322

324-
Field { name, type_ref, visibility, has_default }
323+
Field { name, type_ref, visibility }
325324
}
326325

327326
fn lower_tuple_field(
@@ -333,7 +332,7 @@ impl<'a> Ctx<'a> {
333332
let name = Name::new_tuple_field(idx);
334333
let visibility = self.lower_visibility(field);
335334
let type_ref = TypeRef::from_ast_opt(body_ctx, field.ty());
336-
Field { name, type_ref, visibility, has_default: false }
335+
Field { name, type_ref, visibility }
337336
}
338337

339338
fn lower_union(&mut self, union: &ast::Union) -> Option<FileItemTreeId<Union>> {

src/tools/rust-analyzer/crates/hir-def/src/item_tree/pretty.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ impl Printer<'_> {
135135
self.whitespace();
136136
w!(self, "{{");
137137
self.indented(|this| {
138-
for (idx, Field { name, type_ref, visibility, has_default: _ }) in
139-
fields.iter().enumerate()
140-
{
138+
for (idx, Field { name, type_ref, visibility }) in fields.iter().enumerate() {
141139
this.print_attrs_of(
142140
AttrOwner::Field(parent, Idx::from_raw(RawIdx::from(idx as u32))),
143141
"\n",
@@ -153,9 +151,7 @@ impl Printer<'_> {
153151
FieldsShape::Tuple => {
154152
w!(self, "(");
155153
self.indented(|this| {
156-
for (idx, Field { name, type_ref, visibility, has_default: _ }) in
157-
fields.iter().enumerate()
158-
{
154+
for (idx, Field { name, type_ref, visibility }) in fields.iter().enumerate() {
159155
this.print_attrs_of(
160156
AttrOwner::Field(parent, Idx::from_raw(RawIdx::from(idx as u32))),
161157
"\n",

src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/expr.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ pub fn record_literal_missing_fields(
547547
id: ExprId,
548548
expr: &Expr,
549549
) -> Option<(VariantId, Vec<LocalFieldId>, /*exhaustive*/ bool)> {
550-
let (fields, exhaustive, ellipsis) = match expr {
551-
Expr::RecordLit { fields, spread, ellipsis, .. } => (fields, spread.is_none(), *ellipsis),
550+
let (fields, exhaustive) = match expr {
551+
Expr::RecordLit { fields, spread, .. } => (fields, spread.is_none()),
552552
_ => return None,
553553
};
554554

@@ -563,13 +563,7 @@ pub fn record_literal_missing_fields(
563563
let missed_fields: Vec<LocalFieldId> = variant_data
564564
.fields()
565565
.iter()
566-
.filter_map(|(f, d)| {
567-
if (ellipsis && d.has_default) || specified_fields.contains(&d.name) {
568-
None
569-
} else {
570-
Some(f)
571-
}
572-
})
566+
.filter_map(|(f, d)| if specified_fields.contains(&d.name) { None } else { Some(f) })
573567
.collect();
574568
if missed_fields.is_empty() {
575569
return None;

src/tools/rust-analyzer/crates/hir-ty/src/infer/mutability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl InferenceContext<'_> {
121121
Expr::Become { expr } => {
122122
self.infer_mut_expr(*expr, Mutability::Not);
123123
}
124-
Expr::RecordLit { path: _, fields, spread, ellipsis: _ } => {
124+
Expr::RecordLit { path: _, fields, spread } => {
125125
self.infer_mut_not_expr_iter(fields.iter().map(|it| it.expr).chain(*spread))
126126
}
127127
&Expr::Index { base, index } => {

src/tools/rust-analyzer/crates/hir-ty/src/mir/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
823823
}
824824
Expr::Become { .. } => not_supported!("tail-calls"),
825825
Expr::Yield { .. } => not_supported!("yield"),
826-
Expr::RecordLit { fields, path, spread, ellipsis: _ } => {
826+
Expr::RecordLit { fields, path, spread } => {
827827
let spread_place = match spread {
828828
&Some(it) => {
829829
let Some((p, c)) = self.lower_expr_as_place(current, it, true)? else {

src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_fields.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -846,35 +846,4 @@ pub struct Claims {
846846
"#,
847847
);
848848
}
849-
850-
#[test]
851-
fn default_field_values() {
852-
check_diagnostics(
853-
r#"
854-
struct F {
855-
field1: i32 = 4,
856-
field2: bool,
857-
}
858-
859-
fn f() {
860-
let _f = F {
861-
field2: true,
862-
..
863-
};
864-
865-
let _f = F {
866-
//^ 💡 error: missing structure fields:
867-
//| - field1
868-
field2: true,
869-
};
870-
871-
let _f = F {
872-
//^ 💡 error: missing structure fields:
873-
//| - field2
874-
..
875-
};
876-
}
877-
"#,
878-
);
879-
}
880849
}

0 commit comments

Comments
 (0)