-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Misleading Error with &dyn #95598
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
Comments
My use case for this is the following function, which returns a predicate. fn cmp<P:AsRef<Path>>(name:P) -> impl Fn(&dyn AsRef<Path>)->bool
{
move |s| {
return name.as_ref().ends_with(s)
}
} To call it, I need to do the following. cmp("test")(&&"test".to_string())
cmp("test")(&"test")//This works, because str and Path are both not Sized, right? Please correct me, but I do not think, that I can write this any better right now (without inlining the function). I |
The message does not state that |
Yes, but the whole message is missing the point, of what is actually happening. The Message is very unclear in what is says. Take the error message, without the hints. Misses completely what is going on.
Also can you please explain to me, why |
…yn, r=nagisa Suggest borrowing when trying to coerce unsized type into `dyn Trait` A helpful error in response to rust-lang#95598, since we can't coerce e.g. `&str` into `&dyn Display`, but we can coerce `&&str` into `&dyn Display` :) Not sure if the suggestion message needs some help. Let me know, and I can refine this PR.
Given the following code
The current output is:
Stating, that &str does not have a known size at compile time is just wrong.
I think that rust sees, that the function parameter has a Borrowed type and that the function call also provides a borrowed type. So rust probably procedes to check the actual types 'behind' the borrow.
It is just, that here I would expect a message asking me if I would have liked to borrow here, since that would solve this error.
The text was updated successfully, but these errors were encountered: