about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndy Russell <arussell123@gmail.com>2020-05-26 19:45:30 -0400
committerAndy Russell <arussell123@gmail.com>2020-05-26 21:49:55 -0400
commit68bf8d2487103f90c0427701cf2247d758de9d13 (patch)
treea477fffeba683be8a484f95a22e41137be331ca4
parent5239f5c57bb6eb9e894081727f5aba0a67e89763 (diff)
downloadrust-68bf8d2487103f90c0427701cf2247d758de9d13.tar.gz
rust-68bf8d2487103f90c0427701cf2247d758de9d13.zip
expand `env!` with def-site context
-rw-r--r--src/librustc_builtin_macros/env.rs1
-rw-r--r--src/test/ui/extenv/extenv-not-defined-custom.stderr2
-rw-r--r--src/test/ui/extenv/extenv-not-defined-default.stderr2
-rw-r--r--src/test/ui/extenv/issue-55897.stderr2
-rw-r--r--src/test/ui/macros/macros-nonfatal-errors.stderr2
5 files changed, 9 insertions, 0 deletions
diff --git a/src/librustc_builtin_macros/env.rs b/src/librustc_builtin_macros/env.rs
index 21e1889513b..d769ebb1f55 100644
--- a/src/librustc_builtin_macros/env.rs
+++ b/src/librustc_builtin_macros/env.rs
@@ -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());
diff --git a/src/test/ui/extenv/extenv-not-defined-custom.stderr b/src/test/ui/extenv/extenv-not-defined-custom.stderr
index 523982dd019..56415fd1f0d 100644
--- a/src/test/ui/extenv/extenv-not-defined-custom.stderr
+++ b/src/test/ui/extenv/extenv-not-defined-custom.stderr
@@ -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
 
diff --git a/src/test/ui/extenv/extenv-not-defined-default.stderr b/src/test/ui/extenv/extenv-not-defined-default.stderr
index 4bfe330f592..1a9332c4f1c 100644
--- a/src/test/ui/extenv/extenv-not-defined-default.stderr
+++ b/src/test/ui/extenv/extenv-not-defined-default.stderr
@@ -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
 
diff --git a/src/test/ui/extenv/issue-55897.stderr b/src/test/ui/extenv/issue-55897.stderr
index c57a467cdba..b62f06e33e5 100644
--- a/src/test/ui/extenv/issue-55897.stderr
+++ b/src/test/ui/extenv/issue-55897.stderr
@@ -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
diff --git a/src/test/ui/macros/macros-nonfatal-errors.stderr b/src/test/ui/macros/macros-nonfatal-errors.stderr
index 6ef757a55b8..42954ebcdc1 100644
--- a/src/test/ui/macros/macros-nonfatal-errors.stderr
+++ b/src/test/ui/macros/macros-nonfatal-errors.stderr
@@ -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