Skip to content

Commit e2a9c04

Browse files
author
Keegan McAllister
committed
Allow leading :: in use items
1 parent ad7c647 commit e2a9c04

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5973,6 +5973,10 @@ impl<'a> Parser<'a> {
59735973
fn parse_view_path(&mut self) -> P<ViewPath> {
59745974
let lo = self.span.lo;
59755975

5976+
// Allow a leading :: because the paths are absolute either way.
5977+
// This occurs with "use $crate::..." in macros.
5978+
self.eat(&token::ModSep);
5979+
59765980
if self.check(&token::OpenDelim(token::Brace)) {
59775981
// use {foo,bar}
59785982
let idents = self.parse_unspanned_seq(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
fn main() {
12+
use ::std::mem;
13+
mem::drop(2u);
14+
}

src/test/run-pass/macro-crate-use.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
#![feature(macro_rules)]
12+
13+
pub fn increment(x: uint) -> uint {
14+
x + 1
15+
}
16+
17+
#[macro_export]
18+
macro_rules! increment {
19+
($x:expr) => ({
20+
use $crate::increment;
21+
increment($x)
22+
})
23+
}
24+
25+
fn main() {
26+
assert_eq!(increment!(3), 4);
27+
}

0 commit comments

Comments
 (0)