Skip to content

Commit 879b12e

Browse files
committed
compiletest: Do not require annotations on empty labels and suggestions
1 parent 097cd98 commit 879b12e

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

+168
-450
lines changed

src/tools/compiletest/src/json.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ fn push_actual_errors(
181181
.filter(|(_, span)| Path::new(&span.file_name) == Path::new(&file_name))
182182
.collect();
183183

184-
let spans_in_this_file: Vec<_> = spans_info_in_this_file.iter().map(|(_, span)| span).collect();
185-
186184
let primary_spans: Vec<_> = spans_info_in_this_file
187185
.iter()
188186
.filter(|(is_primary, _)| *is_primary)
@@ -280,7 +278,9 @@ fn push_actual_errors(
280278
line_num: Some(span.line_start + index),
281279
kind: ErrorKind::Suggestion,
282280
msg: line.to_string(),
283-
require_annotation: true,
281+
// Empty suggestions (suggestions to remove something) are common
282+
// and annotating them in source is not useful.
283+
require_annotation: !line.is_empty(),
284284
});
285285
}
286286
}
@@ -294,13 +294,16 @@ fn push_actual_errors(
294294
}
295295

296296
// Add notes for any labels that appear in the message.
297-
for span in spans_in_this_file.iter().filter(|span| span.label.is_some()) {
298-
errors.push(Error {
299-
line_num: Some(span.line_start),
300-
kind: ErrorKind::Note,
301-
msg: span.label.clone().unwrap(),
302-
require_annotation: true,
303-
});
297+
for (_, span) in spans_info_in_this_file {
298+
if let Some(label) = &span.label {
299+
errors.push(Error {
300+
line_num: Some(span.line_start),
301+
kind: ErrorKind::Note,
302+
msg: label.clone(),
303+
// Empty labels (only underlining spans) are common and do not need annotations.
304+
require_annotation: !label.is_empty(),
305+
});
306+
}
304307
}
305308

306309
// Flatten out the children.

tests/incremental/circular-dependencies.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub struct Foo;
1515

1616
pub fn consume_foo(_: Foo) {}
1717
//[cfail2]~^ NOTE function defined here
18-
//[cfail2]~| NOTE
1918

2019
pub fn produce_foo() -> Foo {
2120
Foo

tests/ui/consts/const_in_pattern/reject_non_structural.rs

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ fn main() {
9393
//~| NOTE constant of non-structural type
9494

9595
trait Trait: Sized { const ASSOC: Option<Self>; } //~ NOTE constant defined here
96-
//~^ NOTE
9796
impl Trait for NoDerive { const ASSOC: Option<NoDerive> = Some(NoDerive); }
9897
match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
9998
//~^ ERROR constant of non-structural type `NoDerive` in a pattern

tests/ui/consts/const_in_pattern/reject_non_structural.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ LL | impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
118118
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
119119

120120
error: constant of non-structural type `NoDerive` in a pattern
121-
--> $DIR/reject_non_structural.rs:98:28
121+
--> $DIR/reject_non_structural.rs:97:28
122122
|
123123
LL | struct NoDerive;
124124
| --------------- `NoDerive` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
125125
...
126126
LL | trait Trait: Sized { const ASSOC: Option<Self>; }
127127
| ------------------ ------------------------- constant defined here
128-
...
128+
LL | impl Trait for NoDerive { const ASSOC: Option<NoDerive> = Some(NoDerive); }
129129
LL | match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
130130
| ^^^^^^^^^^^^^^^ constant of non-structural type
131131
|
@@ -136,7 +136,7 @@ LL | impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
136136
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
137137

138138
error: constant of non-structural type `NoDerive` in a pattern
139-
--> $DIR/reject_non_structural.rs:103:28
139+
--> $DIR/reject_non_structural.rs:102:28
140140
|
141141
LL | struct NoDerive;
142142
| --------------- `NoDerive` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
@@ -153,7 +153,7 @@ LL | impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
153153
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
154154

155155
error: constant of non-structural type `NoDerive` in a pattern
156-
--> $DIR/reject_non_structural.rs:108:29
156+
--> $DIR/reject_non_structural.rs:107:29
157157
|
158158
LL | struct NoDerive;
159159
| --------------- `NoDerive` must be annotated with `#[derive(PartialEq)]` to be usable in patterns

tests/ui/fn/param-mismatch-foreign.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
extern "C" {
22
fn foo(x: i32, y: u32, z: i32);
33
//~^ NOTE function defined here
4-
//~| NOTE
54
}
65

76
fn main() {

tests/ui/fn/param-mismatch-foreign.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0061]: this function takes 3 arguments but 2 arguments were supplied
2-
--> $DIR/param-mismatch-foreign.rs:8:5
2+
--> $DIR/param-mismatch-foreign.rs:7:5
33
|
44
LL | foo(1i32, 2i32);
55
| ^^^ ---- argument #2 of type `u32` is missing

tests/ui/fn/signature-error-reporting-under-verbose.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ fn foo(_: i32, _: i32) {}
44

55
fn needs_ptr(_: fn(i32, u32)) {}
66
//~^ NOTE function defined here
7-
//~| NOTE
87

98
fn main() {
109
needs_ptr(foo);

tests/ui/fn/signature-error-reporting-under-verbose.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/signature-error-reporting-under-verbose.rs:10:15
2+
--> $DIR/signature-error-reporting-under-verbose.rs:9:15
33
|
44
LL | needs_ptr(foo);
55
| --------- ^^^ expected fn pointer, found fn item

tests/ui/issues/issue-48131.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// This note is annotated because the purpose of the test
22
// is to ensure that certain other notes are not generated.
3-
#![deny(unused_unsafe)] //~ NOTE
3+
#![deny(unused_unsafe)]
44

55

66
// (test that no note is generated on this unsafe fn)
77
pub unsafe fn a() {
88
fn inner() {
99
unsafe { /* unnecessary */ } //~ ERROR unnecessary `unsafe`
10-
//~^ NOTE
1110
}
1211

1312
inner()
@@ -18,7 +17,6 @@ pub fn b() {
1817
unsafe {
1918
fn inner() {
2019
unsafe { /* unnecessary */ } //~ ERROR unnecessary `unsafe`
21-
//~^ NOTE
2220
}
2321
// `()` is fine to zero-initialize as it is zero sized and inhabited.
2422
let () = ::std::mem::zeroed();

tests/ui/issues/issue-48131.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | #![deny(unused_unsafe)]
1111
| ^^^^^^^^^^^^^
1212

1313
error: unnecessary `unsafe` block
14-
--> $DIR/issue-48131.rs:20:13
14+
--> $DIR/issue-48131.rs:19:13
1515
|
1616
LL | unsafe { /* unnecessary */ }
1717
| ^^^^^^ unnecessary `unsafe` block

tests/ui/mismatched_types/dont-point-return-on-E0308.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
async fn f(_: &()) {}
44
//~^ NOTE function defined here
5-
//~| NOTE
65
// Second note is the span of the underlined argument, I think...
76

87
fn main() {

tests/ui/mismatched_types/dont-point-return-on-E0308.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/dont-point-return-on-E0308.rs:11:11
2+
--> $DIR/dont-point-return-on-E0308.rs:10:11
33
|
44
LL | f(());
55
| - ^^ expected `&()`, found `()`

tests/ui/mismatched_types/similar_paths_primitive.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ struct bool; //~ NOTE the other `bool` is defined in the current crate
44
struct str; //~ NOTE the other `str` is defined in the current crate
55

66
fn foo(_: bool) {} //~ NOTE function defined here
7-
//~^ NOTE
87
fn bar(_: &str) {} //~ NOTE function defined here
9-
//~^ NOTE
8+
109
fn main() {
1110
foo(true);
1211
//~^ ERROR mismatched types [E0308]

tests/ui/mismatched_types/similar_paths_primitive.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/similar_paths_primitive.rs:11:9
2+
--> $DIR/similar_paths_primitive.rs:10:9
33
|
44
LL | foo(true);
55
| --- ^^^^ expected `bool`, found a different `bool`
@@ -20,7 +20,7 @@ LL | fn foo(_: bool) {}
2020
| ^^^ -------
2121

2222
error[E0308]: mismatched types
23-
--> $DIR/similar_paths_primitive.rs:17:9
23+
--> $DIR/similar_paths_primitive.rs:16:9
2424
|
2525
LL | bar("hello");
2626
| --- ^^^^^^^ expected `str`, found a different `str`
@@ -35,7 +35,7 @@ note: the other `str` is defined in the current crate
3535
LL | struct str;
3636
| ^^^^^^^^^^
3737
note: function defined here
38-
--> $DIR/similar_paths_primitive.rs:8:4
38+
--> $DIR/similar_paths_primitive.rs:7:4
3939
|
4040
LL | fn bar(_: &str) {}
4141
| ^^^ -------

tests/ui/numeric/numeric-suffix/numeric-suffix-i32.fixed

-11
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ fn foo<N>(_x: N) {}
1212
//~| NOTE function defined here
1313
//~| NOTE function defined here
1414
//~| NOTE function defined here
15-
//~| NOTE
16-
//~| NOTE
17-
//~| NOTE
18-
//~| NOTE
19-
//~| NOTE
20-
//~| NOTE
21-
//~| NOTE
22-
//~| NOTE
23-
//~| NOTE
24-
//~| NOTE
25-
//~| NOTE
2615

2716
fn main() {
2817
foo::<i32>(42_i32);

tests/ui/numeric/numeric-suffix/numeric-suffix-i32.rs

-11
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ fn foo<N>(_x: N) {}
1212
//~| NOTE function defined here
1313
//~| NOTE function defined here
1414
//~| NOTE function defined here
15-
//~| NOTE
16-
//~| NOTE
17-
//~| NOTE
18-
//~| NOTE
19-
//~| NOTE
20-
//~| NOTE
21-
//~| NOTE
22-
//~| NOTE
23-
//~| NOTE
24-
//~| NOTE
25-
//~| NOTE
2615

2716
fn main() {
2817
foo::<i32>(42_usize);

tests/ui/numeric/numeric-suffix/numeric-suffix-i32.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/numeric-suffix-i32.rs:28:16
2+
--> $DIR/numeric-suffix-i32.rs:17:16
33
|
44
LL | foo::<i32>(42_usize);
55
| ---------- ^^^^^^^^ expected `i32`, found `usize`
@@ -18,7 +18,7 @@ LL + foo::<i32>(42_i32);
1818
|
1919

2020
error[E0308]: mismatched types
21-
--> $DIR/numeric-suffix-i32.rs:32:16
21+
--> $DIR/numeric-suffix-i32.rs:21:16
2222
|
2323
LL | foo::<i32>(42_u64);
2424
| ---------- ^^^^^^ expected `i32`, found `u64`
@@ -37,7 +37,7 @@ LL + foo::<i32>(42_i32);
3737
|
3838

3939
error[E0308]: mismatched types
40-
--> $DIR/numeric-suffix-i32.rs:36:16
40+
--> $DIR/numeric-suffix-i32.rs:25:16
4141
|
4242
LL | foo::<i32>(42_u32);
4343
| ---------- ^^^^^^ expected `i32`, found `u32`
@@ -56,7 +56,7 @@ LL + foo::<i32>(42_i32);
5656
|
5757

5858
error[E0308]: mismatched types
59-
--> $DIR/numeric-suffix-i32.rs:40:16
59+
--> $DIR/numeric-suffix-i32.rs:29:16
6060
|
6161
LL | foo::<i32>(42_u16);
6262
| ---------- ^^^^^^ expected `i32`, found `u16`
@@ -75,7 +75,7 @@ LL + foo::<i32>(42_i32);
7575
|
7676

7777
error[E0308]: mismatched types
78-
--> $DIR/numeric-suffix-i32.rs:44:16
78+
--> $DIR/numeric-suffix-i32.rs:33:16
7979
|
8080
LL | foo::<i32>(42_u8);
8181
| ---------- ^^^^^ expected `i32`, found `u8`
@@ -94,7 +94,7 @@ LL + foo::<i32>(42_i32);
9494
|
9595

9696
error[E0308]: mismatched types
97-
--> $DIR/numeric-suffix-i32.rs:48:16
97+
--> $DIR/numeric-suffix-i32.rs:37:16
9898
|
9999
LL | foo::<i32>(42_isize);
100100
| ---------- ^^^^^^^^ expected `i32`, found `isize`
@@ -113,7 +113,7 @@ LL + foo::<i32>(42_i32);
113113
|
114114

115115
error[E0308]: mismatched types
116-
--> $DIR/numeric-suffix-i32.rs:52:16
116+
--> $DIR/numeric-suffix-i32.rs:41:16
117117
|
118118
LL | foo::<i32>(42_i64);
119119
| ---------- ^^^^^^ expected `i32`, found `i64`
@@ -132,7 +132,7 @@ LL + foo::<i32>(42_i32);
132132
|
133133

134134
error[E0308]: mismatched types
135-
--> $DIR/numeric-suffix-i32.rs:57:16
135+
--> $DIR/numeric-suffix-i32.rs:46:16
136136
|
137137
LL | foo::<i32>(42_i16);
138138
| ---------- ^^^^^^ expected `i32`, found `i16`
@@ -151,7 +151,7 @@ LL + foo::<i32>(42_i32);
151151
|
152152

153153
error[E0308]: mismatched types
154-
--> $DIR/numeric-suffix-i32.rs:61:16
154+
--> $DIR/numeric-suffix-i32.rs:50:16
155155
|
156156
LL | foo::<i32>(42_i8);
157157
| ---------- ^^^^^ expected `i32`, found `i8`
@@ -170,7 +170,7 @@ LL + foo::<i32>(42_i32);
170170
|
171171

172172
error[E0308]: mismatched types
173-
--> $DIR/numeric-suffix-i32.rs:65:16
173+
--> $DIR/numeric-suffix-i32.rs:54:16
174174
|
175175
LL | foo::<i32>(42.0_f64);
176176
| ---------- ^^^^^^^^ expected `i32`, found `f64`
@@ -189,7 +189,7 @@ LL + foo::<i32>(42i32);
189189
|
190190

191191
error[E0308]: mismatched types
192-
--> $DIR/numeric-suffix-i32.rs:69:16
192+
--> $DIR/numeric-suffix-i32.rs:58:16
193193
|
194194
LL | foo::<i32>(42.0_f32);
195195
| ---------- ^^^^^^^^ expected `i32`, found `f32`

tests/ui/numeric/numeric-suffix/numeric-suffix-i64.fixed

-11
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ fn foo<N>(_x: N) {}
1212
//~| NOTE function defined here
1313
//~| NOTE function defined here
1414
//~| NOTE function defined here
15-
//~| NOTE
16-
//~| NOTE
17-
//~| NOTE
18-
//~| NOTE
19-
//~| NOTE
20-
//~| NOTE
21-
//~| NOTE
22-
//~| NOTE
23-
//~| NOTE
24-
//~| NOTE
25-
//~| NOTE
2615

2716
fn main() {
2817
foo::<i64>(42_i64);

tests/ui/numeric/numeric-suffix/numeric-suffix-i64.rs

-11
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ fn foo<N>(_x: N) {}
1212
//~| NOTE function defined here
1313
//~| NOTE function defined here
1414
//~| NOTE function defined here
15-
//~| NOTE
16-
//~| NOTE
17-
//~| NOTE
18-
//~| NOTE
19-
//~| NOTE
20-
//~| NOTE
21-
//~| NOTE
22-
//~| NOTE
23-
//~| NOTE
24-
//~| NOTE
25-
//~| NOTE
2615

2716
fn main() {
2817
foo::<i64>(42_usize);

0 commit comments

Comments
 (0)