about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-04-21 06:44:30 +0200
committerGitHub <noreply@github.com>2023-04-21 06:44:30 +0200
commit637d9ddc35552a3ccc163efc5df2fc7af642c38f (patch)
tree82cb3a251b7b280d9f2c04805dbd542d41bd5e89
parent7d046551a77238f00b6869879c4edbed40c3ac02 (diff)
parenta2f275da511bbe03ca53bb4c90a344340b1c8fff (diff)
downloadrust-637d9ddc35552a3ccc163efc5df2fc7af642c38f.tar.gz
rust-637d9ddc35552a3ccc163efc5df2fc7af642c38f.zip
Rollup merge of #110578 - bvanjoi:fix-issue-110547, r=jackh726
fix(error): normalize whitespace during msg_to_buffer

close https://github.com/rust-lang/rust/issues/110547
-rw-r--r--compiler/rustc_errors/src/emitter.rs1
-rw-r--r--tests/ui/extenv/issue-110547.rs7
-rw-r--r--tests/ui/extenv/issue-110547.stderr29
3 files changed, 37 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs
index 8c76d5e010f..2498ae2b7bc 100644
--- a/compiler/rustc_errors/src/emitter.rs
+++ b/compiler/rustc_errors/src/emitter.rs
@@ -1336,6 +1336,7 @@ impl EmitterWriter {
         //                see?
         for (text, style) in msg.iter() {
             let text = self.translate_message(text, args).map_err(Report::new).unwrap();
+            let text = &normalize_whitespace(&text);
             let lines = text.split('\n').collect::<Vec<_>>();
             if lines.len() > 1 {
                 for (i, line) in lines.iter().enumerate() {
diff --git a/tests/ui/extenv/issue-110547.rs b/tests/ui/extenv/issue-110547.rs
new file mode 100644
index 00000000000..a6fb96ac066
--- /dev/null
+++ b/tests/ui/extenv/issue-110547.rs
@@ -0,0 +1,7 @@
+// compile-flags: -C debug-assertions
+
+fn main() {
+    env!{"\t"}; //~ ERROR not defined at compile time
+    env!("\t"); //~ ERROR not defined at compile time
+    env!("\u{2069}"); //~ ERROR not defined at compile time
+}
diff --git a/tests/ui/extenv/issue-110547.stderr b/tests/ui/extenv/issue-110547.stderr
new file mode 100644
index 00000000000..1219630d346
--- /dev/null
+++ b/tests/ui/extenv/issue-110547.stderr
@@ -0,0 +1,29 @@
+error: environment variable `    ` not defined at compile time
+  --> $DIR/issue-110547.rs:4:5
+   |
+LL |     env!{"\t"};
+   |     ^^^^^^^^^^
+   |
+   = help: use `std::env::var("    ")` to read the variable at run time
+   = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: environment variable `    ` not defined at compile time
+  --> $DIR/issue-110547.rs:5:5
+   |
+LL |     env!("\t");
+   |     ^^^^^^^^^^
+   |
+   = help: use `std::env::var("    ")` to read the variable at run time
+   = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: environment variable `` not defined at compile time
+  --> $DIR/issue-110547.rs:6:5
+   |
+LL |     env!("\u{2069}");
+   |     ^^^^^^^^^^^^^^^^
+   |
+   = help: use `std::env::var("")` to read the variable at run time
+   = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 3 previous errors
+