Skip to content

Commit fff03a5

Browse files
committed
auto merge of #10808 : kballard/rust/use-braces, r=alexcrichton
This fixes #10806.
2 parents b8516de + bd36b06 commit fff03a5

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

src/libsyntax/parse/parser.rs

+15
Original file line numberDiff line numberDiff line change
@@ -4828,6 +4828,21 @@ impl Parser {
48284828
fn parse_view_path(&self) -> @view_path {
48294829
let lo = self.span.lo;
48304830

4831+
if *self.token == token::LBRACE {
4832+
// use {foo,bar}
4833+
let idents = self.parse_unspanned_seq(
4834+
&token::LBRACE, &token::RBRACE,
4835+
seq_sep_trailing_allowed(token::COMMA),
4836+
|p| p.parse_path_list_ident());
4837+
let path = ast::Path {
4838+
span: mk_sp(lo, self.span.hi),
4839+
global: false,
4840+
segments: ~[]
4841+
};
4842+
return @spanned(lo, self.span.hi,
4843+
view_path_list(path, idents, ast::DUMMY_NODE_ID));
4844+
}
4845+
48314846
let first_ident = self.parse_ident();
48324847
let mut path = ~[first_ident];
48334848
debug!("parsed view_path: {}", self.id_to_str(first_ident));

src/libsyntax/print/pprust.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1935,8 +1935,12 @@ pub fn print_view_path(s: @ps, vp: &ast::view_path) {
19351935
}
19361936

19371937
ast::view_path_list(ref path, ref idents, _) => {
1938-
print_path(s, path, false);
1939-
word(s.s, "::{");
1938+
if path.segments.is_empty() {
1939+
word(s.s, "{");
1940+
} else {
1941+
print_path(s, path, false);
1942+
word(s.s, "::{");
1943+
}
19401944
commasep(s, inconsistent, (*idents), |s, w| {
19411945
print_ident(s, w.node.name);
19421946
});

src/test/run-pass/issue-10806.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2013 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+
// xfail-fast
12+
13+
pub fn foo() -> int {
14+
3
15+
}
16+
pub fn bar() -> int {
17+
4
18+
}
19+
20+
pub mod baz {
21+
use {foo, bar};
22+
pub fn quux() -> int {
23+
foo() + bar()
24+
}
25+
}
26+
27+
pub mod grault {
28+
use {foo};
29+
pub fn garply() -> int {
30+
foo()
31+
}
32+
}
33+
34+
pub mod waldo {
35+
use {};
36+
pub fn plugh() -> int {
37+
0
38+
}
39+
}
40+
41+
fn main() {
42+
let _x = baz::quux();
43+
let _y = grault::garply();
44+
let _z = waldo::plugh();
45+
}

0 commit comments

Comments
 (0)