Skip to content

Commit 07b9549

Browse files
committed
compiletest: Make SUGGESTION annotations viral
1 parent 69b3959 commit 07b9549

14 files changed

+58
-42
lines changed

src/tools/compiletest/src/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl TestProps {
306306
(ErrorKind::Note, true),
307307
(ErrorKind::Error, true),
308308
(ErrorKind::Warning, true),
309-
(ErrorKind::Suggestion, false),
309+
(ErrorKind::Suggestion, true),
310310
]),
311311
}
312312
}

src/tools/compiletest/src/runtest.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ impl<'test> TestCx<'test> {
711711

712712
let expect_help = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Help));
713713
let expect_note = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Note));
714+
let expect_sugg = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Suggestion));
714715

715716
// Parse the JSON output from the compiler and extract out the messages.
716717
let actual_errors = json::parse_output(&diagnostic_file_name, &proc_res.stderr, proc_res);
@@ -737,8 +738,12 @@ impl<'test> TestCx<'test> {
737738

738739
None => {
739740
// If the test is a known bug, don't require that the error is annotated
740-
if self.is_unexpected_compiler_message(&actual_error, expect_help, expect_note)
741-
{
741+
if self.is_unexpected_compiler_message(
742+
&actual_error,
743+
expect_help,
744+
expect_note,
745+
expect_sugg,
746+
) {
742747
self.error(&format!(
743748
"{}:{}: unexpected {}: '{}'",
744749
file_name,
@@ -802,6 +807,7 @@ impl<'test> TestCx<'test> {
802807
actual_error: &Error,
803808
expect_help: bool,
804809
expect_note: bool,
810+
expect_sugg: bool,
805811
) -> bool {
806812
actual_error.require_annotation
807813
&& actual_error.kind.map_or(false, |err_kind| {
@@ -811,6 +817,7 @@ impl<'test> TestCx<'test> {
811817
match err_kind {
812818
ErrorKind::Help => expect_help && default_require_annotations,
813819
ErrorKind::Note => expect_note && default_require_annotations,
820+
ErrorKind::Suggestion => expect_sugg && default_require_annotations,
814821
_ => default_require_annotations,
815822
}
816823
})

tests/ui/async-await/suggest-missing-await.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ edition:2018
2+
//@ dont-require-annotations:SUGGESTION
23

34
fn take_u32(_x: u32) {}
45

tests/ui/async-await/suggest-missing-await.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error[E0308]: mismatched types
2-
--> $DIR/suggest-missing-await.rs:12:14
2+
--> $DIR/suggest-missing-await.rs:13:14
33
|
44
LL | take_u32(x)
55
| -------- ^ expected `u32`, found future
66
| |
77
| arguments to this function are incorrect
88
|
99
note: calling an async function returns a future
10-
--> $DIR/suggest-missing-await.rs:12:14
10+
--> $DIR/suggest-missing-await.rs:13:14
1111
|
1212
LL | take_u32(x)
1313
| ^
1414
note: function defined here
15-
--> $DIR/suggest-missing-await.rs:3:4
15+
--> $DIR/suggest-missing-await.rs:4:4
1616
|
1717
LL | fn take_u32(_x: u32) {}
1818
| ^^^^^^^^ -------
@@ -22,13 +22,13 @@ LL | take_u32(x.await)
2222
| ++++++
2323

2424
error[E0308]: mismatched types
25-
--> $DIR/suggest-missing-await.rs:22:5
25+
--> $DIR/suggest-missing-await.rs:23:5
2626
|
2727
LL | dummy()
2828
| ^^^^^^^ expected `()`, found future
2929
|
3030
note: calling an async function returns a future
31-
--> $DIR/suggest-missing-await.rs:22:5
31+
--> $DIR/suggest-missing-await.rs:23:5
3232
|
3333
LL | dummy()
3434
| ^^^^^^^
@@ -42,7 +42,7 @@ LL | dummy();
4242
| +
4343

4444
error[E0308]: `if` and `else` have incompatible types
45-
--> $DIR/suggest-missing-await.rs:35:9
45+
--> $DIR/suggest-missing-await.rs:36:9
4646
|
4747
LL | let _x = if true {
4848
| ______________-
@@ -64,7 +64,7 @@ LL | dummy().await
6464
| ++++++
6565

6666
error[E0308]: `match` arms have incompatible types
67-
--> $DIR/suggest-missing-await.rs:45:14
67+
--> $DIR/suggest-missing-await.rs:46:14
6868
|
6969
LL | let _x = match 0usize {
7070
| ______________-
@@ -87,7 +87,7 @@ LL ~ 1 => dummy().await,
8787
|
8888

8989
error[E0308]: mismatched types
90-
--> $DIR/suggest-missing-await.rs:53:9
90+
--> $DIR/suggest-missing-await.rs:54:9
9191
|
9292
LL | let _x = match dummy() {
9393
| ------- this expression has type `impl Future<Output = ()>`
@@ -102,7 +102,7 @@ LL | let _x = match dummy().await {
102102
| ++++++
103103

104104
error[E0308]: mismatched types
105-
--> $DIR/suggest-missing-await.rs:67:9
105+
--> $DIR/suggest-missing-await.rs:68:9
106106
|
107107
LL | match dummy_result() {
108108
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
@@ -118,7 +118,7 @@ LL | match dummy_result().await {
118118
| ++++++
119119

120120
error[E0308]: mismatched types
121-
--> $DIR/suggest-missing-await.rs:69:9
121+
--> $DIR/suggest-missing-await.rs:70:9
122122
|
123123
LL | match dummy_result() {
124124
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
@@ -134,7 +134,7 @@ LL | match dummy_result().await {
134134
| ++++++
135135

136136
error[E0308]: mismatched types
137-
--> $DIR/suggest-missing-await.rs:77:27
137+
--> $DIR/suggest-missing-await.rs:78:27
138138
|
139139
LL | Some(do_async()).map(|()| {});
140140
| ^^

tests/ui/cast/cast-as-bool.rs

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

tests/ui/cast/cast-as-bool.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0054]: cannot cast `i32` as `bool`
2-
--> $DIR/cast-as-bool.rs:2:13
2+
--> $DIR/cast-as-bool.rs:4:13
33
|
44
LL | let u = 5 as bool;
55
| ^^^^^^^^^
@@ -11,7 +11,7 @@ LL + let u = 5 != 0;
1111
|
1212

1313
error[E0054]: cannot cast `i32` as `bool`
14-
--> $DIR/cast-as-bool.rs:6:13
14+
--> $DIR/cast-as-bool.rs:8:13
1515
|
1616
LL | let t = (1 + 2) as bool;
1717
| ^^^^^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL + let t = (1 + 2) != 0;
2323
|
2424

2525
error[E0054]: cannot cast `u32` as `bool`
26-
--> $DIR/cast-as-bool.rs:10:13
26+
--> $DIR/cast-as-bool.rs:12:13
2727
|
2828
LL | let _ = 5_u32 as bool;
2929
| ^^^^^^^^^^^^^
@@ -35,7 +35,7 @@ LL + let _ = 5_u32 != 0;
3535
|
3636

3737
error[E0054]: cannot cast `f64` as `bool`
38-
--> $DIR/cast-as-bool.rs:13:13
38+
--> $DIR/cast-as-bool.rs:15:13
3939
|
4040
LL | let _ = 64.0_f64 as bool;
4141
| ^^^^^^^^^^^^^^^^
@@ -47,43 +47,43 @@ LL + let _ = 64.0_f64 != 0;
4747
|
4848

4949
error[E0054]: cannot cast `IntEnum` as `bool`
50-
--> $DIR/cast-as-bool.rs:24:13
50+
--> $DIR/cast-as-bool.rs:26:13
5151
|
5252
LL | let _ = IntEnum::One as bool;
5353
| ^^^^^^^^^^^^^^^^^^^^ unsupported cast
5454

5555
error[E0054]: cannot cast `fn(u8) -> String {uwu}` as `bool`
56-
--> $DIR/cast-as-bool.rs:33:13
56+
--> $DIR/cast-as-bool.rs:35:13
5757
|
5858
LL | let _ = uwu as bool;
5959
| ^^^^^^^^^^^ unsupported cast
6060

6161
error[E0054]: cannot cast `unsafe fn() {owo}` as `bool`
62-
--> $DIR/cast-as-bool.rs:35:13
62+
--> $DIR/cast-as-bool.rs:37:13
6363
|
6464
LL | let _ = owo as bool;
6565
| ^^^^^^^^^^^ unsupported cast
6666

6767
error[E0054]: cannot cast `fn(u8) -> String` as `bool`
68-
--> $DIR/cast-as-bool.rs:38:13
68+
--> $DIR/cast-as-bool.rs:40:13
6969
|
7070
LL | let _ = uwu as fn(u8) -> String as bool;
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported cast
7272

7373
error[E0054]: cannot cast `char` as `bool`
74-
--> $DIR/cast-as-bool.rs:40:13
74+
--> $DIR/cast-as-bool.rs:42:13
7575
|
7676
LL | let _ = 'x' as bool;
7777
| ^^^^^^^^^^^ unsupported cast
7878

7979
error[E0054]: cannot cast `*const ()` as `bool`
80-
--> $DIR/cast-as-bool.rs:44:13
80+
--> $DIR/cast-as-bool.rs:46:13
8181
|
8282
LL | let _ = ptr as bool;
8383
| ^^^^^^^^^^^ unsupported cast
8484

8585
error[E0606]: casting `&'static str` as `bool` is invalid
86-
--> $DIR/cast-as-bool.rs:46:13
86+
--> $DIR/cast-as-bool.rs:48:13
8787
|
8888
LL | let v = "hello" as bool;
8989
| ^^^^^^^^^^^^^^^

tests/ui/fn/suggest-return-closure.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn fn_mut() -> _ {
1919
let x = String::new();
2020
//~^ HELP: consider changing this to be mutable
2121
//~| NOTE binding `x` declared here
22+
//~| SUGGESTION mut
2223
|c| { //~ NOTE: value captured here
2324
x.push(c);
2425
//~^ ERROR: does not live long enough

tests/ui/fn/suggest-return-closure.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LL | fn fn_mut() -> _ {
2121
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
2222

2323
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
24-
--> $DIR/suggest-return-closure.rs:32:13
24+
--> $DIR/suggest-return-closure.rs:33:13
2525
|
2626
LL | fn fun() -> _ {
2727
| ^
@@ -32,7 +32,7 @@ LL | fn fun() -> _ {
3232
= note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html
3333

3434
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
35-
--> $DIR/suggest-return-closure.rs:23:9
35+
--> $DIR/suggest-return-closure.rs:24:9
3636
|
3737
LL | x.push(c);
3838
| ^ cannot borrow as mutable
@@ -43,7 +43,7 @@ LL | let mut x = String::new();
4343
| +++
4444

4545
error[E0597]: `x` does not live long enough
46-
--> $DIR/suggest-return-closure.rs:23:9
46+
--> $DIR/suggest-return-closure.rs:24:9
4747
|
4848
LL | let x = String::new();
4949
| - binding `x` declared here

tests/ui/parser/inverted-parameters.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ dont-require-annotations:SUGGESTION
2+
13
struct S;
24

35
impl S {

tests/ui/parser/inverted-parameters.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected one of `:`, `@`, or `|`, found `bar`
2-
--> $DIR/inverted-parameters.rs:4:24
2+
--> $DIR/inverted-parameters.rs:6:24
33
|
44
LL | fn foo(&self, &str bar) {}
55
| -----^^^
@@ -8,7 +8,7 @@ LL | fn foo(&self, &str bar) {}
88
| help: declare the type after the parameter binding: `<identifier>: <type>`
99

1010
error: expected one of `:`, `@`, or `|`, found `quux`
11-
--> $DIR/inverted-parameters.rs:10:10
11+
--> $DIR/inverted-parameters.rs:12:10
1212
|
1313
LL | fn baz(S quux, xyzzy: i32) {}
1414
| --^^^^
@@ -17,19 +17,19 @@ LL | fn baz(S quux, xyzzy: i32) {}
1717
| help: declare the type after the parameter binding: `<identifier>: <type>`
1818

1919
error: expected one of `:`, `@`, or `|`, found `a`
20-
--> $DIR/inverted-parameters.rs:15:12
20+
--> $DIR/inverted-parameters.rs:17:12
2121
|
2222
LL | fn one(i32 a b) {}
2323
| ^ expected one of `:`, `@`, or `|`
2424

2525
error: expected one of `:` or `|`, found `(`
26-
--> $DIR/inverted-parameters.rs:18:23
26+
--> $DIR/inverted-parameters.rs:20:23
2727
|
2828
LL | fn pattern((i32, i32) (a, b)) {}
2929
| ^ expected one of `:` or `|`
3030

3131
error: expected one of `:`, `@`, or `|`, found `)`
32-
--> $DIR/inverted-parameters.rs:21:12
32+
--> $DIR/inverted-parameters.rs:23:12
3333
|
3434
LL | fn fizz(i32) {}
3535
| ^ expected one of `:`, `@`, or `|`
@@ -49,7 +49,7 @@ LL | fn fizz(_: i32) {}
4949
| ++
5050

5151
error: expected one of `:`, `@`, or `|`, found `S`
52-
--> $DIR/inverted-parameters.rs:27:23
52+
--> $DIR/inverted-parameters.rs:29:23
5353
|
5454
LL | fn missing_colon(quux S) {}
5555
| -----^

tests/ui/suggestions/suggest-ref-mut.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ dont-require-annotations:SUGGESTION
2+
13
struct X(usize);
24

35
impl X {

tests/ui/suggestions/suggest-ref-mut.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0594]: cannot assign to `self.0`, which is behind a `&` reference
2-
--> $DIR/suggest-ref-mut.rs:7:9
2+
--> $DIR/suggest-ref-mut.rs:9:9
33
|
44
LL | self.0 = 32;
55
| ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
@@ -10,7 +10,7 @@ LL | fn zap(&mut self) {
1010
| +++
1111

1212
error[E0594]: cannot assign to `*foo`, which is behind a `&` reference
13-
--> $DIR/suggest-ref-mut.rs:15:5
13+
--> $DIR/suggest-ref-mut.rs:17:5
1414
|
1515
LL | *foo = 32;
1616
| ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written
@@ -21,7 +21,7 @@ LL | let ref mut foo = 16;
2121
| +++
2222

2323
error[E0594]: cannot assign to `*bar`, which is behind a `&` reference
24-
--> $DIR/suggest-ref-mut.rs:19:9
24+
--> $DIR/suggest-ref-mut.rs:21:9
2525
|
2626
LL | *bar = 32;
2727
| ^^^^^^^^^ `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) {
3232
| +++
3333

3434
error[E0594]: cannot assign to `*quo`, which is behind a `&` reference
35-
--> $DIR/suggest-ref-mut.rs:23:22
35+
--> $DIR/suggest-ref-mut.rs:25:22
3636
|
3737
LL | ref quo => { *quo = 32; },
3838
| ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written

tests/ui/typeck/issue-90027-async-fn-return-suggestion.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ edition:2018
2+
//@ dont-require-annotations:SUGGESTION
23

34
async fn hello() { //~ HELP try adding a return type
45
0

0 commit comments

Comments
 (0)