compiletest: Avoid ignoring empty diagnostics in one more place

This catches some silly notes emitted by rustc, which should ideally be fixed
This commit is contained in:
Vadim Petrochenkov 2025-04-07 19:13:16 +03:00
parent 5c160f511e
commit fd854a772e
12 changed files with 27 additions and 18 deletions

View file

@ -810,8 +810,7 @@ impl<'test> TestCx<'test> {
expect_help: bool,
expect_note: bool,
) -> bool {
!actual_error.msg.is_empty()
&& actual_error.require_annotation
actual_error.require_annotation
&& match actual_error.kind {
Some(ErrorKind::Help) => expect_help,
Some(ErrorKind::Note) => expect_note,

View file

@ -15,6 +15,7 @@ pub struct Foo;
pub fn consume_foo(_: Foo) {}
//[cfail2]~^ NOTE function defined here
//[cfail2]~| NOTE
pub fn produce_foo() -> Foo {
Foo

View file

@ -93,6 +93,7 @@ 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

View file

@ -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:97:28
--> $DIR/reject_non_structural.rs:98: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
|
@ -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:102:28
--> $DIR/reject_non_structural.rs:103:28
|
LL | struct NoDerive;
| --------------- `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 } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: constant of non-structural type `NoDerive` in a pattern
--> $DIR/reject_non_structural.rs:107:29
--> $DIR/reject_non_structural.rs:108:29
|
LL | struct NoDerive;
| --------------- `NoDerive` must be annotated with `#[derive(PartialEq)]` to be usable in patterns

View file

@ -1,6 +1,7 @@
extern "C" {
fn foo(x: i32, y: u32, z: i32);
//~^ NOTE function defined here
//~| NOTE
}
fn main() {

View file

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

View file

@ -4,8 +4,9 @@ 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]

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/similar_paths_primitive.rs:10:9
--> $DIR/similar_paths_primitive.rs:11:9
|
LL | foo(true);
| --- ^^^^ expected `bool`, found a different `bool`
@ -20,7 +20,7 @@ LL | fn foo(_: bool) {}
| ^^^ -------
error[E0308]: mismatched types
--> $DIR/similar_paths_primitive.rs:16:9
--> $DIR/similar_paths_primitive.rs:17:9
|
LL | bar("hello");
| --- ^^^^^^^ expected `str`, found a different `str`
@ -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:7:4
--> $DIR/similar_paths_primitive.rs:8:4
|
LL | fn bar(_: &str) {}
| ^^^ -------

View file

@ -9,6 +9,8 @@ fn foo() {
//~| NOTE inside of this loop
//~| HELP consider moving the expression out of the loop
//~| NOTE in this expansion of desugaring of `for` loop
//~| NOTE
//~| NOTE
baz.push(foo);
//~^ NOTE value moved here
//~| HELP consider cloning the value
@ -30,17 +32,19 @@ fn main() {
for foo in foos {
//~^ NOTE this reinitialization might get skipped
//~| NOTE move occurs because `foo` has type `String`
//~| NOTE
for bar in &bars {
//~^ NOTE inside of this loop
//~| HELP consider moving the expression out of the loop
//~| NOTE in this expansion of desugaring of `for` loop
//~| NOTE
if foo == *bar {
baz.push(foo);
//~^ NOTE value moved here
//~| HELP consider cloning the value
continue;
//~^ NOTE verify that your loop breaking logic is correct
//~| NOTE this `continue` advances the loop at line 33
//~| NOTE this `continue` advances the loop at line 36
}
}
qux.push(foo);

View file

@ -1,5 +1,5 @@
error[E0382]: use of moved value: `foo`
--> $DIR/nested-loop-moved-value-wrong-continue.rs:19:14
--> $DIR/nested-loop-moved-value-wrong-continue.rs:21:14
|
LL | for foo in foos { for bar in &bars { if foo == *bar {
| --- ---------------- inside of this loop
@ -14,13 +14,13 @@ LL | qux.push(foo);
| ^^^ value used here after move
|
note: verify that your loop breaking logic is correct
--> $DIR/nested-loop-moved-value-wrong-continue.rs:15:9
--> $DIR/nested-loop-moved-value-wrong-continue.rs:17:9
|
LL | for foo in foos { for bar in &bars { if foo == *bar {
| --------------- ----------------
...
LL | continue;
| ^^^^^^^^ this `continue` advances the loop at $DIR/nested-loop-moved-value-wrong-continue.rs:6:23: 18:8
| ^^^^^^^^ this `continue` advances the loop at $DIR/nested-loop-moved-value-wrong-continue.rs:6:23: 20:8
help: consider moving the expression out of the loop so it is only moved once
|
LL ~ for foo in foos { let mut value = baz.push(foo);
@ -36,7 +36,7 @@ LL | baz.push(foo.clone());
| ++++++++
error[E0382]: use of moved value: `foo`
--> $DIR/nested-loop-moved-value-wrong-continue.rs:46:18
--> $DIR/nested-loop-moved-value-wrong-continue.rs:50:18
|
LL | for foo in foos {
| ---
@ -54,7 +54,7 @@ LL | qux.push(foo);
| ^^^ value used here after move
|
note: verify that your loop breaking logic is correct
--> $DIR/nested-loop-moved-value-wrong-continue.rs:41:17
--> $DIR/nested-loop-moved-value-wrong-continue.rs:45:17
|
LL | for foo in foos {
| ---------------
@ -63,7 +63,7 @@ LL | for bar in &bars {
| ----------------
...
LL | continue;
| ^^^^^^^^ this `continue` advances the loop at line 33
| ^^^^^^^^ this `continue` advances the loop at line 36
help: consider moving the expression out of the loop so it is only moved once
|
LL ~ let mut value = baz.push(foo);

View file

@ -10,5 +10,6 @@ const async const fn test() {}
//~| ERROR functions cannot be both `const` and `async`
//~| NOTE `const` because of this
//~| NOTE `async` because of this
//~| NOTE
fn main() {}

View file

@ -15,5 +15,6 @@ async unsafe const fn test() {}
//~| ERROR functions cannot be both `const` and `async`
//~| NOTE `const` because of this
//~| NOTE `async` because of this
//~| NOTE
fn main() {}