Skip to content

Commit 5563a9b

Browse files
committed
Improve span of env-related errors
1 parent 1078250 commit 5563a9b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

compiler/rustc_macros/src/symbols.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use proc_macro2::{Span, TokenStream};
2626
use quote::quote;
2727
use std::collections::HashMap;
2828
use syn::parse::{Parse, ParseStream, Result};
29-
use syn::{braced, punctuated::Punctuated, Expr, Ident, Lit, LitStr, Token};
29+
use syn::{braced, punctuated::Punctuated, Expr, Ident, Lit, LitStr, Macro, Token};
3030

3131
#[cfg(test)]
3232
mod tests;
@@ -59,7 +59,7 @@ struct Symbol {
5959
enum Value {
6060
SameAsName,
6161
String(LitStr),
62-
Env(LitStr),
62+
Env(LitStr, Macro),
6363
Unsupported(Expr),
6464
}
6565

@@ -84,7 +84,7 @@ impl Parse for Value {
8484
}
8585
Expr::Macro(expr) => {
8686
if expr.mac.path.is_ident("env") && let Ok(lit) = expr.mac.parse_body() {
87-
return Ok(Value::Env(lit));
87+
return Ok(Value::Env(lit, expr.mac.clone()));
8888
}
8989
}
9090
_ => {}
@@ -218,7 +218,7 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
218218
let value = match &symbol.value {
219219
Value::SameAsName => name.to_string(),
220220
Value::String(lit) => lit.value(),
221-
Value::Env(_) => continue, // in another loop below
221+
Value::Env(..) => continue, // in another loop below
222222
Value::Unsupported(expr) => {
223223
errors.list.push(syn::Error::new_spanned(
224224
expr,
@@ -252,15 +252,15 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
252252
// Symbols whose value comes from an environment variable. It's allowed for
253253
// these to have the same value as another symbol.
254254
for symbol in &input.symbols {
255-
let env_var = match &symbol.value {
256-
Value::Env(lit) => lit,
255+
let (env_var, expr) = match &symbol.value {
256+
Value::Env(lit, expr) => (lit, expr),
257257
Value::SameAsName | Value::String(_) | Value::Unsupported(_) => continue,
258258
};
259259

260260
let value = match proc_macro::tracked_env::var(env_var.value()) {
261261
Ok(value) => value,
262262
Err(err) => {
263-
errors.error(symbol.name.span(), err.to_string());
263+
errors.list.push(syn::Error::new_spanned(expr, err));
264264
continue;
265265
}
266266
};

0 commit comments

Comments
 (0)