-
Notifications
You must be signed in to change notification settings - Fork 13k
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 compilation error when forgetting to deref_mut in a chain of iterators #105337
Comments
@rustbot claim |
Trying to force the deref using let x = x
.iter_mut()
.map(<&mut [u8]>::from) // <-- this line
.map(foo); error[[E0631]](https://doc.rust-lang.org/stable/error-index.html#E0631): type mismatch in function arguments
--> src/main.rs:18:14
|
18 | .map(<&mut [u8]>::from)
| --- ^^^^^^^^^^^^^^^^^
| | |
| | expected due to this
| | found signature defined here
| required by a bound introduced by this call
|
= note: expected function signature `fn(&mut Vec<u8>) -> _`
found function signature `fn(&mut [u8]) -> _`
note: required by a bound in `map` |
As I understand, the issue is that |
I couldn't find confirmation, so I am releasing. |
@ch-iv Your understanding is right. Sorry, I did not saw the notification, which explain why I didn’t responded earlier. |
@rustbot claim |
@ch-iv you can take a look at #105674 for inspiration on how to walk the method chain looking for the previous types, but in this case you need to look at the expected/found arguments, detect there's a single one and then check if the found implements |
@estebank Ok, thank you. I was unsure about how to proceed, but I hope this will help. |
Current output:
The suggestion isn't perfect, but it provides a path to get to working code:
After passing |
This doesn’t compile:
The solution is either to call first deref
or
Or to use a lambda
The current error doesn’t help to understand what the issue is and it’s very confusing because it may look like a lifetime error (because of the
for<'r>
…).https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c6ac2ca7a31b126442978d30419e07a8
The text was updated successfully, but these errors were encountered: