mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 04:56:25 +03:00
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:
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user