compiletest: Make SUGGESTION annotations viral

This commit is contained in:
Vadim Petrochenkov 2025-04-10 10:34:55 +03:00
parent 2205455d44
commit 0ca31277f3
14 changed files with 58 additions and 42 deletions

View file

@ -306,7 +306,7 @@ impl TestProps {
(ErrorKind::Note, true),
(ErrorKind::Error, true),
(ErrorKind::Warning, true),
(ErrorKind::Suggestion, false),
(ErrorKind::Suggestion, true),
]),
}
}

View file

@ -711,6 +711,7 @@ impl<'test> TestCx<'test> {
let expect_help = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Help));
let expect_note = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Note));
let expect_sugg = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Suggestion));
// Parse the JSON output from the compiler and extract out the messages.
let actual_errors = json::parse_output(&diagnostic_file_name, &proc_res.stderr, proc_res);
@ -737,8 +738,12 @@ impl<'test> TestCx<'test> {
None => {
// If the test is a known bug, don't require that the error is annotated
if self.is_unexpected_compiler_message(&actual_error, expect_help, expect_note)
{
if self.is_unexpected_compiler_message(
&actual_error,
expect_help,
expect_note,
expect_sugg,
) {
self.error(&format!(
"{}:{}: unexpected {}: '{}'",
file_name,
@ -802,6 +807,7 @@ impl<'test> TestCx<'test> {
actual_error: &Error,
expect_help: bool,
expect_note: bool,
expect_sugg: bool,
) -> bool {
actual_error.require_annotation
&& actual_error.kind.map_or(false, |err_kind| {
@ -811,6 +817,7 @@ impl<'test> TestCx<'test> {
match err_kind {
ErrorKind::Help => expect_help && default_require_annotations,
ErrorKind::Note => expect_note && default_require_annotations,
ErrorKind::Suggestion => expect_sugg && default_require_annotations,
_ => default_require_annotations,
}
})

View file

@ -1,4 +1,5 @@
//@ edition:2018
//@ dont-require-annotations:SUGGESTION
fn take_u32(_x: u32) {}

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:12:14
--> $DIR/suggest-missing-await.rs:13:14
|
LL | take_u32(x)
| -------- ^ expected `u32`, found future
@ -7,12 +7,12 @@ LL | take_u32(x)
| arguments to this function are incorrect
|
note: calling an async function returns a future
--> $DIR/suggest-missing-await.rs:12:14
--> $DIR/suggest-missing-await.rs:13:14
|
LL | take_u32(x)
| ^
note: function defined here
--> $DIR/suggest-missing-await.rs:3:4
--> $DIR/suggest-missing-await.rs:4:4
|
LL | fn take_u32(_x: u32) {}
| ^^^^^^^^ -------
@ -22,13 +22,13 @@ LL | take_u32(x.await)
| ++++++
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:22:5
--> $DIR/suggest-missing-await.rs:23:5
|
LL | dummy()
| ^^^^^^^ expected `()`, found future
|
note: calling an async function returns a future
--> $DIR/suggest-missing-await.rs:22:5
--> $DIR/suggest-missing-await.rs:23:5
|
LL | dummy()
| ^^^^^^^
@ -42,7 +42,7 @@ LL | dummy();
| +
error[E0308]: `if` and `else` have incompatible types
--> $DIR/suggest-missing-await.rs:35:9
--> $DIR/suggest-missing-await.rs:36:9
|
LL | let _x = if true {
| ______________-
@ -64,7 +64,7 @@ LL | dummy().await
| ++++++
error[E0308]: `match` arms have incompatible types
--> $DIR/suggest-missing-await.rs:45:14
--> $DIR/suggest-missing-await.rs:46:14
|
LL | let _x = match 0usize {
| ______________-
@ -87,7 +87,7 @@ LL ~ 1 => dummy().await,
|
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:53:9
--> $DIR/suggest-missing-await.rs:54:9
|
LL | let _x = match dummy() {
| ------- this expression has type `impl Future<Output = ()>`
@ -102,7 +102,7 @@ LL | let _x = match dummy().await {
| ++++++
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:67:9
--> $DIR/suggest-missing-await.rs:68:9
|
LL | match dummy_result() {
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
@ -118,7 +118,7 @@ LL | match dummy_result().await {
| ++++++
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:69:9
--> $DIR/suggest-missing-await.rs:70:9
|
LL | match dummy_result() {
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
@ -134,7 +134,7 @@ LL | match dummy_result().await {
| ++++++
error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:77:27
--> $DIR/suggest-missing-await.rs:78:27
|
LL | Some(do_async()).map(|()| {});
| ^^

View file

@ -1,3 +1,5 @@
//@ dont-require-annotations:SUGGESTION
fn main() {
let u = 5 as bool; //~ ERROR cannot cast `i32` as `bool`
//~| HELP compare with zero instead

View file

@ -1,5 +1,5 @@
error[E0054]: cannot cast `i32` as `bool`
--> $DIR/cast-as-bool.rs:2:13
--> $DIR/cast-as-bool.rs:4:13
|
LL | let u = 5 as bool;
| ^^^^^^^^^
@ -11,7 +11,7 @@ LL + let u = 5 != 0;
|
error[E0054]: cannot cast `i32` as `bool`
--> $DIR/cast-as-bool.rs:6:13
--> $DIR/cast-as-bool.rs:8:13
|
LL | let t = (1 + 2) as bool;
| ^^^^^^^^^^^^^^^
@ -23,7 +23,7 @@ LL + let t = (1 + 2) != 0;
|
error[E0054]: cannot cast `u32` as `bool`
--> $DIR/cast-as-bool.rs:10:13
--> $DIR/cast-as-bool.rs:12:13
|
LL | let _ = 5_u32 as bool;
| ^^^^^^^^^^^^^
@ -35,7 +35,7 @@ LL + let _ = 5_u32 != 0;
|
error[E0054]: cannot cast `f64` as `bool`
--> $DIR/cast-as-bool.rs:13:13
--> $DIR/cast-as-bool.rs:15:13
|
LL | let _ = 64.0_f64 as bool;
| ^^^^^^^^^^^^^^^^
@ -47,43 +47,43 @@ LL + let _ = 64.0_f64 != 0;
|
error[E0054]: cannot cast `IntEnum` as `bool`
--> $DIR/cast-as-bool.rs:24:13
--> $DIR/cast-as-bool.rs:26:13
|
LL | let _ = IntEnum::One as bool;
| ^^^^^^^^^^^^^^^^^^^^ unsupported cast
error[E0054]: cannot cast `fn(u8) -> String {uwu}` as `bool`
--> $DIR/cast-as-bool.rs:33:13
--> $DIR/cast-as-bool.rs:35:13
|
LL | let _ = uwu as bool;
| ^^^^^^^^^^^ unsupported cast
error[E0054]: cannot cast `unsafe fn() {owo}` as `bool`
--> $DIR/cast-as-bool.rs:35:13
--> $DIR/cast-as-bool.rs:37:13
|
LL | let _ = owo as bool;
| ^^^^^^^^^^^ unsupported cast
error[E0054]: cannot cast `fn(u8) -> String` as `bool`
--> $DIR/cast-as-bool.rs:38:13
--> $DIR/cast-as-bool.rs:40:13
|
LL | let _ = uwu as fn(u8) -> String as bool;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported cast
error[E0054]: cannot cast `char` as `bool`
--> $DIR/cast-as-bool.rs:40:13
--> $DIR/cast-as-bool.rs:42:13
|
LL | let _ = 'x' as bool;
| ^^^^^^^^^^^ unsupported cast
error[E0054]: cannot cast `*const ()` as `bool`
--> $DIR/cast-as-bool.rs:44:13
--> $DIR/cast-as-bool.rs:46:13
|
LL | let _ = ptr as bool;
| ^^^^^^^^^^^ unsupported cast
error[E0606]: casting `&'static str` as `bool` is invalid
--> $DIR/cast-as-bool.rs:46:13
--> $DIR/cast-as-bool.rs:48:13
|
LL | let v = "hello" as bool;
| ^^^^^^^^^^^^^^^

View file

@ -19,6 +19,7 @@ fn fn_mut() -> _ {
let x = String::new();
//~^ HELP: consider changing this to be mutable
//~| NOTE binding `x` declared here
//~| SUGGESTION mut
|c| { //~ NOTE: value captured here
x.push(c);
//~^ ERROR: does not live long enough

View file

@ -21,7 +21,7 @@ LL | fn fn_mut() -> _ {
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/suggest-return-closure.rs:32:13
--> $DIR/suggest-return-closure.rs:33:13
|
LL | fn fun() -> _ {
| ^
@ -32,7 +32,7 @@ LL | fn fun() -> _ {
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/suggest-return-closure.rs:23:9
--> $DIR/suggest-return-closure.rs:24:9
|
LL | x.push(c);
| ^ cannot borrow as mutable
@ -43,7 +43,7 @@ LL | let mut x = String::new();
| +++
error[E0597]: `x` does not live long enough
--> $DIR/suggest-return-closure.rs:23:9
--> $DIR/suggest-return-closure.rs:24:9
|
LL | let x = String::new();
| - binding `x` declared here

View file

@ -1,3 +1,5 @@
//@ dont-require-annotations:SUGGESTION
struct S;
impl S {

View file

@ -1,5 +1,5 @@
error: expected one of `:`, `@`, or `|`, found `bar`
--> $DIR/inverted-parameters.rs:4:24
--> $DIR/inverted-parameters.rs:6:24
|
LL | fn foo(&self, &str bar) {}
| -----^^^
@ -8,7 +8,7 @@ LL | fn foo(&self, &str bar) {}
| help: declare the type after the parameter binding: `<identifier>: <type>`
error: expected one of `:`, `@`, or `|`, found `quux`
--> $DIR/inverted-parameters.rs:10:10
--> $DIR/inverted-parameters.rs:12:10
|
LL | fn baz(S quux, xyzzy: i32) {}
| --^^^^
@ -17,19 +17,19 @@ LL | fn baz(S quux, xyzzy: i32) {}
| help: declare the type after the parameter binding: `<identifier>: <type>`
error: expected one of `:`, `@`, or `|`, found `a`
--> $DIR/inverted-parameters.rs:15:12
--> $DIR/inverted-parameters.rs:17:12
|
LL | fn one(i32 a b) {}
| ^ expected one of `:`, `@`, or `|`
error: expected one of `:` or `|`, found `(`
--> $DIR/inverted-parameters.rs:18:23
--> $DIR/inverted-parameters.rs:20:23
|
LL | fn pattern((i32, i32) (a, b)) {}
| ^ expected one of `:` or `|`
error: expected one of `:`, `@`, or `|`, found `)`
--> $DIR/inverted-parameters.rs:21:12
--> $DIR/inverted-parameters.rs:23:12
|
LL | fn fizz(i32) {}
| ^ expected one of `:`, `@`, or `|`
@ -49,7 +49,7 @@ LL | fn fizz(_: i32) {}
| ++
error: expected one of `:`, `@`, or `|`, found `S`
--> $DIR/inverted-parameters.rs:27:23
--> $DIR/inverted-parameters.rs:29:23
|
LL | fn missing_colon(quux S) {}
| -----^

View file

@ -1,3 +1,5 @@
//@ dont-require-annotations:SUGGESTION
struct X(usize);
impl X {

View file

@ -1,5 +1,5 @@
error[E0594]: cannot assign to `self.0`, which is behind a `&` reference
--> $DIR/suggest-ref-mut.rs:7:9
--> $DIR/suggest-ref-mut.rs:9:9
|
LL | self.0 = 32;
| ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
@ -10,7 +10,7 @@ LL | fn zap(&mut self) {
| +++
error[E0594]: cannot assign to `*foo`, which is behind a `&` reference
--> $DIR/suggest-ref-mut.rs:15:5
--> $DIR/suggest-ref-mut.rs:17:5
|
LL | *foo = 32;
| ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written
@ -21,7 +21,7 @@ LL | let ref mut foo = 16;
| +++
error[E0594]: cannot assign to `*bar`, which is behind a `&` reference
--> $DIR/suggest-ref-mut.rs:19:9
--> $DIR/suggest-ref-mut.rs:21:9
|
LL | *bar = 32;
| ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written
@ -32,7 +32,7 @@ LL | if let Some(ref mut bar) = Some(16) {
| +++
error[E0594]: cannot assign to `*quo`, which is behind a `&` reference
--> $DIR/suggest-ref-mut.rs:23:22
--> $DIR/suggest-ref-mut.rs:25:22
|
LL | ref quo => { *quo = 32; },
| ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written

View file

@ -1,4 +1,5 @@
//@ edition:2018
//@ dont-require-annotations:SUGGESTION
async fn hello() { //~ HELP try adding a return type
0

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/issue-90027-async-fn-return-suggestion.rs:4:5
--> $DIR/issue-90027-async-fn-return-suggestion.rs:5:5
|
LL | async fn hello() {
| - help: try adding a return type: `-> i32`
@ -7,7 +7,7 @@ LL | 0
| ^ expected `()`, found integer
error[E0308]: mismatched types
--> $DIR/issue-90027-async-fn-return-suggestion.rs:9:5
--> $DIR/issue-90027-async-fn-return-suggestion.rs:10:5
|
LL | async fn world() -> () {
| -- expected `()` because of return type
@ -15,13 +15,13 @@ LL | 0
| ^ expected `()`, found integer
error[E0308]: mismatched types
--> $DIR/issue-90027-async-fn-return-suggestion.rs:14:5
--> $DIR/issue-90027-async-fn-return-suggestion.rs:15:5
|
LL | hello()
| ^^^^^^^ expected `()`, found future
|
note: calling an async function returns a future
--> $DIR/issue-90027-async-fn-return-suggestion.rs:14:5
--> $DIR/issue-90027-async-fn-return-suggestion.rs:15:5
|
LL | hello()
| ^^^^^^^