Skip to content

Commit

Permalink
Rollup merge of rust-lang#72637 - euclio:env-hygiene, r=davidtwco
Browse files Browse the repository at this point in the history
expand `env!` with def-site context

Similar to rust-lang#66349.

Fixes rust-lang/rust-clippy#5619.
  • Loading branch information
RalfJung committed May 30, 2020
2 parents fadfcb6 + 68bf8d2 commit 40fb191
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustc_builtin_macros/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/extenv/extenv-not-defined-custom.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions src/test/ui/extenv/extenv-not-defined-default.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions src/test/ui/extenv/issue-55897.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/macros/macros-nonfatal-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40fb191

Please sign in to comment.