Skip to content

Commit

Permalink
Fix symbols::tests::test_symbols
Browse files Browse the repository at this point in the history
    ---- 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
  • Loading branch information
dtolnay committed Oct 25, 2023
1 parent 4cec09a commit 34e14ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions compiler/rustc_macros/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
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) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/symbols/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit 34e14ef

Please sign in to comment.