From c1552dfddd7a98f37e3269002a5624409d8f3481 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 25 Oct 2023 14:45:31 -0700 Subject: [PATCH] Fix symbols::tests::test_symbols ---- symbols::tests::test_symbols stdout ---- thread 'symbols::tests::test_symbols' panicked at library/proc_macro/src/bridge/client.rs:311:17: procedural macro API is used outside of a procedural macro --- compiler/rustc_macros/src/symbols.rs | 8 ++++++++ compiler/rustc_macros/src/symbols/tests.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_macros/src/symbols.rs b/compiler/rustc_macros/src/symbols.rs index e63bb06eb3f4e..4129712a6b218 100644 --- a/compiler/rustc_macros/src/symbols.rs +++ b/compiler/rustc_macros/src/symbols.rs @@ -257,6 +257,14 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec) { Value::SameAsName | Value::String(_) | Value::Unsupported(_) => continue, }; + if !proc_macro::is_available() { + errors.error( + Span::call_site(), + "proc_macro::tracked_env is not available in unit test".to_owned(), + ); + break; + } + let value = match proc_macro::tracked_env::var(env_var.value()) { Ok(value) => value, Err(err) => { diff --git a/compiler/rustc_macros/src/symbols/tests.rs b/compiler/rustc_macros/src/symbols/tests.rs index bd0c08a53c4f2..9c53453df5b54 100644 --- a/compiler/rustc_macros/src/symbols/tests.rs +++ b/compiler/rustc_macros/src/symbols/tests.rs @@ -27,7 +27,7 @@ fn test_symbols() { let body_tokens = m.mac.tokens.clone(); - test_symbols_macro(body_tokens, &[]); + test_symbols_macro(body_tokens, &["proc_macro::tracked_env is not available in unit test"]); } fn test_symbols_macro(input: TokenStream, expected_errors: &[&str]) {