Skip to content

Commit 7b8cf2a

Browse files
committed
Clean up and add more comments to libstd/lib.rs
1 parent 12c3427 commit 7b8cf2a

File tree

2 files changed

+70
-79
lines changed

2 files changed

+70
-79
lines changed

src/libstd/lib.rs

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,27 @@
210210
test(no_crate_inject, attr(deny(warnings))),
211211
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
212212

213+
// Don't link to std. We are std.
214+
#![no_std]
215+
216+
#![deny(missing_docs)]
217+
218+
// Tell the compiler to link to either panic_abort or panic_unwind
213219
#![needs_panic_runtime]
214220

221+
// Always use alloc_system during stage0 since jemalloc might be unavailable or
222+
// disabled (Issue #30592)
223+
#![cfg_attr(stage0, feature(alloc_system))]
224+
225+
// Turn warnings into errors, but only after stage0, where it can be useful for
226+
// code to emit warnings during language transitions
227+
#![cfg_attr(not(stage0), deny(warnings))]
228+
229+
// std may use features in a platform-specific way
230+
#![allow(unused_features)]
231+
232+
// std is implemented with unstable features, many of which are internal
233+
// compiler details that will never be stable
215234
#![feature(alloc)]
216235
#![feature(allow_internal_unstable)]
217236
#![feature(asm)]
@@ -282,21 +301,13 @@
282301
#![feature(zero_one)]
283302
#![cfg_attr(test, feature(update_panic_count))]
284303

285-
// Issue# 30592: Systematically use alloc_system during stage0 since jemalloc
286-
// might be unavailable or disabled
287-
#![cfg_attr(stage0, feature(alloc_system))]
288-
289-
// Don't link to std. We are std.
290-
#![no_std]
291-
292-
#![deny(missing_docs)]
293-
#![allow(unused_features)] // std may use features in a platform-specific way
294-
#![cfg_attr(not(stage0), deny(warnings))]
295-
304+
// Explicitly import the prelude. The compiler uses this same unstable attribute
305+
// to import the prelude implicitly when building crates that depend on std.
296306
#[prelude_import]
297307
#[allow(unused)]
298308
use prelude::v1::*;
299309

310+
// Access to Bencher, etc.
300311
#[cfg(test)] extern crate test;
301312

302313
// We want to reexport a few macros from core but libcore has already been
@@ -324,11 +335,22 @@ extern crate alloc_system;
324335
// compiler-rt intrinsics
325336
extern crate compiler_builtins;
326337

327-
// Make std testable by not duplicating lang items and other globals. See #2912
338+
// During testing, this crate is not actually the "real" std library, but rather
339+
// it links to the real std library, which was compiled from this same source
340+
// code. So any lang items std defines are conditionally excluded (or else they
341+
// wolud generate duplicate lang item errors), and any globals it defines are
342+
// _not_ the globals used by "real" std. So this import, defined only during
343+
// testing gives test-std access to real-std lang items and globals. See #2912
328344
#[cfg(test)] extern crate std as realstd;
329345

330-
// NB: These reexports are in the order they should be listed in rustdoc
346+
// The standard macros that are not built-in to the compiler.
347+
#[macro_use]
348+
mod macros;
349+
350+
// The Rust prelude
351+
pub mod prelude;
331352

353+
// Public module declarations and reexports
332354
#[stable(feature = "rust1", since = "1.0.0")]
333355
pub use core::any;
334356
#[stable(feature = "rust1", since = "1.0.0")]
@@ -361,48 +383,6 @@ pub use core::raw;
361383
pub use core::result;
362384
#[stable(feature = "rust1", since = "1.0.0")]
363385
pub use core::option;
364-
365-
pub mod error;
366-
367-
#[stable(feature = "rust1", since = "1.0.0")]
368-
pub use alloc::boxed;
369-
#[stable(feature = "rust1", since = "1.0.0")]
370-
pub use alloc::rc;
371-
372-
#[stable(feature = "rust1", since = "1.0.0")]
373-
pub use core_collections::borrow;
374-
#[stable(feature = "rust1", since = "1.0.0")]
375-
pub use core_collections::fmt;
376-
#[stable(feature = "rust1", since = "1.0.0")]
377-
pub use core_collections::slice;
378-
#[stable(feature = "rust1", since = "1.0.0")]
379-
pub use core_collections::str;
380-
#[stable(feature = "rust1", since = "1.0.0")]
381-
pub use core_collections::string;
382-
#[stable(feature = "rust1", since = "1.0.0")]
383-
pub use core_collections::vec;
384-
385-
#[stable(feature = "rust1", since = "1.0.0")]
386-
pub use rustc_unicode::char;
387-
388-
/* Exported macros */
389-
390-
#[macro_use]
391-
mod macros;
392-
393-
mod rtdeps;
394-
395-
/* The Prelude. */
396-
397-
pub mod prelude;
398-
399-
400-
/* Primitive types */
401-
402-
// NB: slice and str are primitive types too, but their module docs + primitive
403-
// doc pages are inlined from the public re-exports of core_collections::{slice,
404-
// str} above.
405-
406386
#[stable(feature = "rust1", since = "1.0.0")]
407387
pub use core::isize;
408388
#[stable(feature = "rust1", since = "1.0.0")]
@@ -413,7 +393,6 @@ pub use core::i16;
413393
pub use core::i32;
414394
#[stable(feature = "rust1", since = "1.0.0")]
415395
pub use core::i64;
416-
417396
#[stable(feature = "rust1", since = "1.0.0")]
418397
pub use core::usize;
419398
#[stable(feature = "rust1", since = "1.0.0")]
@@ -424,42 +403,62 @@ pub use core::u16;
424403
pub use core::u32;
425404
#[stable(feature = "rust1", since = "1.0.0")]
426405
pub use core::u64;
406+
#[stable(feature = "rust1", since = "1.0.0")]
407+
pub use alloc::boxed;
408+
#[stable(feature = "rust1", since = "1.0.0")]
409+
pub use alloc::rc;
410+
#[stable(feature = "rust1", since = "1.0.0")]
411+
pub use core_collections::borrow;
412+
#[stable(feature = "rust1", since = "1.0.0")]
413+
pub use core_collections::fmt;
414+
#[stable(feature = "rust1", since = "1.0.0")]
415+
pub use core_collections::slice;
416+
#[stable(feature = "rust1", since = "1.0.0")]
417+
pub use core_collections::str;
418+
#[stable(feature = "rust1", since = "1.0.0")]
419+
pub use core_collections::string;
420+
#[stable(feature = "rust1", since = "1.0.0")]
421+
pub use core_collections::vec;
422+
#[stable(feature = "rust1", since = "1.0.0")]
423+
pub use rustc_unicode::char;
427424

428425
#[path = "num/f32.rs"] pub mod f32;
429426
#[path = "num/f64.rs"] pub mod f64;
430427

431-
pub mod ascii;
432-
433-
/* Common traits */
434-
435-
pub mod num;
436-
437-
/* Runtime and platform support */
438-
439428
#[macro_use]
440429
pub mod thread;
441-
430+
pub mod ascii;
442431
pub mod collections;
443432
pub mod env;
433+
pub mod error;
444434
pub mod ffi;
445435
pub mod fs;
446436
pub mod io;
447437
pub mod net;
438+
pub mod num;
448439
pub mod os;
449440
pub mod panic;
450441
pub mod path;
451442
pub mod process;
452443
pub mod sync;
453444
pub mod time;
454-
mod memchr;
455445

446+
// Platform-abstraction modules
456447
#[macro_use]
457448
mod sys_common;
458449
mod sys;
459450

460-
pub mod rt;
451+
// Private support modules
461452
mod panicking;
462453
mod rand;
454+
mod memchr;
455+
456+
// This module just defines per-platform native library dependencies
457+
mod rtdeps;
458+
459+
// The runtime entry point and a few unstable public functions used by the
460+
// compiler
461+
pub mod rt;
463462

464463
// Some external utilities of the standard library rely on randomness (aka
465464
// rustc_back::TempDir and tests) and need a way to get at the OS rng we've got

src/libstd/sys_common/mod.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,6 @@
2727
use sync::Once;
2828
use sys;
2929

30-
macro_rules! rtabort {
31-
($($t:tt)*) => (::sys_common::util::abort(format_args!($($t)*)))
32-
}
33-
34-
macro_rules! rtassert {
35-
($e:expr) => ({
36-
if !$e {
37-
rtabort!(concat!("assertion failed: ", stringify!($e)))
38-
}
39-
})
40-
}
41-
4230
pub mod at_exit_imp;
4331
#[cfg(any(not(cargobuild), feature = "backtrace"))]
4432
pub mod backtrace;
@@ -101,6 +89,10 @@ pub fn at_exit<F: FnOnce() + Send + 'static>(f: F) -> Result<(), ()> {
10189
if at_exit_imp::push(Box::new(f)) {Ok(())} else {Err(())}
10290
}
10391

92+
macro_rules! rtabort {
93+
($($t:tt)*) => (::sys_common::util::abort(format_args!($($t)*)))
94+
}
95+
10496
/// One-time runtime cleanup.
10597
pub fn cleanup() {
10698
static CLEANUP: Once = Once::new();

0 commit comments

Comments
 (0)