diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/proc-macro/attr-stmt-expr.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/proc-macro/attr-stmt-expr.rs')
-rw-r--r-- | src/test/ui/proc-macro/attr-stmt-expr.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/test/ui/proc-macro/attr-stmt-expr.rs b/src/test/ui/proc-macro/attr-stmt-expr.rs new file mode 100644 index 000000000..0403684cd --- /dev/null +++ b/src/test/ui/proc-macro/attr-stmt-expr.rs @@ -0,0 +1,66 @@ +// aux-build:attr-stmt-expr.rs +// aux-build:test-macros.rs +// compile-flags: -Z span-debug + +#![feature(proc_macro_hygiene)] +#![feature(rustc_attrs)] + +#![no_std] // Don't load unnecessary hygiene information from std +extern crate std; +extern crate test_macros; +extern crate attr_stmt_expr; + +use test_macros::print_attr; +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)*) => { () } +} + +fn print_str(string: &'static str) { + // macros are handled a bit differently + #[expect_my_macro_expr] + //~^ ERROR attributes on expressions are experimental + //~| HELP add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + my_macro!("{}", string) +} + +macro_rules! make_stmt { + ($stmt:stmt) => { + #[print_attr] + #[rustc_dummy] + $stmt + } +} + +macro_rules! second_make_stmt { + ($stmt:stmt) => { + make_stmt!($stmt); + } +} + +fn main() { + make_stmt!(struct Foo {}); + + #[print_attr] + #[expect_let] + let string = "Hello, world!"; + + #[print_attr] + #[expect_my_macro_stmt] + my_macro!("{}", string); + + #[print_attr] + second_make_stmt!(#[allow(dead_code)] struct Bar {}); + + #[print_attr] + #[rustc_dummy] + struct Other {} + + #[expect_expr] + //~^ ERROR attributes on expressions are experimental + //~| HELP add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + print_str("string") +} |