Skip to content

Commit 59554a2

Browse files
committed
Avoid rendering empty annotations
1 parent 2e2a479 commit 59554a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+94
-195
lines changed

compiler/rustc_errors/src/emitter.rs

+44-37
Original file line numberDiff line numberDiff line change
@@ -1408,51 +1408,58 @@ impl EmitterWriter {
14081408
if !sm.ensure_source_file_source_present(annotated_file.file.clone()) {
14091409
if !self.short_message {
14101410
// We'll just print an unannotated message.
1411-
for (annotation_id, line) in annotated_file.lines.into_iter().enumerate() {
1411+
for (annotation_id, line) in annotated_file.lines.iter().enumerate() {
14121412
let mut annotations = line.annotations.clone();
14131413
annotations.sort_by_key(|a| Reverse(a.start_col));
14141414
let mut line_idx = buffer.num_lines();
1415-
buffer.append(
1416-
line_idx,
1417-
&format!(
1418-
"{}:{}:{}",
1419-
sm.filename_for_diagnostics(&annotated_file.file.name),
1420-
sm.doctest_offset_line(&annotated_file.file.name, line.line_index),
1421-
annotations[0].start_col + 1,
1422-
),
1423-
Style::LineAndColumn,
1424-
);
1425-
if annotation_id == 0 {
1426-
buffer.prepend(line_idx, "--> ", Style::LineNumber);
1415+
1416+
let labels: Vec<_> = annotations
1417+
.iter()
1418+
.filter_map(|a| Some((a.label.as_ref()?, a.is_primary)))
1419+
.filter(|(l, _)| !l.is_empty())
1420+
.collect();
1421+
1422+
if annotation_id == 0 || !labels.is_empty() {
1423+
buffer.append(
1424+
line_idx,
1425+
&format!(
1426+
"{}:{}:{}",
1427+
sm.filename_for_diagnostics(&annotated_file.file.name),
1428+
sm.doctest_offset_line(
1429+
&annotated_file.file.name,
1430+
line.line_index
1431+
),
1432+
annotations[0].start_col + 1,
1433+
),
1434+
Style::LineAndColumn,
1435+
);
1436+
if annotation_id == 0 {
1437+
buffer.prepend(line_idx, "--> ", Style::LineNumber);
1438+
} else {
1439+
buffer.prepend(line_idx, "::: ", Style::LineNumber);
1440+
}
14271441
for _ in 0..max_line_num_len {
14281442
buffer.prepend(line_idx, " ", Style::NoStyle);
14291443
}
14301444
line_idx += 1;
1431-
};
1432-
for (i, annotation) in annotations.into_iter().enumerate() {
1433-
if let Some(label) = &annotation.label {
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);
1452-
}
1453-
buffer.append(line_idx + i, label, style);
1454-
}
1445+
}
1446+
for (label, is_primary) in labels.into_iter() {
1447+
let style = if is_primary {
1448+
Style::LabelPrimary
1449+
} else {
1450+
Style::LabelSecondary
1451+
};
1452+
buffer.prepend(line_idx, " |", Style::LineNumber);
1453+
for _ in 0..max_line_num_len {
1454+
buffer.prepend(line_idx, " ", Style::NoStyle);
1455+
}
1456+
line_idx += 1;
1457+
buffer.append(line_idx, " = note: ", style);
1458+
for _ in 0..max_line_num_len {
1459+
buffer.prepend(line_idx, " ", Style::NoStyle);
14551460
}
1461+
buffer.append(line_idx, label, style);
1462+
line_idx += 1;
14561463
}
14571464
}
14581465
}

src/test/ui/closures/closure-expected.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ LL | let y = x.or_else(4);
1010
= note: wrap the `{integer}` in a closure with no arguments: `|| { /* code */ }`
1111
note: required by a bound in `Option::<T>::or_else`
1212
--> $SRC_DIR/core/src/option.rs:LL:COL
13-
$SRC_DIR/core/src/option.rs:LL:COL
14-
$SRC_DIR/core/src/option.rs:LL:COL
15-
$SRC_DIR/core/src/option.rs:LL:COL
1613

1714
error: aborting due to previous error
1815

src/test/ui/closures/closure-move-sync.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ LL | let t = thread::spawn(|| {
1919
| ^^
2020
note: required by a bound in `spawn`
2121
--> $SRC_DIR/std/src/thread/mod.rs:LL:COL
22-
$SRC_DIR/std/src/thread/mod.rs:LL:COL
23-
$SRC_DIR/std/src/thread/mod.rs:LL:COL
24-
$SRC_DIR/std/src/thread/mod.rs:LL:COL
25-
$SRC_DIR/std/src/thread/mod.rs:LL:COL
2622

2723
error[E0277]: `Sender<()>` cannot be shared between threads safely
2824
--> $DIR/closure-move-sync.rs:18:19
@@ -41,10 +37,6 @@ LL | thread::spawn(|| tx.send(()).unwrap());
4137
| ^^
4238
note: required by a bound in `spawn`
4339
--> $SRC_DIR/std/src/thread/mod.rs:LL:COL
44-
$SRC_DIR/std/src/thread/mod.rs:LL:COL
45-
$SRC_DIR/std/src/thread/mod.rs:LL:COL
46-
$SRC_DIR/std/src/thread/mod.rs:LL:COL
47-
$SRC_DIR/std/src/thread/mod.rs:LL:COL
4840

4941
error: aborting due to 2 previous errors
5042

src/test/ui/closures/coerce-unsafe-to-closure.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
1010
= note: unsafe function cannot be called generically without an unsafe block
1111
note: required by a bound in `Option::<T>::map`
1212
--> $SRC_DIR/core/src/option.rs:LL:COL
13-
$SRC_DIR/core/src/option.rs:LL:COL
14-
$SRC_DIR/core/src/option.rs:LL:COL
15-
$SRC_DIR/core/src/option.rs:LL:COL
1613

1714
error: aborting due to previous error
1815

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ LL | match x { }
66
|
77
note: `Option<i32>` defined here
88
--> $SRC_DIR/core/src/option.rs:LL:COL
9-
$SRC_DIR/core/src/option.rs:LL:COL: not covered
10-
$SRC_DIR/core/src/option.rs:LL:COL: not covered
9+
::: $SRC_DIR/core/src/option.rs:LL:COL
10+
|
11+
= note: not covered
12+
::: $SRC_DIR/core/src/option.rs:LL:COL
13+
|
14+
= note: not covered
1115
= note: the matched value is of type `Option<i32>`
1216
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
1317
|

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ 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-
$SRC_DIR/core/src/option.rs:LL:COL: not covered
11+
::: $SRC_DIR/core/src/option.rs:LL:COL
12+
|
13+
= note: not covered
1214
= note: the matched value is of type `Option<i32>`
1315
help: you might want to use `if let` to ignore the variant that isn't matched
1416
|

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

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

1214
error: aborting due to previous error

src/test/ui/expr/malformed_closure/ruby_style_closure.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ LL | | });
2222
= help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>`
2323
note: required by a bound in `Option::<T>::and_then`
2424
--> $SRC_DIR/core/src/option.rs:LL:COL
25-
$SRC_DIR/core/src/option.rs:LL:COL
26-
$SRC_DIR/core/src/option.rs:LL:COL
27-
$SRC_DIR/core/src/option.rs:LL:COL
2825

2926
error: aborting due to 2 previous errors
3027

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ 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-
$SRC_DIR/core/src/result.rs:LL:COL: not covered
11+
::: $SRC_DIR/core/src/result.rs:LL:COL
12+
|
13+
= note: not covered
1214
= note: the matched value is of type `Result<u32, !>`
1315
help: you might want to use `if let` to ignore the variant that isn't matched
1416
|

src/test/ui/inference/issue-71732.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ LL | .get(&"key".into())
1212
where T: ?Sized;
1313
note: required by a bound in `HashMap::<K, V, S>::get`
1414
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
15-
$SRC_DIR/std/src/collections/hash/map.rs:LL:COL
16-
$SRC_DIR/std/src/collections/hash/map.rs:LL:COL
17-
$SRC_DIR/std/src/collections/hash/map.rs:LL:COL
1815
help: consider specifying the generic argument
1916
|
2017
LL | .get::<Q>(&"key".into())

src/test/ui/intrinsics/const-eval-select-bad.stderr

-16
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ LL | const_eval_select((), 42, 0xDEADBEEF);
3737
= note: wrap the `{integer}` in a closure with no arguments: `|| { /* code */ }`
3838
note: required by a bound in `const_eval_select`
3939
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
40-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
41-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
42-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
43-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
4440

4541
error: this argument must be a function item
4642
--> $DIR/const-eval-select-bad.rs:10:31
@@ -63,10 +59,6 @@ LL | const_eval_select((), 42, 0xDEADBEEF);
6359
= note: wrap the `{integer}` in a closure with no arguments: `|| { /* code */ }`
6460
note: required by a bound in `const_eval_select`
6561
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
66-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
67-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
68-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
69-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
7062

7163
error[E0271]: expected `fn(i32) -> bool {bar}` to be a fn item that returns `i32`, but it returns `bool`
7264
--> $DIR/const-eval-select-bad.rs:32:34
@@ -78,10 +70,6 @@ LL | const_eval_select((1,), foo, bar);
7870
|
7971
note: required by a bound in `const_eval_select`
8072
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
81-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
82-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
83-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
84-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
8573

8674
error[E0631]: type mismatch in function arguments
8775
--> $DIR/const-eval-select-bad.rs:37:32
@@ -98,10 +86,6 @@ LL | const_eval_select((true,), foo, baz);
9886
found function signature `fn(i32) -> _`
9987
note: required by a bound in `const_eval_select`
10088
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
101-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
102-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
103-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
104-
$SRC_DIR/core/src/intrinsics.rs:LL:COL
10589

10690
error: this argument must be a `const fn`
10791
--> $DIR/const-eval-select-bad.rs:42:29

src/test/ui/issues/issue-20162.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | b.sort();
66
|
77
note: required by a bound in `slice::<impl [T]>::sort`
88
--> $SRC_DIR/alloc/src/slice.rs:LL:COL
9-
$SRC_DIR/alloc/src/slice.rs:LL:COL
10-
$SRC_DIR/alloc/src/slice.rs:LL:COL
119
help: consider annotating `X` with `#[derive(Ord)]`
1210
|
1311
LL | #[derive(Ord)]

src/test/ui/issues/issue-23966.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ LL | "".chars().fold(|_, _| (), ());
99
= help: the trait `FnMut<(_, char)>` is not implemented for `()`
1010
note: required by a bound in `fold`
1111
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
12-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
13-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
14-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
1512

1613
error: aborting due to previous error
1714

src/test/ui/issues/issue-31173.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ LL | .cloned()
88
found type `u8`
99
note: required by a bound in `cloned`
1010
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
11-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
12-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
13-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
1411

1512
error[E0599]: the method `collect` exists for struct `Cloned<TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>>`, but its trait bounds were not satisfied
1613
--> $DIR/issue-31173.rs:12:10

src/test/ui/issues/issue-33941.stderr

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ LL | for _ in HashMap::new().iter().cloned() {}
88
found tuple `(&_, &_)`
99
note: required by a bound in `cloned`
1010
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
11-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
12-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
13-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
1411

1512
error[E0271]: expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
1613
--> $DIR/issue-33941.rs:6:14

src/test/ui/issues/issue-34334.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_rece
3232
| `Iterator::Item` is `&(_, _, _)` here
3333
note: required by a bound in `collect`
3434
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
35-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
36-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
3735

3836
error: aborting due to 2 previous errors
3937

src/test/ui/issues/issue-66923-show-error-for-correct-call.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ LL | let x2: Vec<f64> = x1.into_iter().collect();
1515
| ^^^^^^^^^^^ `Iterator::Item` is `&f64` here
1616
note: required by a bound in `collect`
1717
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
18-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
19-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
2018

2119
error[E0277]: a value of type `Vec<f64>` cannot be built from an iterator over elements of type `&f64`
2220
--> $DIR/issue-66923-show-error-for-correct-call.rs:12:29
@@ -36,8 +34,6 @@ LL | let x3 = x1.into_iter().collect::<Vec<f64>>();
3634
| ^^^^^^^^^^^ `Iterator::Item` is `&f64` here
3735
note: required by a bound in `collect`
3836
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
39-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
40-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
4137

4238
error: aborting due to 2 previous errors
4339

src/test/ui/iterators/collect-into-array.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ LL | let whatever: [u32; 10] = (0..10).collect();
77
= help: the trait `FromIterator<{integer}>` is not implemented for `[u32; 10]`
88
note: required by a bound in `collect`
99
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
10-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
11-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
1210

1311
error: aborting due to previous error
1412

src/test/ui/iterators/collect-into-slice.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ LL | let some_generated_vec = (0..10).collect();
1717
= help: the trait `Sized` is not implemented for `[i32]`
1818
note: required by a bound in `collect`
1919
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
20-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
21-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
2220

2321
error[E0277]: a slice of type `[i32]` cannot be built since `[i32]` has no definite size
2422
--> $DIR/collect-into-slice.rs:6:38
@@ -29,8 +27,6 @@ LL | let some_generated_vec = (0..10).collect();
2927
= help: the trait `FromIterator<{integer}>` is not implemented for `[i32]`
3028
note: required by a bound in `collect`
3129
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
32-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
33-
$SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
3430

3531
error: aborting due to 3 previous errors
3632

0 commit comments

Comments
 (0)