diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 1671c8219de16..c951a4d1829a6 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -705,9 +705,24 @@ pub const unsafe fn zeroed() -> T { /// Therefore, it is immediate undefined behavior to call this function on nearly all types, /// including integer types and arrays of integer types, and even if the result is unused. /// +/// # Safety +/// +/// This function is highly unsafe, as calling this function on nearly all types causes +/// undefined behavior. You should **always** prefer using [`MaybeUninit`] instead. +/// +/// If you absolutely must use this function, the following conditions must be upheld: +/// +/// - `T` must be *valid* with any sequence of bytes of the appropriate length, +/// initialized or uninitialized. +/// - `T` must be *[inhabited]*, i.e. possible to construct. This means that types +/// like zero-variant enums and [`!`] are unsound to construct with this function. +/// - You must use the value only in ways which do not violate any *safety* +/// invariants of the type. +/// /// [uninit]: MaybeUninit::uninit /// [assume_init]: MaybeUninit::assume_init /// [inv]: MaybeUninit#initialization-invariant +/// [inhabited]: https://doc.rust-lang.org/reference/glossary.html#inhabited #[inline(always)] #[must_use] #[deprecated(since = "1.39.0", note = "use `mem::MaybeUninit` instead")] diff --git a/tests/ui/thir-print/offset_of.stdout b/tests/ui/thir-print/offset_of.stdout index b3791a2446cb4..c6fe88da57514 100644 --- a/tests/ui/thir-print/offset_of.stdout +++ b/tests/ui/thir-print/offset_of.stdout @@ -67,8 +67,8 @@ body: } ) else_block: None - hir_id: HirId(DefId(offset_of::concrete).10) - span: $DIR/offset_of.rs:37:5: 1440:57 (#0) + lint_level: Explicit(HirId(DefId(offset_of::concrete).10)) + span: $DIR/offset_of.rs:37:5: 1455:57 (#0) } } Stmt { @@ -116,8 +116,8 @@ body: } ) else_block: None - hir_id: HirId(DefId(offset_of::concrete).20) - span: $DIR/offset_of.rs:38:5: 1440:57 (#0) + lint_level: Explicit(HirId(DefId(offset_of::concrete).20)) + span: $DIR/offset_of.rs:38:5: 1455:57 (#0) } } Stmt { @@ -165,8 +165,8 @@ body: } ) else_block: None - hir_id: HirId(DefId(offset_of::concrete).30) - span: $DIR/offset_of.rs:39:5: 1440:57 (#0) + lint_level: Explicit(HirId(DefId(offset_of::concrete).30)) + span: $DIR/offset_of.rs:39:5: 1455:57 (#0) } } Stmt { @@ -214,8 +214,8 @@ body: } ) else_block: None - hir_id: HirId(DefId(offset_of::concrete).40) - span: $DIR/offset_of.rs:40:5: 1440:57 (#0) + lint_level: Explicit(HirId(DefId(offset_of::concrete).40)) + span: $DIR/offset_of.rs:40:5: 1455:57 (#0) } } Stmt { @@ -263,8 +263,8 @@ body: } ) else_block: None - hir_id: HirId(DefId(offset_of::concrete).50) - span: $DIR/offset_of.rs:41:5: 1440:57 (#0) + lint_level: Explicit(HirId(DefId(offset_of::concrete).50)) + span: $DIR/offset_of.rs:41:5: 1455:57 (#0) } } ] @@ -863,8 +863,8 @@ body: } ) else_block: None - hir_id: HirId(DefId(offset_of::generic).12) - span: $DIR/offset_of.rs:45:5: 1440:57 (#0) + lint_level: Explicit(HirId(DefId(offset_of::generic).12)) + span: $DIR/offset_of.rs:45:5: 1455:57 (#0) } } Stmt { @@ -912,8 +912,8 @@ body: } ) else_block: None - hir_id: HirId(DefId(offset_of::generic).24) - span: $DIR/offset_of.rs:46:5: 1440:57 (#0) + lint_level: Explicit(HirId(DefId(offset_of::generic).24)) + span: $DIR/offset_of.rs:46:5: 1455:57 (#0) } } Stmt { @@ -961,8 +961,8 @@ body: } ) else_block: None - hir_id: HirId(DefId(offset_of::generic).36) - span: $DIR/offset_of.rs:47:5: 1440:57 (#0) + lint_level: Explicit(HirId(DefId(offset_of::generic).36)) + span: $DIR/offset_of.rs:47:5: 1455:57 (#0) } } Stmt { @@ -1010,8 +1010,8 @@ body: } ) else_block: None - hir_id: HirId(DefId(offset_of::generic).48) - span: $DIR/offset_of.rs:48:5: 1440:57 (#0) + lint_level: Explicit(HirId(DefId(offset_of::generic).48)) + span: $DIR/offset_of.rs:48:5: 1455:57 (#0) } } ]