Add tests.
This commit is contained in:
parent
3eb235b45e
commit
754fdad4a8
14
src/test/compile-fail/feature-gate-decl_macro.rs
Normal file
14
src/test/compile-fail/feature-gate-decl_macro.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2017 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.
|
||||
|
||||
macro m() {} //~ ERROR `macro` is experimental (see issue #39412)
|
||||
//~| HELP add #![feature(decl_macro)] to the crate attributes to enable
|
||||
|
||||
fn main() {}
|
68
src/test/compile-fail/hygiene/globs.rs
Normal file
68
src/test/compile-fail/hygiene/globs.rs
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
mod foo {
|
||||
pub fn f() {}
|
||||
}
|
||||
|
||||
mod bar {
|
||||
pub fn g() {}
|
||||
}
|
||||
|
||||
macro m($($t:tt)*) {
|
||||
$($t)*
|
||||
use foo::*;
|
||||
f();
|
||||
g(); //~ ERROR cannot find function `g` in this scope
|
||||
}
|
||||
|
||||
fn main() {
|
||||
m! {
|
||||
use bar::*;
|
||||
g();
|
||||
f(); //~ ERROR cannot find function `f` in this scope
|
||||
}
|
||||
}
|
||||
|
||||
n!(f);
|
||||
macro n($i:ident) {
|
||||
mod foo {
|
||||
pub fn $i() -> u32 { 0 }
|
||||
pub fn f() {}
|
||||
|
||||
mod test {
|
||||
use super::*;
|
||||
fn g() {
|
||||
let _: u32 = $i();
|
||||
let _: () = f();
|
||||
}
|
||||
}
|
||||
|
||||
macro n($j:ident) {
|
||||
mod test {
|
||||
use super::*;
|
||||
fn g() {
|
||||
let _: u32 = $i();
|
||||
let _: () = f();
|
||||
$j();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
n!(f);
|
||||
mod test2 {
|
||||
super::n! {
|
||||
f //~ ERROR cannot find function `f` in this scope
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
src/test/compile-fail/hygiene/nested_macro_privacy.rs
Normal file
27
src/test/compile-fail/hygiene/nested_macro_privacy.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
macro n($foo:ident, $S:ident, $i:ident, $m:ident) {
|
||||
mod $foo {
|
||||
#[derive(Default)]
|
||||
pub struct $S { $i: u32 }
|
||||
pub macro $m($e:expr) { $e.$i }
|
||||
}
|
||||
}
|
||||
|
||||
n!(foo, S, i, m);
|
||||
|
||||
fn main() {
|
||||
use foo::{S, m};
|
||||
S::default().i; //~ ERROR field `i` of struct `foo::S` is private
|
||||
m!(S::default()); // ok
|
||||
}
|
25
src/test/compile-fail/hygiene/no_implicit_prelude.rs
Normal file
25
src/test/compile-fail/hygiene/no_implicit_prelude.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
mod foo {
|
||||
pub macro m() { Vec::new(); ().clone() }
|
||||
fn f() { ::bar::m!(); }
|
||||
}
|
||||
|
||||
#[no_implicit_prelude]
|
||||
mod bar {
|
||||
pub macro m() {
|
||||
Vec::new(); //~ ERROR failed to resolve
|
||||
().clone() //~ ERROR no method named `clone` found
|
||||
}
|
||||
fn f() { ::foo::m!(); }
|
||||
}
|
28
src/test/compile-fail/hygiene/privacy.rs
Normal file
28
src/test/compile-fail/hygiene/privacy.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
mod foo {
|
||||
fn f() {}
|
||||
|
||||
pub macro m($e:expr) {
|
||||
f();
|
||||
self::f();
|
||||
::foo::f();
|
||||
$e
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo::m!(
|
||||
foo::f() //~ ERROR `f` is private
|
||||
);
|
||||
}
|
31
src/test/compile-fail/hygiene/trait_items.rs
Normal file
31
src/test/compile-fail/hygiene/trait_items.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
mod foo {
|
||||
pub trait T {
|
||||
fn f(&self) {}
|
||||
}
|
||||
impl T for () {}
|
||||
}
|
||||
|
||||
mod bar {
|
||||
use foo::*;
|
||||
pub macro m() { ().f() }
|
||||
fn f() { ::baz::m!(); }
|
||||
}
|
||||
|
||||
mod baz {
|
||||
pub macro m() { ().f() } //~ ERROR no method named `f` found for type `()` in the current scope
|
||||
fn f() { ::bar::m!(); }
|
||||
}
|
||||
|
||||
fn main() {}
|
25
src/test/run-pass/hygiene/arguments.rs
Normal file
25
src/test/run-pass/hygiene/arguments.rs
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
macro m($t:ty, $e:expr) {
|
||||
mod foo {
|
||||
#[allow(unused)]
|
||||
struct S;
|
||||
pub(super) fn f(_: $t) {}
|
||||
}
|
||||
foo::f($e);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
struct S;
|
||||
m!(S, S);
|
||||
}
|
21
src/test/run-pass/hygiene/auxiliary/intercrate.rs
Normal file
21
src/test/run-pass/hygiene/auxiliary/intercrate.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
pub mod foo {
|
||||
pub use self::bar::m;
|
||||
mod bar {
|
||||
fn f() -> u32 { 1 }
|
||||
pub macro m() {
|
||||
f();
|
||||
}
|
||||
}
|
||||
}
|
38
src/test/run-pass/hygiene/fields.rs
Normal file
38
src/test/run-pass/hygiene/fields.rs
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
mod foo {
|
||||
struct S { x: u32 }
|
||||
struct T(u32);
|
||||
|
||||
pub macro m($S:ident, $x:ident) {{
|
||||
struct $S {
|
||||
$x: u32,
|
||||
x: i32,
|
||||
}
|
||||
|
||||
let s = S { x: 0 };
|
||||
let _ = s.x;
|
||||
|
||||
let t = T(0);
|
||||
let _ = t.0;
|
||||
|
||||
let s = $S { $x: 0, x: 1 };
|
||||
assert_eq!((s.$x, s.x), (0, 1));
|
||||
s
|
||||
}}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let s = foo::m!(S, x);
|
||||
assert_eq!(s.x, 0);
|
||||
}
|
42
src/test/run-pass/hygiene/impl_items.rs
Normal file
42
src/test/run-pass/hygiene/impl_items.rs
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
mod foo {
|
||||
struct S;
|
||||
impl S {
|
||||
fn f(&self) {}
|
||||
}
|
||||
|
||||
pub macro m() {
|
||||
let _: () = S.f();
|
||||
}
|
||||
}
|
||||
|
||||
struct S;
|
||||
|
||||
macro m($f:ident) {
|
||||
impl S {
|
||||
fn f(&self) -> u32 { 0 }
|
||||
fn $f(&self) -> i32 { 0 }
|
||||
}
|
||||
fn f() {
|
||||
let _: u32 = S.f();
|
||||
let _: i32 = S.$f();
|
||||
}
|
||||
}
|
||||
|
||||
m!(f);
|
||||
|
||||
fn main() {
|
||||
let _: i32 = S.f();
|
||||
foo::m!();
|
||||
}
|
19
src/test/run-pass/hygiene/intercrate.rs
Normal file
19
src/test/run-pass/hygiene/intercrate.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2017 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.
|
||||
|
||||
// aux-build:intercrate.rs
|
||||
|
||||
#![feature(decl_macro)]
|
||||
|
||||
extern crate intercrate;
|
||||
|
||||
fn main() {
|
||||
assert_eq!(intercrate::foo::m!(), 1);
|
||||
}
|
34
src/test/run-pass/hygiene/items.rs
Normal file
34
src/test/run-pass/hygiene/items.rs
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
pub macro m($foo:ident, $f:ident, $e:expr) {
|
||||
mod foo {
|
||||
pub fn f() -> u32 { 0 }
|
||||
pub fn $f() -> u64 { 0 }
|
||||
}
|
||||
|
||||
mod $foo {
|
||||
pub fn f() -> i32 { 0 }
|
||||
pub fn $f() -> i64 { 0 }
|
||||
}
|
||||
|
||||
let _: u32 = foo::f();
|
||||
let _: u64 = foo::$f();
|
||||
let _: i32 = $foo::f();
|
||||
let _: i64 = $foo::$f();
|
||||
let _: i64 = $e;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
m!(foo, f, foo::f());
|
||||
let _: i64 = foo::f();
|
||||
}
|
31
src/test/run-pass/hygiene/lexical.rs
Normal file
31
src/test/run-pass/hygiene/lexical.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
mod bar {
|
||||
mod baz {
|
||||
pub fn f() {}
|
||||
}
|
||||
|
||||
pub macro m($f:ident) {
|
||||
baz::f();
|
||||
let _: i32 = $f();
|
||||
{
|
||||
fn $f() -> u32 { 0 }
|
||||
let _: u32 = $f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn f() -> i32 { 0 }
|
||||
bar::m!(f);
|
||||
}
|
27
src/test/run-pass/hygiene/trait_items.rs
Normal file
27
src/test/run-pass/hygiene/trait_items.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
macro m($T:ident, $f:ident) {
|
||||
pub trait $T {
|
||||
fn f(&self) -> u32 { 0 }
|
||||
fn $f(&self) -> i32 { 0 }
|
||||
}
|
||||
impl $T for () {}
|
||||
|
||||
let _: u32 = ().f();
|
||||
let _: i32 = ().$f();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
m!(T, f);
|
||||
let _: i32 = ().f();
|
||||
}
|
21
src/test/run-pass/hygiene/ty_params.rs
Normal file
21
src/test/run-pass/hygiene/ty_params.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2017 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(decl_macro)]
|
||||
|
||||
macro m($T:ident) {
|
||||
fn f<T, $T>(t: T, t2: $T) -> (T, $T) {
|
||||
(t, t2)
|
||||
}
|
||||
}
|
||||
|
||||
m!(T);
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user