1 // aux-build:attr-stmt-expr.rs
2 // aux-build:test-macros.rs
3 // compile-flags: -Z span-debug
6 #![feature(proc_macro_hygiene)]
7 #![feature(stmt_expr_attributes)]
8 #![feature(rustc_attrs)]
11 #![no_std] // Don't load unnecessary hygiene information from std
14 extern crate attr_stmt_expr
;
15 extern crate test_macros
;
16 use attr_stmt_expr
::{expect_let, expect_my_macro_stmt, expect_expr, expect_my_macro_expr}
;
17 use test_macros
::print_attr
;
19 // We don't use `std::println` so that we avoid loading hygiene
20 // information from libstd, which would affect the SyntaxContext ids
21 macro_rules
! my_macro
{
22 ($
($tt
:tt
)*) => { () }
26 fn print_str(string
: &'
static str) {
27 // macros are handled a bit differently
28 #[expect_my_macro_expr]
29 my_macro
!("{}", string
)
32 macro_rules
! make_stmt
{
36 $stmt
; // This semicolon is *not* passed to the macro,
37 // since `$stmt` is already a statement.
41 macro_rules
! second_make_stmt
{
47 // The macro will see a semicolon here
53 make_stmt
!(struct Foo {}
);
57 let string
= "Hello, world!";
60 #[expect_my_macro_stmt]
61 my_macro
!("{}", string
);
64 second_make_stmt
!(#[allow(dead_code)] struct Bar {});
70 // The macro also sees a semicolon,
71 // for consistency with the `ItemWithSemi` case above.
74 struct NonBracedStruct
;