Closure argument type ambiguity errors when the outer call has wrong number of arguments
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 test() {
takes_two_args(|s| {
s.to_string();
});
}
fn takes_two_args(thing: u32, f: impl Fn(&str)) {
todo!();
}
Current output
error[E0282]: type annotations needed
--> src/lib.rs:3:21
|
3 | takes_two_args(|s| {
| ^
4 | s.to_string();
| - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
3 | takes_two_args(|s: /* Type */| {
| ++++++++++++
Desired output
Wrong number of arguments.
Rationale and extra context
In addition to wrong number of arguments, maybe we could also detect when the argument type is not a function. (Both are true in this example)
Other cases
Rust Version
1.87.0
Anything else?
No response
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.
Research direction
The issue names no repository file or test. Reproduce the closure example with rustc 1.87.0, then locate the compiler diagnostics and type-checking tests covering closure argument inference; done means the wrong-argument-count case reports “Wrong number of arguments.” instead of E0282.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100