Back out "Merge record lit's ellipsis into pre-existing spread's variant"

This backs out commit c134b20c9c.
This commit is contained in:
David Barsky 2025-01-27 17:20:11 -05:00
parent 77c1507048
commit f3451d54d6
10 changed files with 34 additions and 55 deletions

View file

@ -25,7 +25,7 @@ use crate::{
db::DefDatabase,
hir::{
Array, AsmOperand, Binding, BindingId, Expr, ExprId, ExprOrPatId, Label, LabelId, Pat,
PatId, RecordFieldPat, Spread, Statement,
PatId, RecordFieldPat, Statement,
},
nameres::DefMap,
path::{ModPath, Path},
@ -362,7 +362,7 @@ impl ExpressionStore {
for field in fields.iter() {
f(field.expr);
}
if let &Spread::Base(expr) = spread {
if let &Some(expr) = spread {
f(expr);
}
}
@ -490,7 +490,7 @@ impl ExpressionStore {
for field in fields.iter() {
f(field.expr);
}
if let &Spread::Base(expr) = spread {
if let &Some(expr) = spread {
f(expr);
}
}

View file

@ -45,7 +45,7 @@ use crate::{
},
Array, Binding, BindingAnnotation, BindingId, BindingProblems, CaptureBy, ClosureKind,
Expr, ExprId, Item, Label, LabelId, Literal, LiteralOrConst, MatchArm, Movability,
OffsetOf, Pat, PatId, RecordFieldPat, RecordLitField, Spread, Statement,
OffsetOf, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
},
item_scope::BuiltinShadowMode,
lang_item::LangItem,
@ -602,13 +602,11 @@ impl ExprCollector<'_> {
Some(RecordLitField { name, expr })
})
.collect();
let spread = nfl.spread().map(|s| self.collect_expr(s)).map_or_else(
|| if nfl.dotdot_token().is_some() { Spread::Yes } else { Spread::No },
Spread::Base,
);
Expr::RecordLit { path, fields, spread }
let spread = nfl.spread().map(|s| self.collect_expr(s));
let ellipsis = nfl.dotdot_token().is_some();
Expr::RecordLit { path, fields, spread, ellipsis }
} else {
Expr::RecordLit { path, fields: Box::default(), spread: Spread::No }
Expr::RecordLit { path, fields: Box::default(), spread: None, ellipsis: false }
};
self.alloc_expr(record_lit, syntax_ptr)

View file

@ -8,7 +8,7 @@ use span::Edition;
use crate::{
hir::{
Array, BindingAnnotation, CaptureBy, ClosureKind, Literal, LiteralOrConst, Movability,
Spread, Statement,
Statement,
},
pretty::{print_generic_args, print_path, print_type_ref},
VariantId,
@ -398,7 +398,7 @@ impl Printer<'_> {
self.print_expr(*expr);
}
}
Expr::RecordLit { path, fields, spread } => {
Expr::RecordLit { path, fields, spread, ellipsis: _ } => {
match path {
Some(path) => self.print_path(path),
None => w!(self, "<EFBFBD>"),
@ -412,16 +412,10 @@ impl Printer<'_> {
p.print_expr(field.expr);
wln!(p, ",");
}
match spread {
Spread::No => {}
Spread::Yes => {
w!(p, "..");
}
Spread::Base(expr) => {
w!(p, "..");
p.print_expr(*expr);
wln!(p);
}
if let Some(spread) = spread {
w!(p, "..");
p.print_expr(*spread);
wln!(p);
}
});
w!(self, "}}");

View file

@ -251,7 +251,8 @@ pub enum Expr {
RecordLit {
path: Option<Box<Path>>,
fields: Box<[RecordLitField]>,
spread: Spread,
spread: Option<ExprId>,
ellipsis: bool,
},
Field {
expr: ExprId,
@ -478,13 +479,6 @@ pub struct RecordLitField {
pub expr: ExprId,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Spread {
No,
Yes,
Base(ExprId),
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Statement {
Let {