Skip to content

Commit 3026204

Browse files
authored
Rollup merge of rust-lang#123867 - eduardosm:unsafe-fns, r=ChrisDenton
Add `unsafe` to two functions with safety invariants
2 parents b5c3db1 + a6ed319 commit 3026204

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Diff for: library/std/src/sys/pal/windows/thread.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,31 @@ impl Thread {
4545
Err(io::Error::last_os_error())
4646
};
4747

48-
extern "system" fn thread_start(main: *mut c_void) -> c::DWORD {
49-
unsafe {
50-
// Next, reserve some stack space for if we otherwise run out of stack.
51-
stack_overflow::reserve_stack();
52-
// Finally, let's run some code.
53-
Box::from_raw(main as *mut Box<dyn FnOnce()>)();
54-
}
48+
unsafe extern "system" fn thread_start(main: *mut c_void) -> c::DWORD {
49+
// Next, reserve some stack space for if we otherwise run out of stack.
50+
stack_overflow::reserve_stack();
51+
// Finally, let's run some code.
52+
Box::from_raw(main as *mut Box<dyn FnOnce()>)();
5553
0
5654
}
5755
}
5856

5957
pub fn set_name(name: &CStr) {
6058
if let Ok(utf8) = name.to_str() {
6159
if let Ok(utf16) = to_u16s(utf8) {
62-
Self::set_name_wide(&utf16)
60+
unsafe {
61+
// SAFETY: the vec returned by `to_u16s` ends with a zero value
62+
Self::set_name_wide(&utf16)
63+
}
6364
};
6465
};
6566
}
6667

67-
pub fn set_name_wide(name: &[u16]) {
68-
unsafe {
69-
c::SetThreadDescription(c::GetCurrentThread(), name.as_ptr());
70-
};
68+
/// # Safety
69+
///
70+
/// `name` must end with a zero value
71+
pub unsafe fn set_name_wide(name: &[u16]) {
72+
c::SetThreadDescription(c::GetCurrentThread(), name.as_ptr());
7173
}
7274

7375
pub fn join(self) {

0 commit comments

Comments
 (0)