-
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
diagnostics: suggest iter_mut() where trying to modify .iter()'ed vector elements inplace #62387
Comments
@rustbot modify labels: A-diagnostics |
Error: Parsing label command in comment failed: ...ify labels|error: must have : or to as label starter at >| A-diagnos... Please let |
Urgh I just ran into this AGAIN. 😭 My code was something like this: use std::path::PathBuf;
struct Container {
things: Vec<PathBuf>,
}
impl Container {
fn things(&mut self) -> &[PathBuf] {
&self.things
}
}
// contains containers
struct ContainerContainer {
contained: Vec<Container>
}
impl ContainerContainer {
fn contained(&self ) -> &[Container] {
&self.contained
}
fn all_the_things(&mut self) -> &[PathBuf]
{
let a = &self.contained().iter().flat_map(|container| container.things()).cloned().collect::<Vec<PathBuf>>();
unimplemented!();
}
}
pub fn main() {} The error shown:
So I changed it to
which made me wonder if I was better off with the origin I really wish rust could somehow detect the |
…ut, r=davidtwco suggest iter_mut() where trying to modify elements from .iter() Fixes rust-lang#115259 Fixes rust-lang#62387
…twco suggest iter_mut() where trying to modify elements from .iter() Fixes rust-lang/rust#115259 Fixes rust-lang/rust#62387
code:
The code gives the following not-very-helpful warning:
trying to use
and a none-mutable vector just causes more errors
The actual fix is to use
iter_mut()
instead of justiter()
:It would be very helpful the compiler could suggest
iter_mut()
!The text was updated successfully, but these errors were encountered: