Skip to content

Commit bd36b06

Browse files
committed
Support imports of the form use {foo,bar}
This fixes #10806.
1 parent 4ab6a08 commit bd36b06

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

Diff for: src/libsyntax/parse/parser.rs

+15
Original file line numberDiff line numberDiff line change
@@ -4813,6 +4813,21 @@ impl Parser {
48134813
fn parse_view_path(&self) -> @view_path {
48144814
let lo = self.span.lo;
48154815

4816+
if *self.token == token::LBRACE {
4817+
// use {foo,bar}
4818+
let idents = self.parse_unspanned_seq(
4819+
&token::LBRACE, &token::RBRACE,
4820+
seq_sep_trailing_allowed(token::COMMA),
4821+
|p| p.parse_path_list_ident());
4822+
let path = ast::Path {
4823+
span: mk_sp(lo, self.span.hi),
4824+
global: false,
4825+
segments: ~[]
4826+
};
4827+
return @spanned(lo, self.span.hi,
4828+
view_path_list(path, idents, ast::DUMMY_NODE_ID));
4829+
}
4830+
48164831
let first_ident = self.parse_ident();
48174832
let mut path = ~[first_ident];
48184833
debug!("parsed view_path: {}", self.id_to_str(first_ident));

Diff for: 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
});

Diff for: 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)