From 2e2a4797a26b0effe15815b403be4ba752cc7a0b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 12 Dec 2022 12:26:16 +0000 Subject: [PATCH] Don't emit empty notes --- compiler/rustc_errors/src/emitter.rs | 36 ++++++++++--------- src/test/ui/error-codes/E0004-2.stderr | 2 -- src/test/ui/error-codes/E0005.stderr | 2 -- src/test/ui/error-codes/E0297.stderr | 2 -- .../feature-gate-exhaustive-patterns.stderr | 2 -- ...-missing-pattern-excluding-comments.stderr | 2 -- .../doc-hidden-non-exhaustive.stderr | 2 -- .../ui/pattern/usefulness/issue-35609.stderr | 2 -- .../ui/pattern/usefulness/issue-3601.stderr | 2 +- .../usefulness/match-arm-statics-2.stderr | 2 -- .../usefulness/match-privately-empty.stderr | 2 -- .../usefulness/non-exhaustive-match.stderr | 2 -- ...recursive-types-are-not-uninhabited.stderr | 2 -- .../uninhabited-matches-feature-gated.stderr | 6 ---- 14 files changed, 20 insertions(+), 46 deletions(-) diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index aaf0699f0dc..268f17f86fe 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1431,25 +1431,27 @@ impl EmitterWriter { }; for (i, annotation) in annotations.into_iter().enumerate() { if let Some(label) = &annotation.label { - let style = if annotation.is_primary { - Style::LabelPrimary - } else { - Style::LabelSecondary - }; - if annotation_id == 0 { - buffer.prepend(line_idx, " |", Style::LineNumber); - for _ in 0..max_line_num_len { - buffer.prepend(line_idx, " ", Style::NoStyle); + if !label.is_empty() { + let style = if annotation.is_primary { + Style::LabelPrimary + } else { + Style::LabelSecondary + }; + if annotation_id == 0 { + buffer.prepend(line_idx, " |", Style::LineNumber); + for _ in 0..max_line_num_len { + buffer.prepend(line_idx, " ", Style::NoStyle); + } + line_idx += 1; + buffer.append(line_idx + i, " = note: ", style); + for _ in 0..max_line_num_len { + buffer.prepend(line_idx, " ", Style::NoStyle); + } + } else { + buffer.append(line_idx + i, ": ", style); } - line_idx += 1; - buffer.append(line_idx + i, " = note: ", style); - for _ in 0..max_line_num_len { - buffer.prepend(line_idx, " ", Style::NoStyle); - } - } else { - buffer.append(line_idx + i, ": ", style); + buffer.append(line_idx + i, label, style); } - buffer.append(line_idx + i, label, style); } } } diff --git a/src/test/ui/error-codes/E0004-2.stderr b/src/test/ui/error-codes/E0004-2.stderr index 200b5235259..7dd1396529b 100644 --- a/src/test/ui/error-codes/E0004-2.stderr +++ b/src/test/ui/error-codes/E0004-2.stderr @@ -6,8 +6,6 @@ LL | match x { } | note: `Option` defined here --> $SRC_DIR/core/src/option.rs:LL:COL - | - = note: $SRC_DIR/core/src/option.rs:LL:COL: not covered $SRC_DIR/core/src/option.rs:LL:COL: not covered = note: the matched value is of type `Option` diff --git a/src/test/ui/error-codes/E0005.stderr b/src/test/ui/error-codes/E0005.stderr index 762654671e0..ef1bb60d149 100644 --- a/src/test/ui/error-codes/E0005.stderr +++ b/src/test/ui/error-codes/E0005.stderr @@ -8,8 +8,6 @@ LL | let Some(y) = x; = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html note: `Option` defined here --> $SRC_DIR/core/src/option.rs:LL:COL - | - = note: $SRC_DIR/core/src/option.rs:LL:COL: not covered = note: the matched value is of type `Option` help: you might want to use `if let` to ignore the variant that isn't matched diff --git a/src/test/ui/error-codes/E0297.stderr b/src/test/ui/error-codes/E0297.stderr index 4d4bdfc09e9..5afa25dcb72 100644 --- a/src/test/ui/error-codes/E0297.stderr +++ b/src/test/ui/error-codes/E0297.stderr @@ -6,8 +6,6 @@ LL | for Some(x) in xs {} | note: `Option` defined here --> $SRC_DIR/core/src/option.rs:LL:COL - | - = note: $SRC_DIR/core/src/option.rs:LL:COL: not covered = note: the matched value is of type `Option` diff --git a/src/test/ui/feature-gates/feature-gate-exhaustive-patterns.stderr b/src/test/ui/feature-gates/feature-gate-exhaustive-patterns.stderr index fe1f247adc0..b26383af72f 100644 --- a/src/test/ui/feature-gates/feature-gate-exhaustive-patterns.stderr +++ b/src/test/ui/feature-gates/feature-gate-exhaustive-patterns.stderr @@ -8,8 +8,6 @@ LL | let Ok(_x) = foo(); = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html note: `Result` defined here --> $SRC_DIR/core/src/result.rs:LL:COL - | - = note: $SRC_DIR/core/src/result.rs:LL:COL: not covered = note: the matched value is of type `Result` help: you might want to use `if let` to ignore the variant that isn't matched diff --git a/src/test/ui/pattern/suggest-adding-appropriate-missing-pattern-excluding-comments.stderr b/src/test/ui/pattern/suggest-adding-appropriate-missing-pattern-excluding-comments.stderr index 635f6c86f4a..e0c88f81eac 100644 --- a/src/test/ui/pattern/suggest-adding-appropriate-missing-pattern-excluding-comments.stderr +++ b/src/test/ui/pattern/suggest-adding-appropriate-missing-pattern-excluding-comments.stderr @@ -6,8 +6,6 @@ LL | match Some(1) { | note: `Option` defined here --> $SRC_DIR/core/src/option.rs:LL:COL - | - = note: $SRC_DIR/core/src/option.rs:LL:COL: not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown diff --git a/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr b/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr index 610c86b3385..35e0661189f 100644 --- a/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr +++ b/src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr @@ -66,8 +66,6 @@ LL | match None { | note: `Option` defined here --> $SRC_DIR/core/src/option.rs:LL:COL - | - = note: $SRC_DIR/core/src/option.rs:LL:COL: not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms diff --git a/src/test/ui/pattern/usefulness/issue-35609.stderr b/src/test/ui/pattern/usefulness/issue-35609.stderr index 00dad2c8b67..12113957d63 100644 --- a/src/test/ui/pattern/usefulness/issue-35609.stderr +++ b/src/test/ui/pattern/usefulness/issue-35609.stderr @@ -107,8 +107,6 @@ LL | match Some(A) { | note: `Option` defined here --> $SRC_DIR/core/src/option.rs:LL:COL - | - = note: = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown, or multiple match arms | diff --git a/src/test/ui/pattern/usefulness/issue-3601.stderr b/src/test/ui/pattern/usefulness/issue-3601.stderr index 195703b922a..e8cfb3e7016 100644 --- a/src/test/ui/pattern/usefulness/issue-3601.stderr +++ b/src/test/ui/pattern/usefulness/issue-3601.stderr @@ -8,7 +8,7 @@ note: `Box` defined here --> $SRC_DIR/alloc/src/boxed.rs:LL:COL $SRC_DIR/alloc/src/boxed.rs:LL:COL $SRC_DIR/alloc/src/boxed.rs:LL:COL -$SRC_DIR/alloc/src/boxed.rs:LL:COL: +$SRC_DIR/alloc/src/boxed.rs:LL:COL = note: the matched value is of type `Box` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | diff --git a/src/test/ui/pattern/usefulness/match-arm-statics-2.stderr b/src/test/ui/pattern/usefulness/match-arm-statics-2.stderr index 88277eb223f..36fc8899100 100644 --- a/src/test/ui/pattern/usefulness/match-arm-statics-2.stderr +++ b/src/test/ui/pattern/usefulness/match-arm-statics-2.stderr @@ -19,8 +19,6 @@ LL | match Some(Some(North)) { | note: `Option>` defined here --> $SRC_DIR/core/src/option.rs:LL:COL - | - = note: $SRC_DIR/core/src/option.rs:LL:COL: not covered : not covered = note: the matched value is of type `Option>` diff --git a/src/test/ui/pattern/usefulness/match-privately-empty.stderr b/src/test/ui/pattern/usefulness/match-privately-empty.stderr index 0e1e1258110..9bb15ba8a42 100644 --- a/src/test/ui/pattern/usefulness/match-privately-empty.stderr +++ b/src/test/ui/pattern/usefulness/match-privately-empty.stderr @@ -6,8 +6,6 @@ LL | match private::DATA { | note: `Option` defined here --> $SRC_DIR/core/src/option.rs:LL:COL - | - = note: $SRC_DIR/core/src/option.rs:LL:COL: not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown diff --git a/src/test/ui/pattern/usefulness/non-exhaustive-match.stderr b/src/test/ui/pattern/usefulness/non-exhaustive-match.stderr index 755333cdb7e..1256867a652 100644 --- a/src/test/ui/pattern/usefulness/non-exhaustive-match.stderr +++ b/src/test/ui/pattern/usefulness/non-exhaustive-match.stderr @@ -36,8 +36,6 @@ LL | match Some(10) { | note: `Option` defined here --> $SRC_DIR/core/src/option.rs:LL:COL - | - = note: $SRC_DIR/core/src/option.rs:LL:COL: not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown diff --git a/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr b/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr index 8aaaa298318..429f0460e89 100644 --- a/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr +++ b/src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr @@ -8,8 +8,6 @@ LL | let Ok(x) = res; = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html note: `Result>` defined here --> $SRC_DIR/core/src/result.rs:LL:COL - | - = note: $SRC_DIR/core/src/result.rs:LL:COL: not covered = note: the matched value is of type `Result>` help: you might want to use `if let` to ignore the variant that isn't matched diff --git a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr index 44d485c47cd..c375fd62877 100644 --- a/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr +++ b/src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr @@ -6,8 +6,6 @@ LL | let _ = match x { | note: `Result` defined here --> $SRC_DIR/core/src/result.rs:LL:COL - | - = note: $SRC_DIR/core/src/result.rs:LL:COL: not covered = note: the matched value is of type `Result` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown @@ -85,8 +83,6 @@ LL | let _ = match x { | note: `Result` defined here --> $SRC_DIR/core/src/result.rs:LL:COL - | - = note: $SRC_DIR/core/src/result.rs:LL:COL: not covered = note: the matched value is of type `Result` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown @@ -105,8 +101,6 @@ LL | let Ok(x) = x; = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html note: `Result` defined here --> $SRC_DIR/core/src/result.rs:LL:COL - | - = note: $SRC_DIR/core/src/result.rs:LL:COL: not covered = note: the matched value is of type `Result` help: you might want to use `if let` to ignore the variant that isn't matched