-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Possible to mutably borrow elements inside a Vec inside a HashMap multiple times #17500
Comments
Little bit shorter example, without mutable borrows. But still fails to freeze fn main() {
let mut my_stuff = std::collections::HashMap::new();
my_stuff.insert(0i, 42i);
let (_, thing) = my_stuff.iter().next().unwrap();
my_stuff.clear();
println!("{}", *thing);
} |
nominating for 1.0 P-backcompat-lang |
though this may be a library issue |
0.o weird This code is also valid:
This is because the hashmap iterator just wraps the rawtable iterator, which just defers to the RawBuckets iterator, which is just a wrapper around two *mut's. That is, literally none of these iterators actually borrows the hashmap. Presumably this is fixable by taking a useless reference somewhere. The other thing I'm seeing is that there's CC @pczarn |
Yep, it's eliding
|
So there's two bugs here: the iterator doesn't borrow the map, and the references are being yielded as |
Assigning P-backcompat-libs, 1.0 |
@pczarn thanks for fixing this! Great job! |
fix: completions after async kw fix rust-lang#17500 ### Changes 1. fix completions after async kw 2. fix completions for `async` kw in trait
Sorry, I'm not sure how to describe this very well in a sentence. I am able to mutably borrow the innermost values of a
HashMap<u32, Vec<int>>
, delete the values, then reference them after they were deleted. This code compiles, runs, and barfs out strange numbers.The text was updated successfully, but these errors were encountered: