@@ -20,9 +20,9 @@ use crate::mem::ManuallyDrop;
20
20
/// # #![allow(invalid_value)]
21
21
/// use std::mem::{self, MaybeUninit};
22
22
///
23
- /// let x: &i32 = unsafe { mem::zeroed() }; // undefined behavior!
23
+ /// let x: &i32 = unsafe { mem::zeroed() }; // undefined behavior! ⚠️
24
24
/// // The equivalent code with `MaybeUninit<&i32>`:
25
- /// let x: &i32 = unsafe { MaybeUninit::zeroed().assume_init() }; // undefined behavior!
25
+ /// let x: &i32 = unsafe { MaybeUninit::zeroed().assume_init() }; // undefined behavior! ⚠️
26
26
/// ```
27
27
///
28
28
/// This is exploited by the compiler for various optimizations, such as eliding
@@ -35,9 +35,9 @@ use crate::mem::ManuallyDrop;
35
35
/// # #![allow(invalid_value)]
36
36
/// use std::mem::{self, MaybeUninit};
37
37
///
38
- /// let b: bool = unsafe { mem::uninitialized() }; // undefined behavior!
38
+ /// let b: bool = unsafe { mem::uninitialized() }; // undefined behavior! ⚠️
39
39
/// // The equivalent code with `MaybeUninit<bool>`:
40
- /// let b: bool = unsafe { MaybeUninit::uninit().assume_init() }; // undefined behavior!
40
+ /// let b: bool = unsafe { MaybeUninit::uninit().assume_init() }; // undefined behavior! ⚠️
41
41
/// ```
42
42
///
43
43
/// Moreover, uninitialized memory is special in that the compiler knows that
@@ -49,9 +49,9 @@ use crate::mem::ManuallyDrop;
49
49
/// # #![allow(invalid_value)]
50
50
/// use std::mem::{self, MaybeUninit};
51
51
///
52
- /// let x: i32 = unsafe { mem::uninitialized() }; // undefined behavior!
52
+ /// let x: i32 = unsafe { mem::uninitialized() }; // undefined behavior! ⚠️
53
53
/// // The equivalent code with `MaybeUninit<i32>`:
54
- /// let x: i32 = unsafe { MaybeUninit::uninit().assume_init() }; // undefined behavior!
54
+ /// let x: i32 = unsafe { MaybeUninit::uninit().assume_init() }; // undefined behavior! ⚠️
55
55
/// ```
56
56
/// (Notice that the rules around uninitialized integers are not finalized yet, but
57
57
/// until they are, it is advisable to avoid them.)
@@ -348,7 +348,7 @@ impl<T> MaybeUninit<T> {
348
348
/// let x = MaybeUninit::<(u8, NotZero)>::zeroed();
349
349
/// let x = unsafe { x.assume_init() };
350
350
/// // Inside a pair, we create a `NotZero` that does not have a valid discriminant.
351
- /// // This is undefined behavior.
351
+ /// // This is undefined behavior. ⚠️
352
352
/// ```
353
353
#[ stable( feature = "maybe_uninit" , since = "1.36.0" ) ]
354
354
#[ inline]
@@ -400,7 +400,7 @@ impl<T> MaybeUninit<T> {
400
400
///
401
401
/// let x = MaybeUninit::<Vec<u32>>::uninit();
402
402
/// let x_vec = unsafe { &*x.as_ptr() };
403
- /// // We have created a reference to an uninitialized vector! This is undefined behavior.
403
+ /// // We have created a reference to an uninitialized vector! This is undefined behavior. ⚠️
404
404
/// ```
405
405
///
406
406
/// (Notice that the rules around references to uninitialized data are not finalized yet, but
@@ -437,7 +437,7 @@ impl<T> MaybeUninit<T> {
437
437
///
438
438
/// let mut x = MaybeUninit::<Vec<u32>>::uninit();
439
439
/// let x_vec = unsafe { &mut *x.as_mut_ptr() };
440
- /// // We have created a reference to an uninitialized vector! This is undefined behavior.
440
+ /// // We have created a reference to an uninitialized vector! This is undefined behavior. ⚠️
441
441
/// ```
442
442
///
443
443
/// (Notice that the rules around references to uninitialized data are not finalized yet, but
@@ -489,7 +489,7 @@ impl<T> MaybeUninit<T> {
489
489
///
490
490
/// let x = MaybeUninit::<Vec<u32>>::uninit();
491
491
/// let x_init = unsafe { x.assume_init() };
492
- /// // `x` had not been initialized yet, so this last line caused undefined behavior.
492
+ /// // `x` had not been initialized yet, so this last line caused undefined behavior. ⚠️
493
493
/// ```
494
494
#[ stable( feature = "maybe_uninit" , since = "1.36.0" ) ]
495
495
#[ inline( always) ]
@@ -553,7 +553,7 @@ impl<T> MaybeUninit<T> {
553
553
/// x.write(Some(vec![0,1,2]));
554
554
/// let x1 = unsafe { x.read() };
555
555
/// let x2 = unsafe { x.read() };
556
- /// // We now created two copies of the same vector, leading to a double-free when
556
+ /// // We now created two copies of the same vector, leading to a double-free ⚠️ when
557
557
/// // they both get dropped!
558
558
/// ```
559
559
#[ unstable( feature = "maybe_uninit_extra" , issue = "63567" ) ]
@@ -603,7 +603,7 @@ impl<T> MaybeUninit<T> {
603
603
///
604
604
/// let x = MaybeUninit::<Vec<u32>>::uninit();
605
605
/// let x_vec: &Vec<u32> = unsafe { x.get_ref() };
606
- /// // We have created a reference to an uninitialized vector! This is undefined behavior.
606
+ /// // We have created a reference to an uninitialized vector! This is undefined behavior. ⚠️
607
607
/// ```
608
608
///
609
609
/// ```rust,no_run
@@ -686,7 +686,7 @@ impl<T> MaybeUninit<T> {
686
686
/// unsafe {
687
687
/// *b.get_mut() = true;
688
688
/// // We have created a (mutable) reference to an uninitialized `bool`!
689
- /// // This is undefined behavior.
689
+ /// // This is undefined behavior. ⚠️
690
690
/// }
691
691
/// ```
692
692
///
0 commit comments