From b1b87ffdbc24e3928bf0aa4c766cd731ebbc641e Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Thu, 12 Mar 2026 12:35:39 -0700 Subject: [PATCH 1/2] Add overview documentation for `std::mem`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I heard that `std::mem` sounds scary to some people, and how it’s described — “Basic functions for dealing with memory” — sounds even to me like something that should be avoided, not even because it would be unsafe, but because it is too low-level. Let’s fix that by telling people about what they can actually find in the module, without having to read all the individual item descriptions. --- library/core/src/mem/mod.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index d8521e79006e3..b321908fd9e77 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -1,7 +1,32 @@ -//! Basic functions for dealing with memory. +//! Basic functions for dealing with memory, values, and types. //! -//! This module contains functions for querying the size and alignment of -//! types, initializing and manipulating memory. +//! The contents of this module can be seen as belonging to a few families: +//! +//! * [`drop`], [`replace`], [`swap`], and [`take`] +//! are safe functions for moving values in particular ways. +//! They are useful in everyday Rust code. +//! +//! * [`size_of`], [`size_of_val`], [`align_of`], [`align_of_val`], and [`offset_of`] +//! give information about the representation of values in memory. +//! +//! * [`discriminant`] +//! allows comparing the variants of [`enum`] values while ignoring their fields. +//! +//! * [`forget`] and [`ManuallyDrop`] +//! prevent destructors from running, which is used in certain kinds of ownership transfer. +//! [`needs_drop`] +//! tells you whether a type’s destructor even does anything. +//! +//! * [`transmute`], [`transmute_copy`], and [`MaybeUninit`] +//! convert and construct values in [`unsafe`] ways. +//! +//! See also the [`alloc`] and [`ptr`] modules for more primitive operations on memory. +//! +// core::alloc exists but doesn’t contain all the items we want to discuss +//! [`alloc`]: ../../std/alloc/index.html +//! [`enum`]: ../../std/keyword.enum.html +//! [`ptr`]: crate::ptr +//! [`unsafe`]: ../../std/keyword.unsafe.html #![stable(feature = "rust1", since = "1.0.0")] From 6dcb85d55db58f6417aa64256db441425d552dbd Mon Sep 17 00:00:00 2001 From: cyrgani Date: Sun, 15 Mar 2026 20:21:47 +0000 Subject: [PATCH 2/2] remove several redundant tests --- tests/ui/binding/match-naked-record.rs | 12 -------- tests/ui/issues/issue-4830.rs | 10 ------- tests/ui/issues/issue-5192.rs | 38 -------------------------- tests/ui/macros/unreachable.rs | 7 ----- tests/ui/moves/array-copy-move.rs | 8 ------ 5 files changed, 75 deletions(-) delete mode 100644 tests/ui/binding/match-naked-record.rs delete mode 100644 tests/ui/issues/issue-4830.rs delete mode 100644 tests/ui/issues/issue-5192.rs delete mode 100644 tests/ui/macros/unreachable.rs delete mode 100644 tests/ui/moves/array-copy-move.rs diff --git a/tests/ui/binding/match-naked-record.rs b/tests/ui/binding/match-naked-record.rs deleted file mode 100644 index ce9489a00f2c6..0000000000000 --- a/tests/ui/binding/match-naked-record.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ run-pass -#![allow(dead_code)] - -struct X { x: isize } - -pub fn main() { - let _x = match 0 { - _ => X { - x: 0 - } - }; -} diff --git a/tests/ui/issues/issue-4830.rs b/tests/ui/issues/issue-4830.rs deleted file mode 100644 index d48c13fd10b1d..0000000000000 --- a/tests/ui/issues/issue-4830.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ check-pass -#![allow(dead_code)] - - -pub struct Scheduler { - /// The event loop used to drive the scheduler and perform I/O - event_loop: Box -} - -pub fn main() { } diff --git a/tests/ui/issues/issue-5192.rs b/tests/ui/issues/issue-5192.rs deleted file mode 100644 index be5d70f09b3c0..0000000000000 --- a/tests/ui/issues/issue-5192.rs +++ /dev/null @@ -1,38 +0,0 @@ -//@ run-pass -#![allow(dead_code)] - -pub trait EventLoop { - fn dummy(&self) { } -} - -pub struct UvEventLoop { - uvio: isize -} - -impl UvEventLoop { - pub fn new() -> UvEventLoop { - UvEventLoop { - uvio: 0 - } - } -} - -impl EventLoop for UvEventLoop { -} - -pub struct Scheduler { - event_loop: Box, -} - -impl Scheduler { - - pub fn new(event_loop: Box) -> Scheduler { - Scheduler { - event_loop: event_loop, - } - } -} - -pub fn main() { - let _sched = Scheduler::new(Box::new(UvEventLoop::new()) as Box); -} diff --git a/tests/ui/macros/unreachable.rs b/tests/ui/macros/unreachable.rs deleted file mode 100644 index c5cea5551cfcf..0000000000000 --- a/tests/ui/macros/unreachable.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ run-fail -//@ error-pattern:internal error: entered unreachable code -//@ needs-subprocess - -fn main() { - unreachable!() -} diff --git a/tests/ui/moves/array-copy-move.rs b/tests/ui/moves/array-copy-move.rs deleted file mode 100644 index ea95bc06a3693..0000000000000 --- a/tests/ui/moves/array-copy-move.rs +++ /dev/null @@ -1,8 +0,0 @@ -//! regression test for issue https://github.com/rust-lang/rust/issues/16783 -//@ run-pass -#![allow(unused_variables)] - -pub fn main() { - let x = [1, 2, 3]; - let y = x; -}