-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Confusing diagnostic - error[E0308]: mismatched types #84400
Comments
The output in beta is
You can make this compile by adding a named lifetime tying |
@estebank, Thanks for responding. The new diagnostic is obviously better but I also don't think I fully understand it to be honest. |
The diagnostic absolutely needs to be improved. The reason this doesn't compile is because the signature desugars to And that is a problem because the compiler can't ensure that |
Here's an even simpler one: fn check<S: AsRef<str>>(_: S) -> bool {
false
}
fn main() {
let options: Vec<String> = Vec::new();
let _ = options.into_iter().filter(check::<&String>);
} On stable this produces the unhelpful
On beta/nightly it's a little better, but still pretty inscrutable:
In this particular case it can be fixed with: fn check<S: AsRef<str>>(_: &S) -> bool {
false
}
fn main() {
let options: Vec<String> = Vec::new();
let _ = options.into_iter().filter(check::<String>);
} But that's not really a general solution. Just sharing in case others run into something similar and ends up here. |
Current output:
|
https://play.rust-lang.org/?gist=d912ef0e107be493dd10b72f973897ba
The current output is:
I'm not quite sure what's the right diagnostic here, maybe that it should be by value?
The text was updated successfully, but these errors were encountered: