-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Description
The following code will compile and run (and fail an assertion), when it should not compile:
use std::cell::RefCell;
struct A {
a: RefCell<Vec<int>>,
}
fn main() {
let mut a = A{a: RefCell::new(vec![1])};
for i in a.a.borrow().iter() {
let r = &mut a;
r.a = RefCell::new(vec![2]);
println!("{}", i);
}
}
Notably, this version properly produces a compile error, recognizing the existing immutable borrow:
use std::cell::RefCell;
struct A {
a: RefCell<Vec<int>>,
}
fn main() {
let mut a = A{a: RefCell::new(vec![1])};
let b = a.a.borrow();
for i in b.iter() {
let r = &mut a;
r.a = RefCell::new(vec![2]);
println!("{}", i);
}
}
Metadata
Metadata
Assignees
Labels
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.