This is because of incorrect use of unreachable_unchecked when Lazy structure is poisoned.
pub fn force(this: &Lazy<T, F>) -> &T {
// Safe because closure is guaranteed to be called at most once
// so we only call `F` once, this also guarantees no race conditions
this.cell.get_or_init(|| unsafe {
match (*this.init.get()).take() {
Some(f) => f(),
None => unreachable_unchecked(),
}
})
}
This should panic instead of causing unreachable UB.
The following program causes UB:
This is because of incorrect use of
unreachable_unchecked
whenLazy
structure is poisoned.This should panic instead of causing unreachable UB.