-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Description
Check out in Release
mode on playpen:
#![feature(cell_extras)]
use std::cell::{RefCell, Ref};
use std::mem;
use std::usize;
fn main() {
let ref_cell = RefCell::new(vec![1, 2, 3]);
let r = ref_cell.borrow();
let mut i = 0;
while i < usize::MAX {
mem::forget(Ref::clone(&r));
i += 1;
}
ref_cell.borrow_mut().push(r[0]);
}
This succeeds (when compiled with optimizations) despite having both a Ref
and a RefMut
.
RefCell::borrow
is safe from this because at usize::MAX
it believes it's mutably borrowed and panics.
There's a debug_assert!(borrow != WRITING && borrow != UNUSED);
line in src/libcore/cell.rs
which would catch this with debug assertions enabled, I believe it should be an assert!
(Ref::clone
is unstable and likely not performance critical anyway).
Metadata
Metadata
Assignees
Labels
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.