Skip to content

Commit 40fb191

Browse files
authored
Rollup merge of #72637 - euclio:env-hygiene, r=davidtwco
expand `env!` with def-site context Similar to #66349. Fixes rust-lang/rust-clippy#5619.
2 parents fadfcb6 + 68bf8d2 commit 40fb191

File tree

5 files changed

+9
-0
lines changed

5 files changed

+9
-0
lines changed

src/librustc_builtin_macros/env.rs

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub fn expand_env<'cx>(
7777
return DummyResult::any(sp);
7878
}
7979

80+
let sp = cx.with_def_site_ctxt(sp);
8081
let e = match env::var(&*var.as_str()) {
8182
Err(_) => {
8283
cx.span_err(sp, &msg.as_str());

src/test/ui/extenv/extenv-not-defined-custom.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: my error message
33
|
44
LL | fn main() { env!("__HOPEFULLY_NOT_DEFINED__", "my error message"); }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error: aborting due to previous error
810

src/test/ui/extenv/extenv-not-defined-default.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: environment variable `__HOPEFULLY_NOT_DEFINED__` not defined
33
|
44
LL | env!("__HOPEFULLY_NOT_DEFINED__");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error: aborting due to previous error
810

src/test/ui/extenv/issue-55897.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: environment variable `NON_EXISTENT` not defined
33
|
44
LL | include!(concat!(env!("NON_EXISTENT"), "/data.rs"));
55
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
68

79
error: suffixes on a string literal are invalid
810
--> $DIR/issue-55897.rs:16:22

src/test/ui/macros/macros-nonfatal-errors.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ error: environment variable `RUST_HOPEFULLY_THIS_DOESNT_EXIST` not defined
4747
|
4848
LL | env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST");
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
|
51+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
5052

5153
error: format argument must be a string literal
5254
--> $DIR/macros-nonfatal-errors.rs:23:13

0 commit comments

Comments
 (0)