]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/macro-expansion-tests.rs
Rollup merge of #42037 - nagisa:charpat, r=sfackler
[rust.git] / src / test / compile-fail / macro-expansion-tests.rs
1 // Copyright 2016 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 #![allow(unused_macros)]
12
13 mod macros_cant_escape_fns {
14     fn f() {
15         macro_rules! m { () => { 3 + 4 } }
16     }
17     fn g() -> i32 { m!() }
18     //~^ ERROR cannot find macro
19 }
20
21 mod macros_cant_escape_mods {
22     mod f {
23         macro_rules! m { () => { 3 + 4 } }
24     }
25     fn g() -> i32 { m!() }
26     //~^ ERROR cannot find macro
27 }
28
29 mod macros_can_escape_flattened_mods_test {
30     #[macro_use]
31     mod f {
32         macro_rules! m { () => { 3 + 4 } }
33     }
34     fn g() -> i32 { m!() }
35 }
36
37 fn macro_tokens_should_match() {
38     macro_rules! m { (a) => { 13 } }
39     m!(a);
40 }
41
42 // should be able to use a bound identifier as a literal in a macro definition:
43 fn self_macro_parsing() {
44     macro_rules! foo { (zz) => { 287; } }
45     fn f(zz: i32) {
46         foo!(zz);
47     }
48 }
49
50 fn main() {}