Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reporting a reason of error with an irrelevant constraint in this example #125110

Open
xmh0511 opened this issue May 14, 2024 · 0 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xmh0511
Copy link

xmh0511 commented May 14, 2024

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));
}
@xmh0511 xmh0511 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant