Skip to content

compiletest: Do not require annotations on empty labels and suggestions #140616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/tools/compiletest/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ fn push_actual_errors(
.filter(|(_, span)| Path::new(&span.file_name) == Path::new(&file_name))
.collect();

let spans_in_this_file: Vec<_> = spans_info_in_this_file.iter().map(|(_, span)| span).collect();

let primary_spans: Vec<_> = spans_info_in_this_file
.iter()
.filter(|(is_primary, _)| *is_primary)
Expand Down Expand Up @@ -280,7 +278,9 @@ fn push_actual_errors(
line_num: Some(span.line_start + index),
kind: ErrorKind::Suggestion,
msg: line.to_string(),
require_annotation: true,
// Empty suggestions (suggestions to remove something) are common
// and annotating them in source is not useful.
require_annotation: !line.is_empty(),
});
}
}
Expand All @@ -294,13 +294,16 @@ fn push_actual_errors(
}

// Add notes for any labels that appear in the message.
for span in spans_in_this_file.iter().filter(|span| span.label.is_some()) {
errors.push(Error {
line_num: Some(span.line_start),
kind: ErrorKind::Note,
msg: span.label.clone().unwrap(),
require_annotation: true,
});
for (_, span) in spans_info_in_this_file {
if let Some(label) = &span.label {
errors.push(Error {
line_num: Some(span.line_start),
kind: ErrorKind::Note,
msg: label.clone(),
// Empty labels (only underlining spans) are common and do not need annotations.
require_annotation: !label.is_empty(),
});
}
}

// Flatten out the children.
Expand Down
1 change: 0 additions & 1 deletion tests/incremental/circular-dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ pub struct Foo;

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

pub fn produce_foo() -> Foo {
Foo
Expand Down
1 change: 0 additions & 1 deletion tests/ui/consts/const_in_pattern/reject_non_structural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ fn main() {
//~| NOTE constant of non-structural type

trait Trait: Sized { const ASSOC: Option<Self>; } //~ NOTE constant defined here
//~^ NOTE
impl Trait for NoDerive { const ASSOC: Option<NoDerive> = Some(NoDerive); }
match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
//~^ ERROR constant of non-structural type `NoDerive` in a pattern
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/consts/const_in_pattern/reject_non_structural.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ LL | impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

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

error: constant of non-structural type `NoDerive` in a pattern
--> $DIR/reject_non_structural.rs:108:29
--> $DIR/reject_non_structural.rs:107:29
|
LL | struct NoDerive;
| --------------- `NoDerive` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
Expand Down
1 change: 0 additions & 1 deletion tests/ui/fn/param-mismatch-foreign.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
extern "C" {
fn foo(x: i32, y: u32, z: i32);
//~^ NOTE function defined here
//~| NOTE
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fn/param-mismatch-foreign.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0061]: this function takes 3 arguments but 2 arguments were supplied
--> $DIR/param-mismatch-foreign.rs:8:5
--> $DIR/param-mismatch-foreign.rs:7:5
|
LL | foo(1i32, 2i32);
| ^^^ ---- argument #2 of type `u32` is missing
Expand Down
1 change: 0 additions & 1 deletion tests/ui/fn/signature-error-reporting-under-verbose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ fn foo(_: i32, _: i32) {}

fn needs_ptr(_: fn(i32, u32)) {}
//~^ NOTE function defined here
//~| NOTE

fn main() {
needs_ptr(foo);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fn/signature-error-reporting-under-verbose.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/signature-error-reporting-under-verbose.rs:10:15
--> $DIR/signature-error-reporting-under-verbose.rs:9:15
|
LL | needs_ptr(foo);
| --------- ^^^ expected fn pointer, found fn item
Expand Down
4 changes: 1 addition & 3 deletions tests/ui/issues/issue-48131.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// This note is annotated because the purpose of the test
// is to ensure that certain other notes are not generated.
#![deny(unused_unsafe)] //~ NOTE
#![deny(unused_unsafe)]


// (test that no note is generated on this unsafe fn)
pub unsafe fn a() {
fn inner() {
unsafe { /* unnecessary */ } //~ ERROR unnecessary `unsafe`
//~^ NOTE
}

inner()
Expand All @@ -18,7 +17,6 @@ pub fn b() {
unsafe {
fn inner() {
unsafe { /* unnecessary */ } //~ ERROR unnecessary `unsafe`
//~^ NOTE
}
// `()` is fine to zero-initialize as it is zero sized and inhabited.
let () = ::std::mem::zeroed();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-48131.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | #![deny(unused_unsafe)]
| ^^^^^^^^^^^^^

error: unnecessary `unsafe` block
--> $DIR/issue-48131.rs:20:13
--> $DIR/issue-48131.rs:19:13
|
LL | unsafe { /* unnecessary */ }
| ^^^^^^ unnecessary `unsafe` block
Expand Down
1 change: 0 additions & 1 deletion tests/ui/mismatched_types/dont-point-return-on-E0308.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/dont-point-return-on-E0308.rs:11:11
--> $DIR/dont-point-return-on-E0308.rs:10:11
|
LL | f(());
| - ^^ expected `&()`, found `()`
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/mismatched_types/similar_paths_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ struct bool; //~ NOTE the other `bool` is defined in the current crate
struct str; //~ NOTE the other `str` is defined in the current crate

fn foo(_: bool) {} //~ NOTE function defined here
//~^ NOTE
fn bar(_: &str) {} //~ NOTE function defined here
//~^ NOTE

fn main() {
foo(true);
//~^ ERROR mismatched types [E0308]
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/mismatched_types/similar_paths_primitive.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/similar_paths_primitive.rs:11:9
--> $DIR/similar_paths_primitive.rs:10:9
|
LL | foo(true);
| --- ^^^^ expected `bool`, found a different `bool`
Expand All @@ -20,7 +20,7 @@ LL | fn foo(_: bool) {}
| ^^^ -------

error[E0308]: mismatched types
--> $DIR/similar_paths_primitive.rs:17:9
--> $DIR/similar_paths_primitive.rs:16:9
|
LL | bar("hello");
| --- ^^^^^^^ expected `str`, found a different `str`
Expand All @@ -35,7 +35,7 @@ note: the other `str` is defined in the current crate
LL | struct str;
| ^^^^^^^^^^
note: function defined here
--> $DIR/similar_paths_primitive.rs:8:4
--> $DIR/similar_paths_primitive.rs:7:4
|
LL | fn bar(_: &str) {}
| ^^^ -------
Expand Down
11 changes: 0 additions & 11 deletions tests/ui/numeric/numeric-suffix/numeric-suffix-i32.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ fn foo<N>(_x: N) {}
//~| NOTE function defined here
//~| NOTE function defined here
//~| NOTE function defined here
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE

fn main() {
foo::<i32>(42_i32);
Expand Down
11 changes: 0 additions & 11 deletions tests/ui/numeric/numeric-suffix/numeric-suffix-i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ fn foo<N>(_x: N) {}
//~| NOTE function defined here
//~| NOTE function defined here
//~| NOTE function defined here
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE

fn main() {
foo::<i32>(42_usize);
Expand Down
22 changes: 11 additions & 11 deletions tests/ui/numeric/numeric-suffix/numeric-suffix-i32.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/numeric-suffix-i32.rs:28:16
--> $DIR/numeric-suffix-i32.rs:17:16
|
LL | foo::<i32>(42_usize);
| ---------- ^^^^^^^^ expected `i32`, found `usize`
Expand All @@ -18,7 +18,7 @@ LL + foo::<i32>(42_i32);
|

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

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

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

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

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

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

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

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

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

error[E0308]: mismatched types
--> $DIR/numeric-suffix-i32.rs:69:16
--> $DIR/numeric-suffix-i32.rs:58:16
|
LL | foo::<i32>(42.0_f32);
| ---------- ^^^^^^^^ expected `i32`, found `f32`
Expand Down
11 changes: 0 additions & 11 deletions tests/ui/numeric/numeric-suffix/numeric-suffix-i64.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ fn foo<N>(_x: N) {}
//~| NOTE function defined here
//~| NOTE function defined here
//~| NOTE function defined here
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE

fn main() {
foo::<i64>(42_i64);
Expand Down
11 changes: 0 additions & 11 deletions tests/ui/numeric/numeric-suffix/numeric-suffix-i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ fn foo<N>(_x: N) {}
//~| NOTE function defined here
//~| NOTE function defined here
//~| NOTE function defined here
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE
//~| NOTE

fn main() {
foo::<i64>(42_usize);
Expand Down
Loading
Loading