syntax: Parse import prefixes as paths
This commit is contained in:
parent
6fa61b810d
commit
e7bc939f1e
9 changed files with 224 additions and 134 deletions
26
src/test/compile-fail/import-prefix-macro-1.rs
Normal file
26
src/test/compile-fail/import-prefix-macro-1.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
mod a {
|
||||
pub mod b {
|
||||
pub mod c {
|
||||
pub struct S;
|
||||
pub struct Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! import {
|
||||
($p: path) => (use $p {S, Z}); //~ERROR expected one of `::`, `;`, or `as`, found `{`
|
||||
}
|
||||
|
||||
import! { a::b::c }
|
||||
|
||||
fn main() {}
|
||||
26
src/test/compile-fail/import-prefix-macro-2.rs
Normal file
26
src/test/compile-fail/import-prefix-macro-2.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
mod a {
|
||||
pub mod b {
|
||||
pub mod c {
|
||||
pub struct S;
|
||||
pub struct Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! import {
|
||||
($p: path) => (use ::$p {S, Z}); //~ERROR expected identifier, found `a::b::c`
|
||||
}
|
||||
|
||||
import! { a::b::c }
|
||||
|
||||
fn main() {}
|
||||
25
src/test/compile-fail/import-ty-params.rs
Normal file
25
src/test/compile-fail/import-ty-params.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
mod a {
|
||||
pub mod b {
|
||||
pub mod c {
|
||||
pub struct S<T>(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! import {
|
||||
($p: path) => (use $p;);
|
||||
}
|
||||
|
||||
import! { a::b::c::S<u8> } //~ERROR type or lifetime parameter is found in import path
|
||||
|
||||
fn main() {}
|
||||
13
src/test/compile-fail/self_type_keyword-2.rs
Normal file
13
src/test/compile-fail/self_type_keyword-2.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
use self::Self as Foo; //~ ERROR unresolved import `self::Self`
|
||||
|
||||
pub fn main() {}
|
||||
|
|
@ -39,9 +39,6 @@ pub fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
use self::Self as Foo;
|
||||
//~^ ERROR expected identifier, found keyword `Self`
|
||||
|
||||
use std::option::Option as Self;
|
||||
//~^ ERROR expected identifier, found keyword `Self`
|
||||
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@
|
|||
|
||||
// compile-flags: -Z parse-only
|
||||
|
||||
use std::any::; //~ ERROR expected identifier or `{` or `*`, found `;`
|
||||
use std::any::; //~ ERROR expected identifier, found `;`
|
||||
|
|
|
|||
35
src/test/run-pass/import-prefix-macro.rs
Normal file
35
src/test/run-pass/import-prefix-macro.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
mod a {
|
||||
pub mod b {
|
||||
pub mod c {
|
||||
pub struct S;
|
||||
pub struct Z;
|
||||
}
|
||||
pub struct W;
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! import {
|
||||
(1 $p: path) => (use $p;);
|
||||
(2 $p: path) => (use $p::{Z};);
|
||||
(3 $p: path) => (use $p::*;);
|
||||
}
|
||||
|
||||
import! { 1 a::b::c::S }
|
||||
import! { 2 a::b::c }
|
||||
import! { 3 a::b }
|
||||
|
||||
fn main() {
|
||||
let s = S;
|
||||
let z = Z;
|
||||
let w = W;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue