expand env! with def-site context

This commit is contained in:
Andy Russell 2020-05-26 19:45:30 -04:00
parent 5239f5c57b
commit 68bf8d2487
No known key found for this signature in database
GPG Key ID: BE2221033EDBC374
5 changed files with 9 additions and 0 deletions

View File

@ -77,6 +77,7 @@ pub fn expand_env<'cx>(
return DummyResult::any(sp); return DummyResult::any(sp);
} }
let sp = cx.with_def_site_ctxt(sp);
let e = match env::var(&*var.as_str()) { let e = match env::var(&*var.as_str()) {
Err(_) => { Err(_) => {
cx.span_err(sp, &msg.as_str()); cx.span_err(sp, &msg.as_str());

View File

@ -3,6 +3,8 @@ error: my error message
| |
LL | fn main() { env!("__HOPEFULLY_NOT_DEFINED__", "my error message"); } LL | fn main() { env!("__HOPEFULLY_NOT_DEFINED__", "my error message"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error error: aborting due to previous error

View File

@ -3,6 +3,8 @@ error: environment variable `__HOPEFULLY_NOT_DEFINED__` not defined
| |
LL | env!("__HOPEFULLY_NOT_DEFINED__"); LL | env!("__HOPEFULLY_NOT_DEFINED__");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error error: aborting due to previous error

View File

@ -3,6 +3,8 @@ error: environment variable `NON_EXISTENT` not defined
| |
LL | include!(concat!(env!("NON_EXISTENT"), "/data.rs")); LL | include!(concat!(env!("NON_EXISTENT"), "/data.rs"));
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: suffixes on a string literal are invalid error: suffixes on a string literal are invalid
--> $DIR/issue-55897.rs:16:22 --> $DIR/issue-55897.rs:16:22

View File

@ -47,6 +47,8 @@ error: environment variable `RUST_HOPEFULLY_THIS_DOESNT_EXIST` not defined
| |
LL | env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST"); LL | env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: format argument must be a string literal error: format argument must be a string literal
--> $DIR/macros-nonfatal-errors.rs:23:13 --> $DIR/macros-nonfatal-errors.rs:23:13