From af74ca0666814e6c448259f2ab796435ababb664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 27 Dec 2022 11:03:59 -0800 Subject: [PATCH] Account for multiple multiline spans with empty padding Instead of ``` LL | fn oom( | __^ | | _| | || LL | || ) { | ||_- LL | | } | |__^ ``` emit ``` LL | // fn oom( LL | || ) { | ||_- LL | | } | |__^ ``` --- compiler/rustc_errors/src/emitter.rs | 22 ++++++++++++++++--- ...alloc-error-handler-bad-signature-1.stderr | 10 ++------- ...alloc-error-handler-bad-signature-2.stderr | 10 ++------- .../ui/asm/aarch64/interpolated-idents.stderr | 7 +----- .../ui/asm/x86_64/interpolated-idents.stderr | 7 +----- src/test/ui/issues/issue-13497-2.stderr | 5 +---- src/test/ui/suggestions/issue-99240-2.stderr | 5 +---- .../clippy/tests/ui/async_yields_async.stderr | 6 ++--- .../ui/result_map_unit_fn_unfixable.stderr | 5 +---- 9 files changed, 30 insertions(+), 47 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index e2a0e436fd5..0ca200abe19 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -845,7 +845,10 @@ impl EmitterWriter { // 3 | | // 4 | | } // | |_^ test - if let [ann] = &line.annotations[..] { + let mut buffer_ops = vec![]; + let mut annotations = vec![]; + let mut short_start = true; + for ann in &line.annotations { if let AnnotationType::MultilineStart(depth) = ann.annotation_type { if source_string.chars().take(ann.start_col).all(|c| c.is_whitespace()) { let style = if ann.is_primary { @@ -853,11 +856,24 @@ impl EmitterWriter { } else { Style::UnderlineSecondary }; - buffer.putc(line_offset, width_offset + depth - 1, '/', style); - return vec![(depth, style)]; + annotations.push((depth, style)); + buffer_ops.push((line_offset, width_offset + depth - 1, '/', style)); + } else { + short_start = false; + break; } + } else if let AnnotationType::MultilineLine(_) = ann.annotation_type { + } else { + short_start = false; + break; } } + if short_start { + for (y, x, c, s) in buffer_ops { + buffer.putc(y, x, c, s); + } + return annotations; + } // We want to display like this: // diff --git a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr index dd3665f22ac..59192a1ecc3 100644 --- a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr +++ b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr @@ -3,10 +3,7 @@ error[E0308]: mismatched types | LL | #[alloc_error_handler] | ---------------------- in this procedural macro expansion -LL | fn oom( - | __^ - | | _| - | || +LL | // fn oom( LL | || info: &Layout, LL | || ) -> () | ||_______- arguments to this function are incorrect @@ -29,10 +26,7 @@ error[E0308]: mismatched types | LL | #[alloc_error_handler] | ---------------------- in this procedural macro expansion -LL | fn oom( - | __^ - | | _| - | || +LL | // fn oom( LL | || info: &Layout, LL | || ) -> () | ||_______^ expected `!`, found `()` diff --git a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr index 2673ee9f937..7d23c2fc05a 100644 --- a/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr +++ b/src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr @@ -3,10 +3,7 @@ error[E0308]: mismatched types | LL | #[alloc_error_handler] | ---------------------- in this procedural macro expansion -LL | fn oom( - | __^ - | | _| - | || +LL | // fn oom( LL | || info: Layout, LL | || ) { | ||_- arguments to this function are incorrect @@ -36,10 +33,7 @@ error[E0308]: mismatched types | LL | #[alloc_error_handler] | ---------------------- in this procedural macro expansion -LL | fn oom( - | __^ - | | _| - | || +LL | // fn oom( LL | || info: Layout, LL | || ) { | ||_^ expected `!`, found `()` diff --git a/src/test/ui/asm/aarch64/interpolated-idents.stderr b/src/test/ui/asm/aarch64/interpolated-idents.stderr index 2df17f2e036..f6c50c2e1fd 100644 --- a/src/test/ui/asm/aarch64/interpolated-idents.stderr +++ b/src/test/ui/asm/aarch64/interpolated-idents.stderr @@ -30,12 +30,7 @@ error: asm outputs are not allowed with the `noreturn` option LL | asm!("", $in(x) x, $out(x) x, $lateout(x) x, $inout(x) x, $inlateout(x) x, | ^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ... -LL | m!(in out lateout inout inlateout const sym - | _____- - | |_____| - | |_____| - | |_____| - | | +LL | / m!(in out lateout inout inlateout const sym LL | | pure nomem readonly preserves_flags LL | | noreturn nostack options); | | - diff --git a/src/test/ui/asm/x86_64/interpolated-idents.stderr b/src/test/ui/asm/x86_64/interpolated-idents.stderr index 6ac2ac5a779..80a8c8c77cf 100644 --- a/src/test/ui/asm/x86_64/interpolated-idents.stderr +++ b/src/test/ui/asm/x86_64/interpolated-idents.stderr @@ -30,12 +30,7 @@ error: asm outputs are not allowed with the `noreturn` option LL | asm!("", $in(x) x, $out(x) x, $lateout(x) x, $inout(x) x, $inlateout(x) x, | ^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ... -LL | m!(in out lateout inout inlateout const sym - | _____- - | |_____| - | |_____| - | |_____| - | | +LL | / m!(in out lateout inout inlateout const sym LL | | pure nomem readonly preserves_flags LL | | noreturn nostack att_syntax options); | | - diff --git a/src/test/ui/issues/issue-13497-2.stderr b/src/test/ui/issues/issue-13497-2.stderr index 3abeadf9e4b..a365e24e27e 100644 --- a/src/test/ui/issues/issue-13497-2.stderr +++ b/src/test/ui/issues/issue-13497-2.stderr @@ -1,10 +1,7 @@ error[E0515]: cannot return value referencing local variable `rawLines` --> $DIR/issue-13497-2.rs:3:5 | -LL | rawLines - | ______^ - | | _____| - | || +LL | // rawLines LL | || .iter().map(|l| l.trim()).collect() | ||_______________-___________________________^ returns a value referencing data owned by the current function | |_______________| diff --git a/src/test/ui/suggestions/issue-99240-2.stderr b/src/test/ui/suggestions/issue-99240-2.stderr index 260df85653b..a2b55978478 100644 --- a/src/test/ui/suggestions/issue-99240-2.stderr +++ b/src/test/ui/suggestions/issue-99240-2.stderr @@ -4,10 +4,7 @@ error[E0618]: expected function, found enum variant `Alias::Unit` LL | Unit, | ---- enum variant `Alias::Unit` defined here ... -LL | Alias:: - | ______^ - | | _____| - | || +LL | // Alias:: LL | || Unit(); | ||________^_- call expression requires function | |________| diff --git a/src/tools/clippy/tests/ui/async_yields_async.stderr b/src/tools/clippy/tests/ui/async_yields_async.stderr index 92ba3592967..22ce1c6f647 100644 --- a/src/tools/clippy/tests/ui/async_yields_async.stderr +++ b/src/tools/clippy/tests/ui/async_yields_async.stderr @@ -3,8 +3,7 @@ error: an async construct yields a type which is itself awaitable | LL | let _h = async { | _____________________- -LL | | async { - | | _________^ +LL | |/ async { LL | || 3 LL | || } | ||_________^ awaitable value not awaited @@ -37,8 +36,7 @@ error: an async construct yields a type which is itself awaitable | LL | let _j = async || { | ________________________- -LL | | async { - | | _________^ +LL | |/ async { LL | || 3 LL | || } | ||_________^ awaitable value not awaited diff --git a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr index 2e1eb8eb180..d0e534f6356 100644 --- a/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr +++ b/src/tools/clippy/tests/ui/result_map_unit_fn_unfixable.stderr @@ -19,10 +19,7 @@ LL | x.field.map(|value| if value > 0 { do_nothing(value); do_nothing(value) error: called `map(f)` on an `Result` value where `f` is a closure that returns the unit type `()` --> $DIR/result_map_unit_fn_unfixable.rs:29:5 | -LL | x.field.map(|value| { - | ______^ - | | _____| - | || +LL | // x.field.map(|value| { LL | || do_nothing(value); LL | || do_nothing(value) LL | || });