-
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/incorrect "&mut &mut [T] is not an iterator" #84837
Comments
This can happen "naturally" when trying to mutate nested arrays: let mut inner = [1usize, 2, 3, 4, 5];
let mut outer = [&mut inner];
for items in &mut outer {
for item in items {
*item += 1
}
}
Not sure if there is a more idiomatic way to write that code that avoids this but it feels like this should just work. The message
Also seems confusing when I think/know that it should definitely be an Iterator (or IntoIterator). The same code using let mut inner = vec![1, 2, 3, 4, 5];
let mut outer = vec![&mut inner];
for items in &mut outer {
for item in items {
*item += 1
}
}
|
These labels are given with |
Ah someone already added a variant for I'm still curious why the code doesn't "just work"tm but at least the errors are helpful. |
Triage: we now provide enough context to figure out what the problem might be, but it is not newcomer friendly.
|
I need to check why the logic being modified at #106360 doesn't trigger for these cases. |
… r=compiler-errors Tweak E0277 `&`-removal suggestions Fix rust-lang#64068, fix rust-lang#84837.
… r=compiler-errors Tweak E0277 `&`-removal suggestions Fix rust-lang#64068, fix rust-lang#84837.
… r=compiler-errors Tweak E0277 `&`-removal suggestions Fix rust-lang#64068, fix rust-lang#84837.
Given the following code:
The current output is:
Ideally it would say that
&mut &mut T
is not an iterator and maybe suggest removing&mut
.On the other hand,
for _ in &mut &mut (0usize..)
just derefs and works fine.@rustbot label: A-diagnostics D-incorrect D-confusing
The text was updated successfully, but these errors were encountered: