UB dropping slice_deque::IntoIter containing dangling items
dtolnay opened this issue · 0 comments
dtolnay commented
Inside this Drop
impl:
Lines 2454 to 2458 in 045fb28
those _x
are of type T
, based on:
Lines 2363 to 2364 in 045fb28
However T
is may_dangle, so it's UB to touch/pass/return an object of that type by value. Check out rust-lang/unsafe-code-guidelines#283.
Here is an example of code that triggers the problem. We have a SliceDeque<&usize>
and drop its IntoIter, which ends up with _x: &'dangling usize
inside of that Drop impl.
use slice_deque::SliceDeque;
fn main() {
let _iter;
let x = Box::new(0usize);
let mut deque = SliceDeque::new();
deque.push_back(&*x);
_iter = deque.into_iter();
// x is dropped
// then _iter is dropped
}