Skip to content

Commit 6edc994

Browse files
committed
Auto merge of #27388 - alexcrichton:remove-curious-inner, r=brson
This isn't actually necessary any more with the advent of `$crate` and changes in the compiler to expand macros to `::core::$foo` in the context of a `#![no_std]` crate. The libcore inner module was also trimmed down a bit to the bare bones.
2 parents 28869d4 + 5af6cf9 commit 6edc994

File tree

8 files changed

+46
-61
lines changed

8 files changed

+46
-61
lines changed

src/libcore/lib.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,23 @@ pub mod fmt;
157157
// note: does not need to be public
158158
mod tuple;
159159

160+
// A curious inner-module that's not exported that contains the bindings of core
161+
// so that compiler-expanded references to `core::$foo` can be resolved within
162+
// core itself.
163+
//
164+
// Note that no crate-defined macros require this module due to the existence of
165+
// the `$crate` meta variable, only those expansions defined in the compiler
166+
// require this. This is because the compiler doesn't currently know that it's
167+
// compiling the core library when it's compiling this library, so it expands
168+
// all references to `::core::$foo`
160169
#[doc(hidden)]
161170
mod core {
162-
pub use intrinsics;
163-
pub use panicking;
164-
pub use fmt;
165-
pub use clone;
166-
pub use cmp;
167-
pub use hash;
168-
pub use marker;
169-
pub use option;
170-
pub use iter;
171-
}
172-
173-
#[doc(hidden)]
174-
mod std {
175-
// range syntax
176-
pub use ops;
171+
pub use intrinsics; // derive(PartialOrd)
172+
pub use fmt; // format_args!
173+
pub use clone; // derive(Clone)
174+
pub use cmp; // derive(Ord)
175+
pub use hash; // derive(Hash)
176+
pub use marker; // derive(Copy)
177+
pub use option; // iterator protocol
178+
pub use iter; // iterator protocol
177179
}

src/libcore/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use mem;
2020
use clone::Clone;
2121
use intrinsics;
2222
use ops::Deref;
23-
use core::fmt;
23+
use fmt;
2424
use option::Option::{self, Some, None};
2525
use marker::{PhantomData, Send, Sized, Sync};
2626
use nonzero::NonZero;

src/libcore/str/pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
reason = "API not fully fleshed out and ready to be stabilized")]
1818

1919
use prelude::*;
20-
use core::cmp;
20+
use cmp;
2121
use usize;
2222

2323
// Pattern

src/libstd/lib.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -416,27 +416,10 @@ pub mod __rand {
416416
// because rustdoc only looks for these modules at the crate level.
417417
include!("primitive_docs.rs");
418418

419-
// A curious inner-module that's not exported that contains the binding
420-
// 'std' so that macro-expanded references to std::error and such
421-
// can be resolved within libstd.
422-
#[doc(hidden)]
419+
// The expansion of --test has a few references to `::std::$foo` so this module
420+
// is necessary to get things to compile.
421+
#[cfg(test)]
423422
mod std {
424-
pub use sync; // used for select!()
425-
pub use error; // used for try!()
426-
pub use fmt; // used for any formatting strings
427-
pub use option; // used for thread_local!{}
428-
pub use rt; // used for panic!()
429-
pub use vec; // used for vec![]
430-
pub use cell; // used for tls!
431-
pub use thread; // used for thread_local!
432-
pub use marker; // used for tls!
433-
434-
// The test runner calls ::std::env::args() but really wants realstd
435-
#[cfg(test)] pub use realstd::env as env;
436-
// The test runner requires std::slice::Vector, so re-export std::slice just for it.
437-
//
438-
// It is also used in vec![]
439-
pub use slice;
440-
441-
pub use boxed; // used for vec![]
423+
pub use option;
424+
pub use realstd::env;
442425
}

src/libstd/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ mod tests {
799799
#[cfg(not(target_os="android"))]
800800
#[test]
801801
fn test_inherit_env() {
802-
use std::env;
802+
use env;
803803

804804
let result = env_cmd().output().unwrap();
805805
let output = String::from_utf8(result.stdout).unwrap();

src/libstd/sync/mpsc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ impl error::Error for TryRecvError {
11071107
mod tests {
11081108
use prelude::v1::*;
11091109

1110-
use std::env;
1110+
use env;
11111111
use super::*;
11121112
use thread;
11131113

@@ -1655,7 +1655,7 @@ mod tests {
16551655
mod sync_tests {
16561656
use prelude::v1::*;
16571657

1658-
use std::env;
1658+
use env;
16591659
use thread;
16601660
use super::*;
16611661

src/libstd/thread/local.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ pub struct LocalKey<T> {
107107
#[cfg(not(no_elf_tls))]
108108
macro_rules! thread_local {
109109
(static $name:ident: $t:ty = $init:expr) => (
110-
static $name: ::std::thread::LocalKey<$t> =
110+
static $name: $crate::thread::LocalKey<$t> =
111111
__thread_local_inner!($t, $init,
112112
#[cfg_attr(all(any(target_os = "macos", target_os = "linux"),
113113
not(target_arch = "aarch64")),
114114
thread_local)]);
115115
);
116116
(pub static $name:ident: $t:ty = $init:expr) => (
117-
pub static $name: ::std::thread::LocalKey<$t> =
117+
pub static $name: $crate::thread::LocalKey<$t> =
118118
__thread_local_inner!($t, $init,
119119
#[cfg_attr(all(any(target_os = "macos", target_os = "linux"),
120120
not(target_arch = "aarch64")),
@@ -128,11 +128,11 @@ macro_rules! thread_local {
128128
#[cfg(no_elf_tls)]
129129
macro_rules! thread_local {
130130
(static $name:ident: $t:ty = $init:expr) => (
131-
static $name: ::std::thread::LocalKey<$t> =
131+
static $name: $crate::thread::LocalKey<$t> =
132132
__thread_local_inner!($t, $init, #[]);
133133
);
134134
(pub static $name:ident: $t:ty = $init:expr) => (
135-
pub static $name: ::std::thread::LocalKey<$t> =
135+
pub static $name: $crate::thread::LocalKey<$t> =
136136
__thread_local_inner!($t, $init, #[]);
137137
);
138138
}
@@ -145,11 +145,11 @@ macro_rules! thread_local {
145145
macro_rules! __thread_local_inner {
146146
($t:ty, $init:expr, #[$($attr:meta),*]) => {{
147147
$(#[$attr])*
148-
static __KEY: ::std::thread::__LocalKeyInner<$t> =
149-
::std::thread::__LocalKeyInner::new();
148+
static __KEY: $crate::thread::__LocalKeyInner<$t> =
149+
$crate::thread::__LocalKeyInner::new();
150150
fn __init() -> $t { $init }
151-
fn __getit() -> &'static ::std::thread::__LocalKeyInner<$t> { &__KEY }
152-
::std::thread::LocalKey::new(__getit, __init)
151+
fn __getit() -> &'static $crate::thread::__LocalKeyInner<$t> { &__KEY }
152+
$crate::thread::LocalKey::new(__getit, __init)
153153
}}
154154
}
155155

src/libstd/thread/scoped_tls.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ pub struct ScopedKey<T> { inner: fn() -> &'static imp::KeyInner<T> }
7070
#[allow_internal_unstable]
7171
macro_rules! scoped_thread_local {
7272
(static $name:ident: $t:ty) => (
73-
static $name: ::std::thread::ScopedKey<$t> =
73+
static $name: $crate::thread::ScopedKey<$t> =
7474
__scoped_thread_local_inner!($t);
7575
);
7676
(pub static $name:ident: $t:ty) => (
77-
pub static $name: ::std::thread::ScopedKey<$t> =
77+
pub static $name: $crate::thread::ScopedKey<$t> =
7878
__scoped_thread_local_inner!($t);
7979
);
8080
}
@@ -87,10 +87,10 @@ macro_rules! scoped_thread_local {
8787
#[cfg(no_elf_tls)]
8888
macro_rules! __scoped_thread_local_inner {
8989
($t:ty) => {{
90-
static _KEY: ::std::thread::__ScopedKeyInner<$t> =
91-
::std::thread::__ScopedKeyInner::new();
92-
fn _getit() -> &'static ::std::thread::__ScopedKeyInner<$t> { &_KEY }
93-
::std::thread::ScopedKey::new(_getit)
90+
static _KEY: $crate::thread::__ScopedKeyInner<$t> =
91+
$crate::thread::__ScopedKeyInner::new();
92+
fn _getit() -> &'static $crate::thread::__ScopedKeyInner<$t> { &_KEY }
93+
$crate::thread::ScopedKey::new(_getit)
9494
}}
9595
}
9696

@@ -109,10 +109,10 @@ macro_rules! __scoped_thread_local_inner {
109109
target_os = "openbsd",
110110
target_arch = "aarch64")),
111111
thread_local)]
112-
static _KEY: ::std::thread::__ScopedKeyInner<$t> =
113-
::std::thread::__ScopedKeyInner::new();
114-
fn _getit() -> &'static ::std::thread::__ScopedKeyInner<$t> { &_KEY }
115-
::std::thread::ScopedKey::new(_getit)
112+
static _KEY: $crate::thread::__ScopedKeyInner<$t> =
113+
$crate::thread::__ScopedKeyInner::new();
114+
fn _getit() -> &'static $crate::thread::__ScopedKeyInner<$t> { &_KEY }
115+
$crate::thread::ScopedKey::new(_getit)
116116
}}
117117
}
118118

@@ -225,7 +225,7 @@ impl<T> ScopedKey<T> {
225225
no_elf_tls)))]
226226
#[doc(hidden)]
227227
mod imp {
228-
use std::cell::Cell;
228+
use cell::Cell;
229229

230230
pub struct KeyInner<T> { inner: Cell<*mut T> }
231231

0 commit comments

Comments
 (0)