File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1748,6 +1748,31 @@ unsafe impl<T: ?Sized> IsZero for *mut T {
1748
1748
}
1749
1749
}
1750
1750
1751
+ // `Option<&T>`, `Option<&mut T>` and `Option<Box<T>>` are guaranteed to represent `None` as null.
1752
+ // For fat pointers, the bytes that would be the pointer metadata in the `Some` variant
1753
+ // are padding in the `None` variant, so ignoring them and zero-initializing instead is ok.
1754
+
1755
+ unsafe impl < T : ?Sized > IsZero for Option < & T > {
1756
+ #[ inline]
1757
+ fn is_zero ( & self ) -> bool {
1758
+ self . is_none ( )
1759
+ }
1760
+ }
1761
+
1762
+ unsafe impl < T : ?Sized > IsZero for Option < & mut T > {
1763
+ #[ inline]
1764
+ fn is_zero ( & self ) -> bool {
1765
+ self . is_none ( )
1766
+ }
1767
+ }
1768
+
1769
+ unsafe impl < T : ?Sized > IsZero for Option < Box < T > > {
1770
+ #[ inline]
1771
+ fn is_zero ( & self ) -> bool {
1772
+ self . is_none ( )
1773
+ }
1774
+ }
1775
+
1751
1776
1752
1777
////////////////////////////////////////////////////////////////////////////////
1753
1778
// Common trait implementations for Vec
You can’t perform that action at this time.
0 commit comments