Reporting a reason of error with an irrelevant constraint in this example
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
Code
trait Binder<Args>{
fn invoke(&self,args:Args);
}
impl<T,U,F> Binder<(T,U)> for F
where F:Fn(T,U,& dyn Binder<(T,U)>)
{
fn invoke(&self,args:(T,U)) {
let (t,u) = args;
self(t,u,self)
}
}
fn main(){
let f = |a,b,c|{};
f.invoke((1,2));
}
Current output
--> src/main.rs:15:4
|
14 | let f = |a,b,c|{};
| ------- doesn't satisfy `<_ as FnOnce<(_, _, &dyn Binder<(_, _)>)>>::Output = ()` or `_: Binder<(_, _)>`
15 | f.invoke((1,2));
| ^^^^^^
|
note: trait bound `<{closure@src/main.rs:14:10: 14:17} as FnOnce<(_, _, &dyn Binder<(_, _)>)>>::Output = ()` was not satisfied
--> src/main.rs:6:9
|
5 | impl<T,U,F> Binder<(T,U)> for F
| ------------- -
6 | where F:Fn(T,U,& dyn Binder<(T,U)>)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
= help: items from traits can only be used if the trait is implemented and in scope
note: `Binder` defines an item `invoke`, perhaps you need to implement it
--> src/main.rs:1:1
|
1 | trait Binder<Args>{
| ^^^^^^^^^^^^^^^^^^
Desired output
This example should be successfully inferred from the context
Rationale and extra context
No response
Other cases
No response
Rust Version
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2
Anything else?
If manually annotate the parameter types, the example can be compiled
fn main(){
let f = |a,b,c:& dyn Binder<(i32,i32)>|{};
f.invoke((1,2));
}
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
Start by reproducing the example in src/main.rs with rustc 1.78.0, then compare it with the manually annotated version that compiles. Investigate why inference reports the irrelevant FnOnce output and Binder bounds; done means the unannotated example compiles successfully as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100