Skip to content

Commit e8564ad

Browse files
committed
Use custom macro instead of println
Loading a macro from libstd causes us to load serialized `SyntaxContext`s in a platform-dependent way, causing the printed spans to differ between platforms.
1 parent 6f91c32 commit e8564ad

File tree

6 files changed

+152
-141
lines changed

6 files changed

+152
-141
lines changed

src/test/ui/proc-macro/allowed-attr-stmt-expr.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ extern crate std;
1313

1414
extern crate attr_stmt_expr;
1515
extern crate test_macros;
16-
use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr};
16+
use attr_stmt_expr::{expect_let, expect_my_macro_stmt, expect_expr, expect_my_macro_expr};
1717
use test_macros::print_attr;
18-
use std::println;
18+
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)*) => { () }
23+
}
24+
1925

2026
fn print_str(string: &'static str) {
2127
// macros are handled a bit differently
22-
#[expect_print_expr]
23-
println!("{}", string)
28+
#[expect_my_macro_expr]
29+
my_macro!("{}", string)
2430
}
2531

2632
macro_rules! make_stmt {
@@ -51,8 +57,8 @@ fn main() {
5157
let string = "Hello, world!";
5258

5359
#[print_attr]
54-
#[expect_print_stmt]
55-
println!("{}", string);
60+
#[expect_my_macro_stmt]
61+
my_macro!("{}", string);
5662

5763
#[print_attr]
5864
second_make_stmt!(#[allow(dead_code)] struct Bar {});

0 commit comments

Comments
 (0)