Nested argument mismatch could suggest moving extra parameter outside parenthesis
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
fn mul(a: i32, b: i32) -> i32 {
a * b
}
fn main() {
let x = mul(4.min(3, 14));
println!("{x}");
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0061]: this method takes 1 argument but 2 arguments were supplied
--> src/main.rs:6:19
|
6 | let x = mul(4.min(3, 14));
| ^^^ ----
| | |
| | unexpected argument of type `{integer}`
| help: remove the extra argument
|
note: method defined here
--> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cmp.rs:877:8
|
877 | fn min(self, other: Self) -> Self
| ^^^
error[E0061]: this function takes 2 arguments but 1 argument was supplied
--> src/main.rs:6:13
|
6 | let x = mul(4.min(3, 14));
| ^^^-------------- an argument of type `i32` is missing
|
note: function defined here
--> src/main.rs:1:4
|
1 | fn mul(a: i32, b: i32) -> i32 {
| ^^^ ------ ------
help: provide the argument
|
6 | let x = mul(4.min(3, 14), /* i32 */);
| ~~~~~~~~~~~~~~~~~~~~~~~~~
For more information about this error, try `rustc --explain E0061`.
error: could not compile `playground` (bin "playground") due to 2 previous errors
Desired output
Something like
6 | let x = mul(4.min(3), 14);
| ^^^ ~~~~~
| |
| |
| help: move the argument outside the parenthesis
Rationale and extra context
This happened while trying to pass a missing parameter to an outer function, but I had placed the extra parameter to a call inside instead. When both of the conditions are met, we can be mostly sure that the user intended to pass the parameter to the outer function instead:
- The inner function/method expects at least one argument and the user passed in an extra one
- The function call is the last passed in argument to the outer function, but outer function expects one additional argument.
- The type matches (not sure if possible to check that, but that would make it 100% sure that this is what the user intended)
Other cases
No response
Rust Version
Latest nightly
Anything else?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.