Skip to content

Commit c251884

Browse files
committed
Clean up and add more comments to libstd/lib.rs
1 parent 8f5bb1f commit c251884

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)]
@@ -283,21 +302,13 @@
283302
#![feature(zero_one)]
284303
#![cfg_attr(test, feature(update_panic_count))]
285304

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

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

303314
// We want to reexport a few macros from core but libcore has already been
@@ -325,11 +336,22 @@ extern crate alloc_system;
325336
// compiler-rt intrinsics
326337
extern crate compiler_builtins;
327338

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

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

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

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

432-
pub mod ascii;
433-
434-
/* Common traits */
435-
436-
pub mod num;
437-
438-
/* Runtime and platform support */
439-
440429
#[macro_use]
441430
pub mod thread;
442-
431+
pub mod ascii;
443432
pub mod collections;
444433
pub mod env;
434+
pub mod error;
445435
pub mod ffi;
446436
pub mod fs;
447437
pub mod io;
448438
pub mod net;
439+
pub mod num;
449440
pub mod os;
450441
pub mod panic;
451442
pub mod path;
452443
pub mod process;
453444
pub mod sync;
454445
pub mod time;
455-
mod memchr;
456446

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

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

465464
// Some external utilities of the standard library rely on randomness (aka
466465
// 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)