Skip to content

Commit 5af6cf9

Browse files
committed
std: Remove the curious inner module
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.
1 parent 523ee8d commit 5af6cf9

File tree

9 files changed

+48
-63
lines changed

9 files changed

+48
-63
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/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ macro_rules! panic {
1717
);
1818
($msg:expr) => ({
1919
static _MSG_FILE_LINE: (&'static str, &'static str, u32) = ($msg, file!(), line!());
20-
::core::panicking::panic(&_MSG_FILE_LINE)
20+
$crate::panicking::panic(&_MSG_FILE_LINE)
2121
});
2222
($fmt:expr, $($arg:tt)*) => ({
2323
// The leading _'s are to avoid dead code warnings if this is
2424
// used inside a dead function. Just `#[allow(dead_code)]` is
2525
// insufficient, since the user may have
2626
// `#[forbid(dead_code)]` and which cannot be overridden.
2727
static _FILE_LINE: (&'static str, u32) = (file!(), line!());
28-
::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
28+
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
2929
});
3030
}
3131

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
@@ -421,27 +421,10 @@ pub mod __rand {
421421
// because rustdoc only looks for these modules at the crate level.
422422
include!("primitive_docs.rs");
423423

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

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)