Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
363addc
Gate repr(Rust) correctly on non-ADT items
compiler-errors Aug 22, 2024
6b0fc97
Win: Open dir for sync access in remove_dir_all
ChrisDenton Sep 3, 2024
d0a2ca4
Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut`
ChayimFriedman2 Aug 20, 2024
0fa92b4
add `Thread::{into_raw, from_raw}`
ibraheemdev Jul 12, 2022
96a3b48
Clarify docs for std::fs::File::write
shekhirin Sep 18, 2024
a18564c
[Clippy] Swap `manual_retain` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
bd8e88f
Do not ICE with incorrect empty suggestion
estebank Jul 19, 2024
682c5f4
Explicitly mark a hack as a HACK and elaborate its comment
fmease Sep 18, 2024
d9cdb71
library: Destabilize Lazy{Cell,Lock}::{force,deref}_mut
workingjubilee Sep 17, 2024
f22797d
library: Call it really_init_mut to avoid name collisions
workingjubilee Sep 18, 2024
0cf89b5
compiler: Use make_indirect for the wasm ABI
workingjubilee Sep 16, 2024
a800d1c
compiler: s/make_indirect_byval/pass_by_stack_offset/
workingjubilee Sep 16, 2024
b75711d
tests: Remove test for wrong wasm codegen
workingjubilee Sep 16, 2024
51718e8
tests: Move wasm32 to transparent-opaque-ptr.rs test
workingjubilee Sep 17, 2024
6fd8a50
Update the minimum external LLVM to 18
cuviper Sep 17, 2024
8bab397
Revert "Add a hack to prevent proc_macro misopt in CI"
cuviper Sep 18, 2024
4722ad1
Rollup merge of #97524 - ibraheemdev:thread-raw, r=ibraheemdev
workingjubilee Sep 18, 2024
2a1dd35
Rollup merge of #127988 - estebank:dupe-derive-params, r=fmease
workingjubilee Sep 18, 2024
2eb65a6
Rollup merge of #129422 - compiler-errors:repr-rust, r=fmease
workingjubilee Sep 18, 2024
591ec6c
Rollup merge of #129934 - ChrisDenton:remove-dir-all3, r=Amanieu
workingjubilee Sep 18, 2024
b33dd7d
Rollup merge of #130450 - workingjubilee:these-names-are-indirect, r=…
workingjubilee Sep 18, 2024
12b59e5
Rollup merge of #130476 - workingjubilee:more-lazy-methods-take-2, r=…
workingjubilee Sep 18, 2024
d972605
Rollup merge of #130487 - cuviper:min-llvm-18, r=nikic
workingjubilee Sep 18, 2024
4d9ce4b
Rollup merge of #130513 - shekhirin:fs-write-doc-comment, r=cuviper
workingjubilee Sep 18, 2024
4bd9de5
Rollup merge of #130522 - GnomedDev:clippy-manual-retain-paths, r=com…
workingjubilee Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,54 @@ impl Thread {
self.inner.name.as_str()
}

/// Consumes the `Thread`, returning a raw pointer.
///
/// To avoid a memory leak the pointer must be converted
/// back into a `Thread` using [`Thread::from_raw`].
///
/// # Examples
///
/// ```
/// #![feature(thread_raw)]
///
/// use std::thread::{self, Thread};
///
/// let thread = thread::current();
/// let id = thread.id();
/// let ptr = Thread::into_raw(thread);
/// unsafe {
/// assert_eq!(Thread::from_raw(ptr).id(), id);
/// }
/// ```
#[unstable(feature = "thread_raw", issue = "97523")]
pub fn into_raw(self) -> *const () {
// Safety: We only expose an opaque pointer, which maintains the `Pin` invariant.
let inner = unsafe { Pin::into_inner_unchecked(self.inner) };
Arc::into_raw(inner) as *const ()
}

/// Constructs a `Thread` from a raw pointer.
///
/// The raw pointer must have been previously returned
/// by a call to [`Thread::into_raw`].
///
/// # Safety
///
/// This function is unsafe because improper use may lead
/// to memory unsafety, even if the returned `Thread` is never
/// accessed.
///
/// Creating a `Thread` from a pointer other than one returned
/// from [`Thread::into_raw`] is **undefined behavior**.
///
/// Calling this function twice on the same raw pointer can lead
/// to a double-free if both `Thread` instances are dropped.
#[unstable(feature = "thread_raw", issue = "97523")]
pub unsafe fn from_raw(ptr: *const ()) -> Thread {
// Safety: Upheld by caller.
unsafe { Thread { inner: Pin::new_unchecked(Arc::from_raw(ptr as *const Inner)) } }
}

fn cname(&self) -> Option<&CStr> {
self.inner.name.as_cstr()
}
Expand Down