2017-09-02 15:21:13 +00:00
|
|
|
//@ compile-flags: -Z trace-macros
|
|
|
|
|
2020-03-21 21:12:24 +00:00
|
|
|
#![recursion_limit = "4"]
|
2017-09-02 15:21:13 +00:00
|
|
|
|
|
|
|
macro_rules! my_faulty_macro {
|
|
|
|
() => {
|
2017-11-20 12:13:27 +00:00
|
|
|
my_faulty_macro!(bcd); //~ ERROR no rules
|
2017-09-02 15:21:13 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-02 16:13:25 +00:00
|
|
|
macro_rules! pat_macro {
|
2017-09-02 15:21:13 +00:00
|
|
|
() => {
|
2017-09-02 16:13:25 +00:00
|
|
|
pat_macro!(A{a:a, b:0, c:_, ..});
|
|
|
|
};
|
|
|
|
($a:pat) => {
|
2020-02-29 03:23:58 +00:00
|
|
|
$a //~ ERROR expected expression
|
2017-09-02 15:21:13 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! my_recursive_macro {
|
|
|
|
() => {
|
2017-11-20 12:13:27 +00:00
|
|
|
my_recursive_macro!(); //~ ERROR recursion limit
|
2017-09-02 15:21:13 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! my_macro {
|
2020-03-21 21:12:24 +00:00
|
|
|
() => {};
|
2017-09-02 15:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
my_faulty_macro!();
|
|
|
|
my_recursive_macro!();
|
|
|
|
test!();
|
|
|
|
non_exisiting!();
|
|
|
|
derive!(Debug);
|
2017-09-02 16:13:25 +00:00
|
|
|
let a = pat_macro!();
|
2017-09-02 15:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[my_macro]
|
2020-03-21 21:12:24 +00:00
|
|
|
fn use_bang_macro_as_attr() {}
|
2017-09-02 15:21:13 +00:00
|
|
|
|
2021-07-17 18:13:50 +00:00
|
|
|
#[derive(Debug)] //~ ERROR `derive` may only be applied to `struct`s
|
2020-03-21 21:12:24 +00:00
|
|
|
fn use_derive_macro_as_attr() {}
|
2023-07-31 14:55:47 +00:00
|
|
|
|
|
|
|
macro_rules! test {
|
|
|
|
(let $p:pat = $e:expr) => {test!(($p,$e))};
|
|
|
|
// this should be expr
|
|
|
|
// vvv
|
2024-05-16 06:26:37 +00:00
|
|
|
(($p:pat, $e:pat)) => {let $p = $e;}; //~ ERROR expected expression, found pattern `1+1`
|
2023-07-31 14:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn foo() {
|
|
|
|
test!(let x = 1+1);
|
|
|
|
}
|