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