2019-06-19 15:55:18 -05:00
|
|
|
error[E0308]: mismatched types
|
2020-10-22 21:03:36 -05:00
|
|
|
--> $DIR/suggest-missing-await.rs:12:14
|
2019-06-19 15:55:18 -05:00
|
|
|
|
|
|
|
|
LL | take_u32(x)
|
2023-02-10 12:03:54 -06:00
|
|
|
| -------- ^ expected `u32`, found future
|
Implementation for 65853
This attempts to bring better error messages to invalid method calls, by applying some heuristics to identify common mistakes.
The algorithm is inspired by Levenshtein distance and longest common sub-sequence. In essence, we treat the types of the function, and the types of the arguments you provided as two "words" and compute the edits to get from one to the other.
We then modify that algorithm to detect 4 cases:
- A function input is missing
- An extra argument was provided
- The type of an argument is straight up invalid
- Two arguments have been swapped
- A subset of the arguments have been shuffled
(We detect the last two as separate cases so that we can detect two swaps, instead of 4 parameters permuted.)
It helps to understand this argument by paying special attention to terminology: "inputs" refers to the inputs being *expected* by the function, and "arguments" refers to what has been provided at the call site.
The basic sketch of the algorithm is as follows:
- Construct a boolean grid, with a row for each argument, and a column for each input. The cell [i, j] is true if the i'th argument could satisfy the j'th input.
- If we find an argument that could satisfy no inputs, provided for an input that can't be satisfied by any other argument, we consider this an "invalid type".
- Extra arguments are those that can't satisfy any input, provided for an input that *could* be satisfied by another argument.
- Missing inputs are inputs that can't be satisfied by any argument, where the provided argument could satisfy another input
- Swapped / Permuted arguments are identified with a cycle detection algorithm.
As each issue is found, we remove the relevant inputs / arguments and check for more issues. If we find no issues, we match up any "valid" arguments, and start again.
Note that there's a lot of extra complexity:
- We try to stay efficient on the happy path, only computing the diagonal until we find a problem, and then filling in the rest of the matrix.
- Closure arguments are wrapped in a tuple and need to be unwrapped
- We need to resolve closure types after the rest, to allow the most specific type constraints
- We need to handle imported C functions that might be variadic in their inputs.
I tried to document a lot of this in comments in the code and keep the naming clear.
2022-01-21 22:50:54 -06:00
|
|
|
| |
|
|
|
|
| arguments to this function are incorrect
|
2019-06-19 15:55:18 -05:00
|
|
|
|
|
2023-02-10 12:03:54 -06:00
|
|
|
note: calling an async function returns a future
|
|
|
|
--> $DIR/suggest-missing-await.rs:12:14
|
|
|
|
|
|
|
|
|
LL | take_u32(x)
|
|
|
|
| ^
|
Implementation for 65853
This attempts to bring better error messages to invalid method calls, by applying some heuristics to identify common mistakes.
The algorithm is inspired by Levenshtein distance and longest common sub-sequence. In essence, we treat the types of the function, and the types of the arguments you provided as two "words" and compute the edits to get from one to the other.
We then modify that algorithm to detect 4 cases:
- A function input is missing
- An extra argument was provided
- The type of an argument is straight up invalid
- Two arguments have been swapped
- A subset of the arguments have been shuffled
(We detect the last two as separate cases so that we can detect two swaps, instead of 4 parameters permuted.)
It helps to understand this argument by paying special attention to terminology: "inputs" refers to the inputs being *expected* by the function, and "arguments" refers to what has been provided at the call site.
The basic sketch of the algorithm is as follows:
- Construct a boolean grid, with a row for each argument, and a column for each input. The cell [i, j] is true if the i'th argument could satisfy the j'th input.
- If we find an argument that could satisfy no inputs, provided for an input that can't be satisfied by any other argument, we consider this an "invalid type".
- Extra arguments are those that can't satisfy any input, provided for an input that *could* be satisfied by another argument.
- Missing inputs are inputs that can't be satisfied by any argument, where the provided argument could satisfy another input
- Swapped / Permuted arguments are identified with a cycle detection algorithm.
As each issue is found, we remove the relevant inputs / arguments and check for more issues. If we find no issues, we match up any "valid" arguments, and start again.
Note that there's a lot of extra complexity:
- We try to stay efficient on the happy path, only computing the diagonal until we find a problem, and then filling in the rest of the matrix.
- Closure arguments are wrapped in a tuple and need to be unwrapped
- We need to resolve closure types after the rest, to allow the most specific type constraints
- We need to handle imported C functions that might be variadic in their inputs.
I tried to document a lot of this in comments in the code and keep the naming clear.
2022-01-21 22:50:54 -06:00
|
|
|
note: function defined here
|
|
|
|
--> $DIR/suggest-missing-await.rs:3:4
|
|
|
|
|
|
|
|
|
LL | fn take_u32(_x: u32) {}
|
|
|
|
| ^^^^^^^^ -------
|
2020-10-21 16:25:09 -05:00
|
|
|
help: consider `await`ing on the `Future`
|
|
|
|
|
|
|
|
|
LL | take_u32(x.await)
|
2021-06-21 21:07:19 -05:00
|
|
|
| ++++++
|
2019-06-19 15:55:18 -05:00
|
|
|
|
2019-12-03 19:32:50 -06:00
|
|
|
error[E0308]: mismatched types
|
2020-10-22 21:03:36 -05:00
|
|
|
--> $DIR/suggest-missing-await.rs:22:5
|
2019-12-03 19:32:50 -06:00
|
|
|
|
|
|
|
|
LL | dummy()
|
2023-02-10 12:03:54 -06:00
|
|
|
| ^^^^^^^ expected `()`, found future
|
2019-12-03 19:32:50 -06:00
|
|
|
|
|
2023-02-10 12:03:54 -06:00
|
|
|
note: calling an async function returns a future
|
|
|
|
--> $DIR/suggest-missing-await.rs:22:5
|
|
|
|
|
|
|
|
|
LL | dummy()
|
|
|
|
| ^^^^^^^
|
2020-10-21 16:25:09 -05:00
|
|
|
help: consider `await`ing on the `Future`
|
2019-12-03 19:32:50 -06:00
|
|
|
|
|
|
|
|
LL | dummy().await
|
2021-06-21 21:07:19 -05:00
|
|
|
| ++++++
|
2022-02-11 01:18:06 -06:00
|
|
|
help: consider using a semicolon here
|
|
|
|
|
|
|
|
|
LL | dummy();
|
|
|
|
| +
|
2019-12-03 19:32:50 -06:00
|
|
|
|
2021-11-16 00:51:20 -06:00
|
|
|
error[E0308]: `if` and `else` have incompatible types
|
2022-02-11 01:18:06 -06:00
|
|
|
--> $DIR/suggest-missing-await.rs:35:9
|
2021-11-16 00:51:20 -06:00
|
|
|
|
|
|
|
|
LL | let _x = if true {
|
|
|
|
| ______________-
|
|
|
|
LL | | dummy()
|
|
|
|
| | ------- expected because of this
|
|
|
|
LL | |
|
|
|
|
LL | | } else {
|
|
|
|
LL | | dummy().await
|
2023-02-10 12:03:54 -06:00
|
|
|
| | ^^^^^^^^^^^^^ expected future, found `()`
|
2021-11-16 00:51:20 -06:00
|
|
|
LL | |
|
|
|
|
LL | | };
|
|
|
|
| |_____- `if` and `else` have incompatible types
|
|
|
|
|
|
2022-04-17 14:00:32 -05:00
|
|
|
= note: expected opaque type `impl Future<Output = ()>`
|
|
|
|
found unit type `()`
|
2021-11-16 00:51:20 -06:00
|
|
|
help: consider `await`ing on the `Future`
|
|
|
|
|
|
|
|
|
LL | dummy().await
|
|
|
|
| ++++++
|
|
|
|
|
|
|
|
error[E0308]: `match` arms have incompatible types
|
2022-02-11 01:18:06 -06:00
|
|
|
--> $DIR/suggest-missing-await.rs:45:14
|
2021-11-16 00:51:20 -06:00
|
|
|
|
|
|
|
|
LL | let _x = match 0usize {
|
|
|
|
| ______________-
|
|
|
|
LL | | 0 => dummy(),
|
2021-11-16 18:16:23 -06:00
|
|
|
| | ------- this is found to be of type `impl Future<Output = ()>`
|
2021-11-16 00:51:20 -06:00
|
|
|
LL | | 1 => dummy(),
|
2021-11-16 18:16:23 -06:00
|
|
|
| | ------- this is found to be of type `impl Future<Output = ()>`
|
2021-11-16 00:51:20 -06:00
|
|
|
LL | | 2 => dummy().await,
|
2023-02-10 12:03:54 -06:00
|
|
|
| | ^^^^^^^^^^^^^ expected future, found `()`
|
2021-11-16 00:51:20 -06:00
|
|
|
LL | |
|
|
|
|
LL | | };
|
|
|
|
| |_____- `match` arms have incompatible types
|
|
|
|
|
|
2021-11-16 18:16:23 -06:00
|
|
|
= note: expected opaque type `impl Future<Output = ()>`
|
2021-11-16 00:51:20 -06:00
|
|
|
found unit type `()`
|
|
|
|
help: consider `await`ing on the `Future`
|
|
|
|
|
|
|
|
|
LL ~ 0 => dummy().await,
|
|
|
|
LL ~ 1 => dummy().await,
|
|
|
|
|
|
|
|
|
|
|
|
|
error[E0308]: mismatched types
|
2022-02-11 01:18:06 -06:00
|
|
|
--> $DIR/suggest-missing-await.rs:53:9
|
2021-11-16 00:51:20 -06:00
|
|
|
|
|
2021-12-15 17:16:21 -06:00
|
|
|
LL | let _x = match dummy() {
|
|
|
|
| ------- this expression has type `impl Future<Output = ()>`
|
2021-11-16 00:51:20 -06:00
|
|
|
LL | () => {}
|
2023-02-10 12:03:54 -06:00
|
|
|
| ^^ expected future, found `()`
|
2021-11-16 00:51:20 -06:00
|
|
|
|
|
2021-11-16 18:16:23 -06:00
|
|
|
= note: expected opaque type `impl Future<Output = ()>`
|
2021-11-16 00:51:20 -06:00
|
|
|
found unit type `()`
|
|
|
|
help: consider `await`ing on the `Future`
|
|
|
|
|
|
|
|
|
LL | let _x = match dummy().await {
|
|
|
|
| ++++++
|
|
|
|
|
2021-11-17 23:38:04 -06:00
|
|
|
error[E0308]: mismatched types
|
2022-02-11 01:18:06 -06:00
|
|
|
--> $DIR/suggest-missing-await.rs:67:9
|
2021-11-17 23:38:04 -06:00
|
|
|
|
|
2021-12-15 17:16:21 -06:00
|
|
|
LL | match dummy_result() {
|
|
|
|
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
|
|
|
|
...
|
2021-11-17 23:38:04 -06:00
|
|
|
LL | Ok(_) => {}
|
2023-02-10 12:03:54 -06:00
|
|
|
| ^^^^^ expected future, found `Result<_, _>`
|
2021-11-17 23:38:04 -06:00
|
|
|
|
|
2021-11-20 12:00:14 -06:00
|
|
|
= note: expected opaque type `impl Future<Output = Result<(), ()>>`
|
2021-11-17 23:38:04 -06:00
|
|
|
found enum `Result<_, _>`
|
|
|
|
help: consider `await`ing on the `Future`
|
|
|
|
|
|
|
|
|
LL | match dummy_result().await {
|
|
|
|
| ++++++
|
|
|
|
|
|
|
|
error[E0308]: mismatched types
|
2022-02-11 01:18:06 -06:00
|
|
|
--> $DIR/suggest-missing-await.rs:69:9
|
2021-11-17 23:38:04 -06:00
|
|
|
|
|
2021-12-15 17:16:21 -06:00
|
|
|
LL | match dummy_result() {
|
|
|
|
| -------------- this expression has type `impl Future<Output = Result<(), ()>>`
|
|
|
|
...
|
2021-11-17 23:38:04 -06:00
|
|
|
LL | Err(_) => {}
|
2023-02-10 12:03:54 -06:00
|
|
|
| ^^^^^^ expected future, found `Result<_, _>`
|
2021-11-17 23:38:04 -06:00
|
|
|
|
|
2021-11-20 12:00:14 -06:00
|
|
|
= note: expected opaque type `impl Future<Output = Result<(), ()>>`
|
2021-11-17 23:38:04 -06:00
|
|
|
found enum `Result<_, _>`
|
|
|
|
help: consider `await`ing on the `Future`
|
|
|
|
|
|
|
|
|
LL | match dummy_result().await {
|
|
|
|
| ++++++
|
|
|
|
|
|
|
|
error: aborting due to 7 previous errors
|
2019-06-19 15:55:18 -05:00
|
|
|
|
|
|
|
For more information about this error, try `rustc --explain E0308`.
|