]> git.lizzy.rs Git - rust.git/blob - tests/ui/proc-macro/attr-stmt-expr.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / proc-macro / attr-stmt-expr.rs
1 // aux-build:attr-stmt-expr.rs
2 // aux-build:test-macros.rs
3 // compile-flags: -Z span-debug
4
5 #![feature(proc_macro_hygiene)]
6 #![feature(rustc_attrs)]
7
8 #![no_std] // Don't load unnecessary hygiene information from std
9 extern crate std;
10 extern crate test_macros;
11 extern crate attr_stmt_expr;
12
13 use test_macros::print_attr;
14 use attr_stmt_expr::{expect_let, expect_my_macro_stmt, expect_expr, expect_my_macro_expr};
15
16 // We don't use `std::println` so that we avoid loading hygiene
17 // information from libstd, which would affect the SyntaxContext ids
18 macro_rules! my_macro {
19     ($($tt:tt)*) => { () }
20 }
21
22 fn print_str(string: &'static str) {
23     // macros are handled a bit differently
24     #[expect_my_macro_expr]
25     //~^ ERROR attributes on expressions are experimental
26     //~| HELP add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
27     my_macro!("{}", string)
28 }
29
30 macro_rules! make_stmt {
31     ($stmt:stmt) => {
32         #[print_attr]
33         #[rustc_dummy]
34         $stmt
35     }
36 }
37
38 macro_rules! second_make_stmt {
39     ($stmt:stmt) => {
40         make_stmt!($stmt);
41     }
42 }
43
44 fn main() {
45     make_stmt!(struct Foo {});
46
47     #[print_attr]
48     #[expect_let]
49     let string = "Hello, world!";
50
51     #[print_attr]
52     #[expect_my_macro_stmt]
53     my_macro!("{}", string);
54
55     #[print_attr]
56     second_make_stmt!(#[allow(dead_code)] struct Bar {});
57
58     #[print_attr]
59     #[rustc_dummy]
60     struct Other {}
61
62     #[expect_expr]
63     //~^ ERROR attributes on expressions are experimental
64     //~| HELP add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
65     print_str("string")
66 }