为什么 `*mut T` 实现了 `Unwindsafe` 但 `&mut T` 没有?
Why does `*mut T` implement `Unwindsafe` but `&mut T` doesn't?
在 Unwindsafe
的 documentation 中,我们有:
Types such as &mut
T and &RefCell<T>
are examples which are not unwind safe. The general idea is that any mutable state which can be shared across catch_unwind
is not unwind safe by default. This is because it is very easy to witness a broken invariant outside of catch_unwind
as the data is simply accessed as usual.
按照这个逻辑,在我看来 *mut T
不应该是 Unwindsafe
。但是it turns out that it is。这是为什么?
*mut T
作为原始指针,它没有任何不变性。
可以为null,指向无效内存,就是Copy
,可以有两个指向同一个内存区域
无论如何, 和 安全性都无法改变 *mut T
,因此没有理由不成为 Unwindsafe
.
在 Unwindsafe
的 documentation 中,我们有:
Types such as
&mut
T and&RefCell<T>
are examples which are not unwind safe. The general idea is that any mutable state which can be shared acrosscatch_unwind
is not unwind safe by default. This is because it is very easy to witness a broken invariant outside ofcatch_unwind
as the data is simply accessed as usual.
按照这个逻辑,在我看来 *mut T
不应该是 Unwindsafe
。但是it turns out that it is。这是为什么?
*mut T
作为原始指针,它没有任何不变性。
可以为null,指向无效内存,就是Copy
,可以有两个指向同一个内存区域
无论如何, 和 安全性都无法改变 *mut T
,因此没有理由不成为 Unwindsafe
.