From ec0975dd6bdd2afb2cbe3373ba3da98ec8ef453b Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 3 Sep 2023 17:10:42 +0200 Subject: [PATCH] Don't forget to normalize the translated message --- compiler/rustc_errors/src/emitter.rs | 8 +++++++- .../const-eval/const_panic-normalize-tabs-115498.rs | 5 +++++ .../const_panic-normalize-tabs-115498.stderr | 11 +++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.rs create mode 100644 tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.stderr diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 0cae06881b174..fd8c283bde4b7 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2346,7 +2346,13 @@ impl FileWithAnnotatedLines { } let label = label.as_ref().map(|m| { - emitter.translate_message(m, args).map_err(Report::new).unwrap().to_string() + normalize_whitespace( + &emitter + .translate_message(m, &args) + .map_err(Report::new) + .unwrap() + .to_string(), + ) }); if lo.line != hi.line { diff --git a/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.rs b/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.rs new file mode 100644 index 0000000000000..0bf2f0e6669d7 --- /dev/null +++ b/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.rs @@ -0,0 +1,5 @@ +#![crate_type = "lib"] + +struct Bug([u8; panic!{"\t"}]); +//~^ ERROR evaluation of constant value failed +//~| NOTE: in this expansion of panic! diff --git a/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.stderr b/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.stderr new file mode 100644 index 0000000000000..82c63dd176d4d --- /dev/null +++ b/tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.stderr @@ -0,0 +1,11 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/const_panic-normalize-tabs-115498.rs:3:17 + | +LL | struct Bug([u8; panic!{"\t"}]); + | ^^^^^^^^^^^^ the evaluated program panicked at ' ', $DIR/const_panic-normalize-tabs-115498.rs:3:17 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`.