Skip to content

Commit 7206157

Browse files
author
Alexander Regueiro
committed
Added run-pass and compile-fail tests.
1 parent d397378 commit 7206157

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 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(decl_macro)]
12+
13+
macro m($mod_name:ident) {
14+
pub mod $mod_name {
15+
pub const BAR: u32 = 123;
16+
}
17+
}
18+
19+
fn main() {
20+
m!(foo);
21+
let _ = foo::BAR;
22+
//~^ ERROR cannot find value `BAR` in module `foo`
23+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2018 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(decl_macro)]
12+
13+
macro m() {
14+
pub mod #foo {
15+
pub const BAR: u32 = 123;
16+
}
17+
}
18+
19+
fn main() {
20+
m!();
21+
let _ = foo::BAR;
22+
//~^ ERROR cannot find value `BAR` in module `foo`
23+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2018 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(decl_macro)]
12+
13+
macro m_helper() {
14+
struct #S;
15+
}
16+
17+
macro m() {
18+
m_helper!();
19+
let s = S;
20+
}
21+
22+
fn main() {
23+
m!();
24+
let s = S;
25+
//~^ ERROR cannot find value `S` in this scope
26+
}

src/test/run-pass/hygiene-optout-1.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 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(decl_macro)]
12+
13+
macro m($mod_name:ident) {
14+
pub mod #$mod_name {
15+
pub const #BAR: u32 = 123;
16+
}
17+
}
18+
19+
fn main() {
20+
m!(foo);
21+
assert_eq!(123, foo::BAR);
22+
}

src/test/run-pass/hygiene-optout-2.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 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(decl_macro)]
12+
13+
macro m() {
14+
pub mod #foo {
15+
pub const #BAR: u32 = 123;
16+
}
17+
}
18+
19+
fn main() {
20+
m!();
21+
assert_eq!(123, foo::BAR);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 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(decl_macro)]
12+
13+
use std::marker::PhantomData;
14+
15+
macro m($lifetime:tt) {
16+
pub struct #Foo<$lifetime>(PhantomData<&#'a ()>);
17+
}
18+
19+
fn main() {
20+
m!('a);
21+
let _ = Foo(Default::default());
22+
}

0 commit comments

Comments
 (0)