Skip to content

Commit

Permalink
Use custom macro instead of println
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Aaron1011 committed Nov 27, 2020
1 parent 6f91c32 commit e8564ad
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 141 deletions.
18 changes: 12 additions & 6 deletions src/test/ui/proc-macro/allowed-attr-stmt-expr.rs
Expand Up @@ -13,14 +13,20 @@ extern crate std;

extern crate attr_stmt_expr;
extern crate test_macros;
use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr};
use attr_stmt_expr::{expect_let, expect_my_macro_stmt, expect_expr, expect_my_macro_expr};
use test_macros::print_attr;
use std::println;

// 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_print_expr]
println!("{}", string)
#[expect_my_macro_expr]
my_macro!("{}", string)
}

macro_rules! make_stmt {
Expand Down Expand Up @@ -51,8 +57,8 @@ fn main() {
let string = "Hello, world!";

#[print_attr]
#[expect_print_stmt]
println!("{}", string);
#[expect_my_macro_stmt]
my_macro!("{}", string);

#[print_attr]
second_make_stmt!(#[allow(dead_code)] struct Bar {});
Expand Down

0 comments on commit e8564ad

Please sign in to comment.