rustc: Make functional record and struct update use ".." instead of "with".
"with" is still accepted for backwards compatibility.
This commit is contained in:
parent
c7ed9908d6
commit
87f4c15311
3 changed files with 21 additions and 7 deletions
|
@ -928,7 +928,8 @@ class parser {
|
|||
!self.is_keyword(~"with") {
|
||||
self.expect(token::COMMA);
|
||||
if self.token == token::RBRACE ||
|
||||
self.is_keyword(~"with") {
|
||||
self.is_keyword(~"with") ||
|
||||
self.token == token::DOTDOT {
|
||||
// Accept an optional trailing comma.
|
||||
break;
|
||||
}
|
||||
|
@ -936,7 +937,7 @@ class parser {
|
|||
}
|
||||
|
||||
let base;
|
||||
if self.eat_keyword(~"with") {
|
||||
if self.eat_keyword(~"with") || self.eat(token::DOTDOT) {
|
||||
base = some(self.parse_expr());
|
||||
} else {
|
||||
base = none;
|
||||
|
@ -1548,6 +1549,16 @@ class parser {
|
|||
let mut fields = ~[self.parse_field(token::COLON)];
|
||||
let mut base = none;
|
||||
while self.token != token::RBRACE {
|
||||
if self.token == token::COMMA
|
||||
&& self.look_ahead(1) == token::DOTDOT {
|
||||
self.bump();
|
||||
self.bump();
|
||||
base = some(self.parse_expr()); break;
|
||||
}
|
||||
|
||||
// XXX: Remove "with" after all code is converted over and there's
|
||||
// a snapshot.
|
||||
|
||||
// optional comma before "with"
|
||||
if self.token == token::COMMA
|
||||
&& self.token_is_keyword(~"with",
|
||||
|
|
|
@ -1039,7 +1039,9 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
|
|||
some(expr) => {
|
||||
if vec::len(fields) > 0u { space(s.s); }
|
||||
ibox(s, indent_unit);
|
||||
word_space(s, ~"with");
|
||||
word(s.s, ~",");
|
||||
space(s.s);
|
||||
word(s.s, ~"..");
|
||||
print_expr(s, expr);
|
||||
end(s);
|
||||
}
|
||||
|
@ -1055,7 +1057,9 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
|
|||
some(expr) => {
|
||||
if vec::len(fields) > 0u { space(s.s); }
|
||||
ibox(s, indent_unit);
|
||||
word_space(s, ~"with");
|
||||
word(s.s, ~",");
|
||||
space(s.s);
|
||||
word(s.s, ~"..");
|
||||
print_expr(s, expr);
|
||||
end(s);
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@ struct Foo {
|
|||
|
||||
fn main() {
|
||||
let a = Foo { x: 1, y: 2 };
|
||||
let b = Foo { x: 3 with a };
|
||||
let c = Foo { x: 4, with a };
|
||||
io::println(fmt!("%? %?", b, c));
|
||||
let c = Foo { x: 4, .. a };
|
||||
io::println(fmt!("%?", c));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue