Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

Lines changed: 13 additions & 10 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)