From 939ee383043dce00c108c22f1e933f1e052f3f3d Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 18 Jul 2024 17:33:52 +0000 Subject: Make `Thread::new_inner` a safe function --- library/std/src/thread/mod.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'library/std/src') diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 87d5c2f742c..13b02cd8d3a 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1337,21 +1337,19 @@ pub struct Thread { impl Thread { /// Used only internally to construct a thread object without spawning. pub(crate) fn new(name: ThreadNameString) -> Thread { - unsafe { Self::new_inner(ThreadName::Other(name)) } + Self::new_inner(ThreadName::Other(name)) } pub(crate) fn new_unnamed() -> Thread { - unsafe { Self::new_inner(ThreadName::Unnamed) } + Self::new_inner(ThreadName::Unnamed) } // Used in runtime to construct main thread pub(crate) fn new_main() -> Thread { - unsafe { Self::new_inner(ThreadName::Main) } + Self::new_inner(ThreadName::Main) } - /// # Safety - /// If `name` is `ThreadName::Other(_)`, the contained string must be valid UTF-8. - unsafe fn new_inner(name: ThreadName) -> Thread { + fn new_inner(name: ThreadName) -> Thread { // We have to use `unsafe` here to construct the `Parker` in-place, // which is required for the UNIX implementation. // -- cgit 1.4.1-3-g733a5