2018-03-16 06:20:56 +00:00
|
|
|
// aux-build:attr-stmt-expr.rs
|
2020-11-24 19:47:49 +00:00
|
|
|
// aux-build:test-macros.rs
|
|
|
|
// compile-flags: -Z span-debug
|
2018-03-16 06:20:56 +00:00
|
|
|
|
2018-07-06 01:09:35 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
2020-11-24 19:47:49 +00:00
|
|
|
#![feature(rustc_attrs)]
|
2018-03-16 06:20:56 +00:00
|
|
|
|
2020-11-24 19:47:49 +00:00
|
|
|
#![no_std] // Don't load unnecessary hygiene information from std
|
|
|
|
extern crate std;
|
|
|
|
extern crate test_macros;
|
2018-03-16 06:20:56 +00:00
|
|
|
extern crate attr_stmt_expr;
|
2020-11-24 19:47:49 +00:00
|
|
|
|
|
|
|
use test_macros::print_attr;
|
2020-11-27 02:44:09 +00:00
|
|
|
use attr_stmt_expr::{expect_let, expect_my_macro_stmt, expect_expr, expect_my_macro_expr};
|
|
|
|
|
|
|
|
// We don't use `std::println` so that we avoid loading hygiene
|
|
|
|
// information from libstd, which would affect the SyntaxContext ids
|
|
|
|
macro_rules! my_macro {
|
|
|
|
($($tt:tt)*) => { () }
|
|
|
|
}
|
2018-03-16 06:20:56 +00:00
|
|
|
|
|
|
|
fn print_str(string: &'static str) {
|
|
|
|
// macros are handled a bit differently
|
2020-11-27 02:44:09 +00:00
|
|
|
#[expect_my_macro_expr]
|
2018-03-16 06:20:56 +00:00
|
|
|
//~^ ERROR attributes on expressions are experimental
|
2019-07-09 09:32:08 +00:00
|
|
|
//~| HELP add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
|
2020-11-27 02:44:09 +00:00
|
|
|
my_macro!("{}", string)
|
2018-03-16 06:20:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 19:47:49 +00:00
|
|
|
macro_rules! make_stmt {
|
|
|
|
($stmt:stmt) => {
|
2020-11-17 19:27:44 +00:00
|
|
|
#[print_attr]
|
2020-11-25 21:58:10 +00:00
|
|
|
#[rustc_dummy]
|
2020-11-24 19:47:49 +00:00
|
|
|
$stmt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! second_make_stmt {
|
|
|
|
($stmt:stmt) => {
|
|
|
|
make_stmt!($stmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-16 06:20:56 +00:00
|
|
|
fn main() {
|
2020-11-24 19:47:49 +00:00
|
|
|
make_stmt!(struct Foo {});
|
|
|
|
|
|
|
|
#[print_attr]
|
2018-03-16 06:20:56 +00:00
|
|
|
#[expect_let]
|
|
|
|
let string = "Hello, world!";
|
|
|
|
|
2020-11-24 19:47:49 +00:00
|
|
|
#[print_attr]
|
2020-11-27 02:44:09 +00:00
|
|
|
#[expect_my_macro_stmt]
|
|
|
|
my_macro!("{}", string);
|
2018-03-16 06:20:56 +00:00
|
|
|
|
2020-11-24 19:47:49 +00:00
|
|
|
#[print_attr]
|
|
|
|
second_make_stmt!(#[allow(dead_code)] struct Bar {});
|
|
|
|
|
|
|
|
#[print_attr]
|
|
|
|
#[rustc_dummy]
|
|
|
|
struct Other {}
|
|
|
|
|
2018-03-16 06:20:56 +00:00
|
|
|
#[expect_expr]
|
|
|
|
//~^ ERROR attributes on expressions are experimental
|
2019-07-09 09:32:08 +00:00
|
|
|
//~| HELP add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
|
2018-03-16 06:20:56 +00:00
|
|
|
print_str("string")
|
|
|
|
}
|