diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-03-17 08:49:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-17 08:49:02 -0400 |
| commit | d7a09d4e655871671a6c94c05a506ae3626ce528 (patch) | |
| tree | 919699b2faad4565554047dce25bcfee522346b6 /src/libstd | |
| parent | 5aab3b97af7691636928b35350a46b393f0d6d5a (diff) | |
| parent | 1545f4e2a323eb869b13f36bd05cc91ff21d5161 (diff) | |
| download | rust-d7a09d4e655871671a6c94c05a506ae3626ce528.tar.gz rust-d7a09d4e655871671a6c94c05a506ae3626ce528.zip | |
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 ```
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/rt.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys_common/thread_info.rs | 7 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 7 |
3 files changed, 4 insertions, 14 deletions
diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index 78d5aa597ba..6c791cd336d 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -34,7 +34,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { use panic; use sys; use sys_common; - use sys_common::thread_info::{self, NewThread}; + use sys_common::thread_info; use thread::Thread; sys::init(); @@ -47,7 +47,7 @@ fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { // created. Note that this isn't necessary in general for new threads, // but we just do this to name the main thread and to give it correct // info about the stack bounds. - let thread: Thread = NewThread::new(Some("main".to_owned())); + let thread = Thread::new(Some("main".to_owned())); thread_info::set(main_guard, thread); // Store our args if necessary in a squirreled away location diff --git a/src/libstd/sys_common/thread_info.rs b/src/libstd/sys_common/thread_info.rs index 95d8b6cc951..5ed48ee4558 100644 --- a/src/libstd/sys_common/thread_info.rs +++ b/src/libstd/sys_common/thread_info.rs @@ -31,7 +31,7 @@ impl ThreadInfo { if c.borrow().is_none() { *c.borrow_mut() = Some(ThreadInfo { stack_guard: None, - thread: NewThread::new(None), + thread: Thread::new(None), }) } Some(f(c.borrow_mut().as_mut().unwrap())) @@ -54,8 +54,3 @@ pub fn set(stack_guard: Option<usize>, thread: Thread) { thread: thread, })); } - -// a hack to get around privacy restrictions; implemented by `std::thread` -pub trait NewThread { - fn new(name: Option<String>) -> Self; -} diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 64c2be25222..edf928d6106 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -745,7 +745,7 @@ pub struct Thread { impl Thread { // Used only internally to construct a thread object without spawning - fn new(name: Option<String>) -> Thread { + pub(crate) fn new(name: Option<String>) -> Thread { let cname = name.map(|n| { CString::new(n).expect("thread name may not contain interior null bytes") }); @@ -858,11 +858,6 @@ impl fmt::Debug for Thread { } } -// a hack to get around privacy restrictions -impl thread_info::NewThread for Thread { - fn new(name: Option<String>) -> Thread { Thread::new(name) } -} - //////////////////////////////////////////////////////////////////////////////// // JoinHandle //////////////////////////////////////////////////////////////////////////////// |
