rust/tests/ui/macros/trace_faulty_macros.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1018 B
Rust
Raw Normal View History

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
};
}
macro_rules! pat_macro {
2017-09-02 15:21:13 +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);
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
#[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() {}
macro_rules! test {
(let $p:pat = $e:expr) => {test!(($p,$e))};
// this should be expr
// vvv
(($p:pat, $e:pat)) => {let $p = $e;}; //~ ERROR expected expression, found pattern `1+1`
}
fn foo() {
test!(let x = 1+1);
}