Skip to content

Commit 2e2a479

Browse files
committed
Don't emit empty notes
1 parent 063b167 commit 2e2a479

14 files changed

+20
-46
lines changed

compiler/rustc_errors/src/emitter.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -1431,25 +1431,27 @@ impl EmitterWriter {
14311431
};
14321432
for (i, annotation) in annotations.into_iter().enumerate() {
14331433
if let Some(label) = &annotation.label {
1434-
let style = if annotation.is_primary {
1435-
Style::LabelPrimary
1436-
} else {
1437-
Style::LabelSecondary
1438-
};
1439-
if annotation_id == 0 {
1440-
buffer.prepend(line_idx, " |", Style::LineNumber);
1441-
for _ in 0..max_line_num_len {
1442-
buffer.prepend(line_idx, " ", Style::NoStyle);
1434+
if !label.is_empty() {
1435+
let style = if annotation.is_primary {
1436+
Style::LabelPrimary
1437+
} else {
1438+
Style::LabelSecondary
1439+
};
1440+
if annotation_id == 0 {
1441+
buffer.prepend(line_idx, " |", Style::LineNumber);
1442+
for _ in 0..max_line_num_len {
1443+
buffer.prepend(line_idx, " ", Style::NoStyle);
1444+
}
1445+
line_idx += 1;
1446+
buffer.append(line_idx + i, " = note: ", style);
1447+
for _ in 0..max_line_num_len {
1448+
buffer.prepend(line_idx, " ", Style::NoStyle);
1449+
}
1450+
} else {
1451+
buffer.append(line_idx + i, ": ", style);
14431452
}
1444-
line_idx += 1;
1445-
buffer.append(line_idx + i, " = note: ", style);
1446-
for _ in 0..max_line_num_len {
1447-
buffer.prepend(line_idx, " ", Style::NoStyle);
1448-
}
1449-
} else {
1450-
buffer.append(line_idx + i, ": ", style);
1453+
buffer.append(line_idx + i, label, style);
14511454
}
1452-
buffer.append(line_idx + i, label, style);
14531455
}
14541456
}
14551457
}

src/test/ui/error-codes/E0004-2.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | match x { }
66
|
77
note: `Option<i32>` defined here
88
--> $SRC_DIR/core/src/option.rs:LL:COL
9-
|
10-
= note:
119
$SRC_DIR/core/src/option.rs:LL:COL: not covered
1210
$SRC_DIR/core/src/option.rs:LL:COL: not covered
1311
= note: the matched value is of type `Option<i32>`

src/test/ui/error-codes/E0005.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ LL | let Some(y) = x;
88
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
99
note: `Option<i32>` defined here
1010
--> $SRC_DIR/core/src/option.rs:LL:COL
11-
|
12-
= note:
1311
$SRC_DIR/core/src/option.rs:LL:COL: not covered
1412
= note: the matched value is of type `Option<i32>`
1513
help: you might want to use `if let` to ignore the variant that isn't matched

src/test/ui/error-codes/E0297.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | for Some(x) in xs {}
66
|
77
note: `Option<i32>` defined here
88
--> $SRC_DIR/core/src/option.rs:LL:COL
9-
|
10-
= note:
119
$SRC_DIR/core/src/option.rs:LL:COL: not covered
1210
= note: the matched value is of type `Option<i32>`
1311

src/test/ui/feature-gates/feature-gate-exhaustive-patterns.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ LL | let Ok(_x) = foo();
88
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
99
note: `Result<u32, !>` defined here
1010
--> $SRC_DIR/core/src/result.rs:LL:COL
11-
|
12-
= note:
1311
$SRC_DIR/core/src/result.rs:LL:COL: not covered
1412
= note: the matched value is of type `Result<u32, !>`
1513
help: you might want to use `if let` to ignore the variant that isn't matched

src/test/ui/pattern/suggest-adding-appropriate-missing-pattern-excluding-comments.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | match Some(1) {
66
|
77
note: `Option<i32>` defined here
88
--> $SRC_DIR/core/src/option.rs:LL:COL
9-
|
10-
= note:
119
$SRC_DIR/core/src/option.rs:LL:COL: not covered
1210
= note: the matched value is of type `Option<i32>`
1311
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown

src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ LL | match None {
6666
|
6767
note: `Option<HiddenEnum>` defined here
6868
--> $SRC_DIR/core/src/option.rs:LL:COL
69-
|
70-
= note:
7169
$SRC_DIR/core/src/option.rs:LL:COL: not covered
7270
= note: the matched value is of type `Option<HiddenEnum>`
7371
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

src/test/ui/pattern/usefulness/issue-35609.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ LL | match Some(A) {
107107
|
108108
note: `Option<Enum>` defined here
109109
--> $SRC_DIR/core/src/option.rs:LL:COL
110-
|
111-
= note:
112110
= note: the matched value is of type `Option<Enum>`
113111
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown, or multiple match arms
114112
|

src/test/ui/pattern/usefulness/issue-3601.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ note: `Box<ElementKind>` defined here
88
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
99
$SRC_DIR/alloc/src/boxed.rs:LL:COL
1010
$SRC_DIR/alloc/src/boxed.rs:LL:COL
11-
$SRC_DIR/alloc/src/boxed.rs:LL:COL:
11+
$SRC_DIR/alloc/src/boxed.rs:LL:COL
1212
= note: the matched value is of type `Box<ElementKind>`
1313
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1414
|

src/test/ui/pattern/usefulness/match-arm-statics-2.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ LL | match Some(Some(North)) {
1919
|
2020
note: `Option<Option<Direction>>` defined here
2121
--> $SRC_DIR/core/src/option.rs:LL:COL
22-
|
23-
= note:
2422
$SRC_DIR/core/src/option.rs:LL:COL: not covered
2523
: not covered
2624
= note: the matched value is of type `Option<Option<Direction>>`

src/test/ui/pattern/usefulness/match-privately-empty.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | match private::DATA {
66
|
77
note: `Option<Private>` defined here
88
--> $SRC_DIR/core/src/option.rs:LL:COL
9-
|
10-
= note:
119
$SRC_DIR/core/src/option.rs:LL:COL: not covered
1210
= note: the matched value is of type `Option<Private>`
1311
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown

src/test/ui/pattern/usefulness/non-exhaustive-match.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ LL | match Some(10) {
3636
|
3737
note: `Option<i32>` defined here
3838
--> $SRC_DIR/core/src/option.rs:LL:COL
39-
|
40-
= note:
4139
$SRC_DIR/core/src/option.rs:LL:COL: not covered
4240
= note: the matched value is of type `Option<i32>`
4341
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown

src/test/ui/recursion/recursive-types-are-not-uninhabited.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ LL | let Ok(x) = res;
88
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
99
note: `Result<u32, &R<'_>>` defined here
1010
--> $SRC_DIR/core/src/result.rs:LL:COL
11-
|
12-
= note:
1311
$SRC_DIR/core/src/result.rs:LL:COL: not covered
1412
= note: the matched value is of type `Result<u32, &R<'_>>`
1513
help: you might want to use `if let` to ignore the variant that isn't matched

src/test/ui/uninhabited/uninhabited-matches-feature-gated.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | let _ = match x {
66
|
77
note: `Result<u32, &Void>` defined here
88
--> $SRC_DIR/core/src/result.rs:LL:COL
9-
|
10-
= note:
119
$SRC_DIR/core/src/result.rs:LL:COL: not covered
1210
= note: the matched value is of type `Result<u32, &Void>`
1311
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 {
8583
|
8684
note: `Result<u32, Void>` defined here
8785
--> $SRC_DIR/core/src/result.rs:LL:COL
88-
|
89-
= note:
9086
$SRC_DIR/core/src/result.rs:LL:COL: not covered
9187
= note: the matched value is of type `Result<u32, Void>`
9288
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;
105101
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
106102
note: `Result<u32, Void>` defined here
107103
--> $SRC_DIR/core/src/result.rs:LL:COL
108-
|
109-
= note:
110104
$SRC_DIR/core/src/result.rs:LL:COL: not covered
111105
= note: the matched value is of type `Result<u32, Void>`
112106
help: you might want to use `if let` to ignore the variant that isn't matched

0 commit comments

Comments
 (0)