You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3989fe9
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/behavior-considered-undefined.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,6 +144,9 @@ r[undefined.validity.struct]
144
144
r[undefined.validity.union]
145
145
* For a `union`, the exact validity requirements are not decided yet. Obviously, all values that can be created entirely in safe code are valid. If the union has a [zero-sized] field, then every possible value is valid. Further details are [still being debated](https://github.com/rust-lang/unsafe-code-guidelines/issues/438).
146
146
147
+
r[undefined.validity.maybe-uninit]
148
+
* A [`MaybeUninit<T>`] is always valid (see [lang-types.maybe-uninit.validity]).
149
+
147
150
r[undefined.validity.reference-box]
148
151
* A reference or [`Box<T>`] must be aligned and non-null, it cannot be [dangling], and it must point to a valid value (in case of dynamically sized types, using the actual dynamic type of the pointee as determined by the [metadata]). Note that the last point (about pointing to a valid value) remains a subject of some debate.
It also ensures that [`static` items] which have a type with interior mutability aren't placed in memory marked as read only.
50
50
51
+
r[lang-types.maybe-uninit]
52
+
## `MaybeUninit<T>`
53
+
54
+
r[lang-types.maybe-uninit.intro]
55
+
[`MaybeUninit<T>`] is a type for values that are laid out like a `T` but need not be a valid `T`. This is useful when allocating and writing to memory intended for `T` values before that memory holds a valid `T`, as when initializing such values in place.
56
+
57
+
r[lang-types.maybe-uninit.validity]
58
+
A value of type [`MaybeUninit<T>`] is always [valid], regardless of any validity requirements for a value of type `T`.
59
+
60
+
r[lang-types.maybe-uninit.layout]
61
+
[`MaybeUninit<T>`] is guaranteed to have the same [size], [alignment], and [ABI] as `T`.
62
+
51
63
r[lang-types.phantom-data]
52
64
## `PhantomData<T>`
53
65
@@ -188,6 +200,7 @@ These implicit `Sized` bounds may be relaxed by using the special `?Sized` bound
188
200
[`Arc<Self>`]: std::sync::Arc
189
201
[`Deref`]: std::ops::Deref
190
202
[`DerefMut`]: std::ops::DerefMut
203
+
[`MaybeUninit<T>`]: core::mem::MaybeUninit
191
204
[`Pin<P>`]: std::pin::Pin
192
205
[`Rc<Self>`]: std::rc::Rc
193
206
[`RefUnwindSafe`]: std::panic::RefUnwindSafe
@@ -196,6 +209,8 @@ These implicit `Sized` bounds may be relaxed by using the special `?Sized` bound
0 commit comments