Skip to content

Commit 87f4c15

Browse files
committed
rustc: Make functional record and struct update use ".." instead of "with".
"with" is still accepted for backwards compatibility.
1 parent c7ed990 commit 87f4c15

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,15 +928,16 @@ class parser {
928928
!self.is_keyword(~"with") {
929929
self.expect(token::COMMA);
930930
if self.token == token::RBRACE ||
931-
self.is_keyword(~"with") {
931+
self.is_keyword(~"with") ||
932+
self.token == token::DOTDOT {
932933
// Accept an optional trailing comma.
933934
break;
934935
}
935936
vec::push(fields, self.parse_field(token::COLON));
936937
}
937938

938939
let base;
939-
if self.eat_keyword(~"with") {
940+
if self.eat_keyword(~"with") || self.eat(token::DOTDOT) {
940941
base = some(self.parse_expr());
941942
} else {
942943
base = none;
@@ -1548,6 +1549,16 @@ class parser {
15481549
let mut fields = ~[self.parse_field(token::COLON)];
15491550
let mut base = none;
15501551
while self.token != token::RBRACE {
1552+
if self.token == token::COMMA
1553+
&& self.look_ahead(1) == token::DOTDOT {
1554+
self.bump();
1555+
self.bump();
1556+
base = some(self.parse_expr()); break;
1557+
}
1558+
1559+
// XXX: Remove "with" after all code is converted over and there's
1560+
// a snapshot.
1561+
15511562
// optional comma before "with"
15521563
if self.token == token::COMMA
15531564
&& self.token_is_keyword(~"with",

src/libsyntax/print/pprust.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,9 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
10391039
some(expr) => {
10401040
if vec::len(fields) > 0u { space(s.s); }
10411041
ibox(s, indent_unit);
1042-
word_space(s, ~"with");
1042+
word(s.s, ~",");
1043+
space(s.s);
1044+
word(s.s, ~"..");
10431045
print_expr(s, expr);
10441046
end(s);
10451047
}
@@ -1055,7 +1057,9 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
10551057
some(expr) => {
10561058
if vec::len(fields) > 0u { space(s.s); }
10571059
ibox(s, indent_unit);
1058-
word_space(s, ~"with");
1060+
word(s.s, ~",");
1061+
space(s.s);
1062+
word(s.s, ~"..");
10591063
print_expr(s, expr);
10601064
end(s);
10611065
}

src/test/run-pass/functional-struct-update.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ struct Foo {
55

66
fn main() {
77
let a = Foo { x: 1, y: 2 };
8-
let b = Foo { x: 3 with a };
9-
let c = Foo { x: 4, with a };
10-
io::println(fmt!("%? %?", b, c));
8+
let c = Foo { x: 4, .. a };
9+
io::println(fmt!("%?", c));
1110
}
1211

0 commit comments

Comments
 (0)