Skip to content

Commit e3dc5f5

Browse files
committed
auto merge of #11911 : kballard/rust/empty-functional-update, r=pcwalton
Fixes #8972
2 parents a6764c2 + 2258243 commit e3dc5f5

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

src/libsyntax/parse/parser.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -1915,25 +1915,19 @@ impl Parser {
19151915
let mut fields = ~[];
19161916
let mut base = None;
19171917

1918-
fields.push(self.parse_field());
19191918
while self.token != token::RBRACE {
1920-
self.commit_expr(fields.last().unwrap().expr,
1921-
&[token::COMMA], &[token::RBRACE]);
1922-
19231919
if self.eat(&token::DOTDOT) {
19241920
base = Some(self.parse_expr());
19251921
break;
19261922
}
19271923

1928-
if self.token == token::RBRACE {
1929-
// Accept an optional trailing comma.
1930-
break;
1931-
}
19321924
fields.push(self.parse_field());
1925+
self.commit_expr(fields.last().unwrap().expr,
1926+
&[token::COMMA], &[token::RBRACE]);
19331927
}
19341928

19351929
hi = pth.span.hi;
1936-
self.commit_expr_expecting(fields.last().unwrap().expr, token::RBRACE);
1930+
self.expect(&token::RBRACE);
19371931
ex = ExprStruct(pth, fields, base);
19381932
return self.mk_expr(lo, hi, ex);
19391933
}
@@ -2583,8 +2577,9 @@ impl Parser {
25832577
// For distingishing between struct literals and blocks
25842578
fn looking_at_struct_literal(&mut self) -> bool {
25852579
self.token == token::LBRACE &&
2586-
(self.look_ahead(1, |t| token::is_plain_ident(t)) &&
2587-
self.look_ahead(2, |t| *t == token::COLON))
2580+
((self.look_ahead(1, |t| token::is_plain_ident(t)) &&
2581+
self.look_ahead(2, |t| *t == token::COLON))
2582+
|| self.look_ahead(1, |t| *t == token::DOTDOT))
25882583
}
25892584

25902585
fn parse_match_expr(&mut self) -> @Expr {

src/libsyntax/print/pprust.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1174,8 +1174,10 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) {
11741174
match wth {
11751175
Some(expr) => {
11761176
ibox(s, indent_unit);
1177-
word(&mut s.s, ",");
1178-
space(&mut s.s);
1177+
if !fields.is_empty() {
1178+
word(&mut s.s, ",");
1179+
space(&mut s.s);
1180+
}
11791181
word(&mut s.s, "..");
11801182
print_expr(s, expr);
11811183
end(s);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deriving(Eq,Clone)]
12+
struct Foo<T> {
13+
bar: T,
14+
baz: T
15+
}
16+
17+
pub fn main() {
18+
let foo = Foo {
19+
bar: 0,
20+
baz: 1
21+
};
22+
23+
let foo_ = foo.clone();
24+
let foo = Foo { ..foo };
25+
assert_eq!(foo, foo_);
26+
27+
let foo = Foo {
28+
bar: ~"one",
29+
baz: ~"two"
30+
};
31+
32+
let foo_ = foo.clone();
33+
let foo = Foo { ..foo };
34+
assert_eq!(foo, foo_);
35+
}

0 commit comments

Comments
 (0)