Skip to content

Commit fc1bb24

Browse files
authored
Rollup merge of #40503 - swgillespie:thread-hack-removal, r=sfackler
std: remove a workaround for privacy limitations `std::thread::Thread` implements a non-exported `NewThread` trait to allow for internal-only use of `Thread::new`. Nowadays we have `pub(crate)`, which accomplishes the same thing but much more idiomatically. Rustdoc handles this correctly (I checked and I didn't see `Thread::new` on the rustdoc entry for `Thread` with this change), and the stage1 `rustc` emits the correct error still (I'm assuming that the stage1 compiler uses my `libstd`?): ``` $ ./build/x86_64-apple-darwin/stage1/bin/rustc test.rs error: method `new` is private --> test.rs:4:18 | 4 | let thread = thread::Thread::new(None); | ^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error ```
2 parents 9f2e520 + 1545f4e commit fc1bb24

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

src/libstd/rt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize {
3434
use panic;
3535
use sys;
3636
use sys_common;
37-
use sys_common::thread_info::{self, NewThread};
37+
use sys_common::thread_info;
3838
use thread::Thread;
3939

4040
sys::init();
@@ -47,7 +47,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize {
4747
// created. Note that this isn't necessary in general for new threads,
4848
// but we just do this to name the main thread and to give it correct
4949
// info about the stack bounds.
50-
let thread: Thread = NewThread::new(Some("main".to_owned()));
50+
let thread = Thread::new(Some("main".to_owned()));
5151
thread_info::set(main_guard, thread);
5252

5353
// Store our args if necessary in a squirreled away location

src/libstd/sys_common/thread_info.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl ThreadInfo {
3131
if c.borrow().is_none() {
3232
*c.borrow_mut() = Some(ThreadInfo {
3333
stack_guard: None,
34-
thread: NewThread::new(None),
34+
thread: Thread::new(None),
3535
})
3636
}
3737
Some(f(c.borrow_mut().as_mut().unwrap()))
@@ -54,8 +54,3 @@ pub fn set(stack_guard: Option<usize>, thread: Thread) {
5454
thread: thread,
5555
}));
5656
}
57-
58-
// a hack to get around privacy restrictions; implemented by `std::thread`
59-
pub trait NewThread {
60-
fn new(name: Option<String>) -> Self;
61-
}

src/libstd/thread/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ pub struct Thread {
745745

746746
impl Thread {
747747
// Used only internally to construct a thread object without spawning
748-
fn new(name: Option<String>) -> Thread {
748+
pub(crate) fn new(name: Option<String>) -> Thread {
749749
let cname = name.map(|n| {
750750
CString::new(n).expect("thread name may not contain interior null bytes")
751751
});
@@ -858,11 +858,6 @@ impl fmt::Debug for Thread {
858858
}
859859
}
860860

861-
// a hack to get around privacy restrictions
862-
impl thread_info::NewThread for Thread {
863-
fn new(name: Option<String>) -> Thread { Thread::new(name) }
864-
}
865-
866861
////////////////////////////////////////////////////////////////////////////////
867862
// JoinHandle
868863
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)