2020-11-24 13:47:49 -06:00
|
|
|
// aux-build:attr-stmt-expr.rs
|
|
|
|
// aux-build:test-macros.rs
|
|
|
|
// compile-flags: -Z span-debug
|
|
|
|
// check-pass
|
|
|
|
|
|
|
|
#![feature(proc_macro_hygiene)]
|
|
|
|
#![feature(stmt_expr_attributes)]
|
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
#![no_std] // Don't load unnecessary hygiene information from std
|
|
|
|
extern crate std;
|
|
|
|
|
|
|
|
extern crate attr_stmt_expr;
|
|
|
|
extern crate test_macros;
|
2020-11-26 20:44:09 -06:00
|
|
|
use attr_stmt_expr::{expect_let, expect_my_macro_stmt, expect_expr, expect_my_macro_expr};
|
2020-11-24 13:47:49 -06:00
|
|
|
use test_macros::print_attr;
|
2020-11-26 20:44:09 -06:00
|
|
|
|
|
|
|
// 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)*) => { () }
|
|
|
|
}
|
|
|
|
|
2020-11-24 13:47:49 -06: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]
|
|
|
|
my_macro!("{}", string)
|
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]
|
|
|
|
$stmt; // This semicolon is *not* passed to the macro,
|
|
|
|
// since `$stmt` is already a statement.
|
2020-11-24 13:47:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! second_make_stmt {
|
|
|
|
($stmt:stmt) => {
|
|
|
|
make_stmt!($stmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 15:58:10 -06:00
|
|
|
// The macro will see a semicolon here
|
|
|
|
#[print_attr]
|
|
|
|
struct ItemWithSemi;
|
|
|
|
|
2020-11-24 13:47:49 -06:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
make_stmt!(struct Foo {});
|
|
|
|
|
|
|
|
#[print_attr]
|
|
|
|
#[expect_let]
|
|
|
|
let string = "Hello, world!";
|
|
|
|
|
|
|
|
#[print_attr]
|
2020-11-26 20:44:09 -06:00
|
|
|
#[expect_my_macro_stmt]
|
|
|
|
my_macro!("{}", string);
|
2020-11-24 13:47:49 -06:00
|
|
|
|
|
|
|
#[print_attr]
|
|
|
|
second_make_stmt!(#[allow(dead_code)] struct Bar {});
|
|
|
|
|
|
|
|
#[print_attr]
|
|
|
|
#[rustc_dummy]
|
|
|
|
struct Other {};
|
|
|
|
|
2020-11-25 15:58:10 -06:00
|
|
|
// The macro also sees a semicolon,
|
|
|
|
// for consistency with the `ItemWithSemi` case above.
|
|
|
|
#[print_attr]
|
|
|
|
#[rustc_dummy]
|
|
|
|
struct NonBracedStruct;
|
|
|
|
|
2020-11-24 13:47:49 -06:00
|
|
|
#[expect_expr]
|
|
|
|
print_str("string")
|
|
|
|
}
|