diff options
| author | Keegan McAllister <kmcallister@mozilla.com> | 2014-12-09 22:53:12 -0800 |
|---|---|---|
| committer | Keegan McAllister <kmcallister@mozilla.com> | 2015-01-05 11:38:12 -0800 |
| commit | e2a9c04e192926fde1a8e886b55e4c2b6e0e56cb (patch) | |
| tree | 6a0e56d493460f967b6475bb287a197c990fd830 | |
| parent | ad7c64777380a780b42028855ad0d09932a11623 (diff) | |
| download | rust-e2a9c04e192926fde1a8e886b55e4c2b6e0e56cb.tar.gz rust-e2a9c04e192926fde1a8e886b55e4c2b6e0e56cb.zip | |
Allow leading :: in use items
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 4 | ||||
| -rw-r--r-- | src/test/run-pass/crate-leading-sep.rs | 14 | ||||
| -rw-r--r-- | src/test/run-pass/macro-crate-use.rs | 27 |
3 files changed, 45 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f513692c31d..62bda20473f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5973,6 +5973,10 @@ impl<'a> Parser<'a> { fn parse_view_path(&mut self) -> P<ViewPath> { let lo = self.span.lo; + // Allow a leading :: because the paths are absolute either way. + // This occurs with "use $crate::..." in macros. + self.eat(&token::ModSep); + if self.check(&token::OpenDelim(token::Brace)) { // use {foo,bar} let idents = self.parse_unspanned_seq( diff --git a/src/test/run-pass/crate-leading-sep.rs b/src/test/run-pass/crate-leading-sep.rs new file mode 100644 index 00000000000..b2956f4e229 --- /dev/null +++ b/src/test/run-pass/crate-leading-sep.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + use ::std::mem; + mem::drop(2u); +} diff --git a/src/test/run-pass/macro-crate-use.rs b/src/test/run-pass/macro-crate-use.rs new file mode 100644 index 00000000000..1cea4fba2aa --- /dev/null +++ b/src/test/run-pass/macro-crate-use.rs @@ -0,0 +1,27 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(macro_rules)] + +pub fn increment(x: uint) -> uint { + x + 1 +} + +#[macro_export] +macro_rules! increment { + ($x:expr) => ({ + use $crate::increment; + increment($x) + }) +} + +fn main() { + assert_eq!(increment!(3), 4); +} |
