Rollup merge of #72637 - euclio:env-hygiene, r=davidtwco

expand `env!` with def-site context

Similar to #66349.

Fixes rust-lang/rust-clippy#5619.
This commit is contained in:
Ralf Jung 2020-05-30 23:08:46 +02:00 committed by GitHub
commit 40fb1913e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 0 deletions

View file

@ -77,6 +77,7 @@ pub fn expand_env<'cx>(
return DummyResult::any(sp);
}
let sp = cx.with_def_site_ctxt(sp);
let e = match env::var(&*var.as_str()) {
Err(_) => {
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"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
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__");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
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"));
| ^^^^^^^^^^^^^^^^^^^^
|
= 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
--> $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");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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
--> $DIR/macros-nonfatal-errors.rs:23:13