Skip to content
88 changes: 15 additions & 73 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ macro_rules! book {
builder.ensure(RustbookSrc {
target: self.target,
name: INTERNER.intern_str($book_name),
src: doc_src(builder),
src: INTERNER.intern_path(builder.src.join($path)),
})
}
}
Expand All @@ -60,6 +60,7 @@ macro_rules! book {
// NOTE: When adding a book here, make sure to ALSO build the book by
// adding a build step in `src/bootstrap/builder.rs`!
book!(
CargoBook, "src/tools/cargo/src/doc", "cargo";
EditionGuide, "src/doc/edition-guide", "edition-guide";
EmbeddedBook, "src/doc/embedded-book", "embedded-book";
Nomicon, "src/doc/nomicon", "nomicon";
Expand All @@ -69,10 +70,6 @@ book!(
RustdocBook, "src/doc/rustdoc", "rustdoc";
);

fn doc_src(builder: &Builder<'_>) -> Interned<PathBuf> {
INTERNER.intern_path(builder.src.join("src/doc"))
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct UnstableBook {
target: Interned<String>,
Expand All @@ -96,48 +93,11 @@ impl Step for UnstableBook {
builder.ensure(RustbookSrc {
target: self.target,
name: INTERNER.intern_str("unstable-book"),
src: builder.md_doc_out(self.target),
src: INTERNER.intern_path(builder.md_doc_out(self.target).join("unstable-book")),
})
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct CargoBook {
target: Interned<String>,
name: Interned<String>,
}

impl Step for CargoBook {
type Output = ();
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
run.path("src/tools/cargo/src/doc/book").default_condition(builder.config.docs)
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(CargoBook { target: run.target, name: INTERNER.intern_str("cargo") });
}

fn run(self, builder: &Builder<'_>) {
let target = self.target;
let name = self.name;
let src = builder.src.join("src/tools/cargo/src/doc");

let out = builder.doc_out(target);
t!(fs::create_dir_all(&out));

let out = out.join(name);

builder.info(&format!("Cargo Book ({}) - {}", target, name));

let _ = fs::remove_dir_all(&out);

builder.run(builder.tool_cmd(Tool::Rustbook).arg("build").arg(&src).arg("-d").arg(out));
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
struct RustbookSrc {
target: Interned<String>,
Expand All @@ -164,7 +124,6 @@ impl Step for RustbookSrc {
t!(fs::create_dir_all(&out));

let out = out.join(name);
let src = src.join(name);
let index = out.join("index.html");
let rustbook = builder.tool_exe(Tool::Rustbook);
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
Expand All @@ -182,7 +141,6 @@ impl Step for RustbookSrc {
pub struct TheBook {
compiler: Compiler,
target: Interned<String>,
name: &'static str,
}

impl Step for TheBook {
Expand All @@ -198,53 +156,37 @@ impl Step for TheBook {
run.builder.ensure(TheBook {
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
target: run.target,
name: "book",
});
}

/// Builds the book and associated stuff.
///
/// We need to build:
///
/// * Book (first edition)
/// * Book (second edition)
/// * Book
/// * Older edition redirects
/// * Version info and CSS
/// * Index page
/// * Redirect pages
fn run(self, builder: &Builder<'_>) {
let compiler = self.compiler;
let target = self.target;
let name = self.name;

// build book
builder.ensure(RustbookSrc {
target,
name: INTERNER.intern_string(name.to_string()),
src: doc_src(builder),
name: INTERNER.intern_str("book"),
src: INTERNER.intern_path(builder.src.join("src/doc/book")),
});

// building older edition redirects

let source_name = format!("{}/first-edition", name);
builder.ensure(RustbookSrc {
target,
name: INTERNER.intern_string(source_name),
src: doc_src(builder),
});

let source_name = format!("{}/second-edition", name);
builder.ensure(RustbookSrc {
target,
name: INTERNER.intern_string(source_name),
src: doc_src(builder),
});

let source_name = format!("{}/2018-edition", name);
builder.ensure(RustbookSrc {
target,
name: INTERNER.intern_string(source_name),
src: doc_src(builder),
});
for edition in &["first-edition", "second-edition", "2018-edition"] {
builder.ensure(RustbookSrc {
target,
name: INTERNER.intern_string(format!("book/{}", edition)),
src: INTERNER.intern_path(builder.src.join("src/doc/book").join(edition)),
});
}

// build the version info page and CSS
builder.ensure(Standalone { compiler, target });
Expand Down Expand Up @@ -531,7 +473,7 @@ impl Step for Rustc {

// Build cargo command.
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc");
cargo.env("RUSTDOCFLAGS", "--document-private-items --passes strip-hidden");
cargo.env("RUSTDOCFLAGS", "--document-private-items");
compile::rustc_cargo(builder, &mut cargo, target);

// Only include compiler crates, no dependencies of those, such as `libc`.
Expand Down
20 changes: 8 additions & 12 deletions src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ fn rustbook_features() -> Vec<String> {
macro_rules! bootstrap_tool {
($(
$name:ident, $path:expr, $tool_name:expr
$(,llvm_tools = $llvm:expr)*
$(,is_external_tool = $external:expr)*
$(,is_unstable_tool = $unstable:expr)*
$(,features = $features:expr)*
;
)+) => {
Expand All @@ -301,15 +301,6 @@ macro_rules! bootstrap_tool {
)+
}

impl Tool {
/// Whether this tool requires LLVM to run
pub fn uses_llvm_tools(&self) -> bool {
match self {
$(Tool::$name => false $(|| $llvm)*,)+
}
}
}

impl<'a> Builder<'a> {
pub fn tool_exe(&self, tool: Tool) -> PathBuf {
match tool {
Expand Down Expand Up @@ -350,7 +341,12 @@ macro_rules! bootstrap_tool {
compiler: self.compiler,
target: self.target,
tool: $tool_name,
mode: Mode::ToolBootstrap,
mode: if false $(|| $unstable)* {
// use in-tree libraries for unstable features
Mode::ToolStd
} else {
Mode::ToolBootstrap
},
path: $path,
is_optional_tool: false,
source_type: if false $(|| $external)* {
Expand All @@ -377,7 +373,7 @@ bootstrap_tool!(
Tidy, "src/tools/tidy", "tidy";
Linkchecker, "src/tools/linkchecker", "linkchecker";
CargoTest, "src/tools/cargotest", "cargotest";
Compiletest, "src/tools/compiletest", "compiletest", llvm_tools = true;
Compiletest, "src/tools/compiletest", "compiletest", is_unstable_tool = true;
BuildManifest, "src/tools/build-manifest", "build-manifest";
RemoteTestClient, "src/tools/remote-test-client", "remote-test-client";
RustInstaller, "src/tools/rust-installer", "fabricate", is_external_tool = true;
Expand Down
2 changes: 1 addition & 1 deletion src/libpanic_unwind/emcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
let sz = mem::size_of_val(&data);
let exception = __cxa_allocate_exception(sz);
if exception == ptr::null_mut() {
if exception.is_null() {
return uw::_URC_FATAL_PHASE1_ERROR as u32;
}
ptr::write(exception as *mut _, data);
Expand Down
8 changes: 6 additions & 2 deletions src/libstd/sys/hermit/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ pub fn init_environment(env: *const *const i8) {
unsafe {
ENV = Some(Mutex::new(HashMap::new()));

if env.is_null() {
return;
}

let mut guard = ENV.as_ref().unwrap().lock().unwrap();
let mut environ = env;
while environ != ptr::null() && *environ != ptr::null() {
while !(*environ).is_null() {
if let Some((key, value)) = parse(CStr::from_ptr(*environ).to_bytes()) {
guard.insert(key, value);
}
environ = environ.offset(1);
environ = environ.add(1);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/hermit/thread_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ static KEYS_LOCK: Mutex = Mutex::new();
static mut LOCALS: *mut BTreeMap<Key, *mut u8> = ptr::null_mut();

unsafe fn keys() -> &'static mut BTreeMap<Key, Option<Dtor>> {
if KEYS == ptr::null_mut() {
if KEYS.is_null() {
KEYS = Box::into_raw(Box::new(BTreeMap::new()));
}
&mut *KEYS
}

unsafe fn locals() -> &'static mut BTreeMap<Key, *mut u8> {
if LOCALS == ptr::null_mut() {
if LOCALS.is_null() {
LOCALS = Box::into_raw(Box::new(BTreeMap::new()));
}
&mut *LOCALS
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/sgx/abi/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'a> Drop for ActiveTls<'a> {
any_non_null_dtor = false;
for (value, dtor) in TLS_KEY_IN_USE.iter().filter_map(&value_with_destructor) {
let value = value.replace(ptr::null_mut());
if value != ptr::null_mut() {
if !value.is_null() {
any_non_null_dtor = true;
unsafe { dtor(value) }
}
Expand Down
10 changes: 6 additions & 4 deletions src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,13 @@ pub fn env() -> Env {
let _guard = env_lock();
let mut environ = *environ();
let mut result = Vec::new();
while environ != ptr::null() && *environ != ptr::null() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
if !environ.is_null() {
while !(*environ).is_null() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
}
environ = environ.add(1);
}
environ = environ.offset(1);
}
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
}
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/sys/vxworks/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ pub fn env() -> Env {
unsafe {
let _guard = env_lock();
let mut environ = *environ();
if environ == ptr::null() {
if environ.is_null() {
panic!("os::env() failure getting env string from OS: {}", io::Error::last_os_error());
}
let mut result = Vec::new();
while *environ != ptr::null() {
while !(*environ).is_null() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
}
environ = environ.offset(1);
environ = environ.add(1);
}
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
}
Expand Down
10 changes: 6 additions & 4 deletions src/libstd/sys/wasi/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ pub fn env() -> Env {
let _guard = env_lock();
let mut environ = libc::environ;
let mut result = Vec::new();
while environ != ptr::null_mut() && *environ != ptr::null_mut() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
if !environ.is_null() {
while !(*environ).is_null() {
if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) {
result.push(key_value);
}
environ = environ.add(1);
}
environ = environ.offset(1);
}
return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData };
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn error_string(mut errnum: i32) -> String {
];
module = c::GetModuleHandleW(NTDLL_DLL.as_ptr());

if module != ptr::null_mut() {
if !module.is_null() {
errnum ^= c::FACILITY_NT_BIT as i32;
flags = c::FORMAT_MESSAGE_FROM_HMODULE;
}
Expand Down
4 changes: 3 additions & 1 deletion src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![crate_name = "compiletest"]
#![feature(test)]
#![deny(warnings)]
// The `test` crate is the only unstable feature
// allowed here, just to share similar code.
#![feature(test)]

extern crate test;

Expand Down