Closed
Description
Minimal example:
fn do_something<T>(collection: &mut Vec<T>) {
let a = &collection;
collection.swap(1, 2);
}
Error message (ran in playground):
rustc 1.17.0 (56124baa9 2017-04-24)
error[E0502]: cannot borrow `*collection` as mutable because `collection` is also borrowed as immutable
--> <anon>:3:5
|
2 | let a = &collection;
| ---------- immutable borrow occurs here
3 | collection.swap(1, 2);
| ^^^^^^^^^^ mutable borrow occurs here
4 | }
| - immutable borrow ends here
error[E0502]: cannot borrow `*collection` as mutable because `collection` is also borrowed as immutable
--> <anon>:3:5
|
2 | let a = &collection;
| ---------- immutable borrow occurs here
3 | collection.swap(1, 2);
| ^^^^^^^^^^ mutable borrow occurs here
4 | }
| - immutable borrow ends here
error: aborting due to 2 previous errors
Compilation failed.
Tested on nightly as well (rustc 1.19.0-nightly (0ed1ec9f9 2017-05-18)
)
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsCategory: An issue proposing an enhancement or a PR with one.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Working group: Diagnostics