diff --git a/src/Cargo.lock b/src/Cargo.lock index f70fc81829f58..004d1c0ffc933 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -10,6 +10,7 @@ dependencies = [ name = "alloc" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "std_unicode 0.0.0", @@ -23,6 +24,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", "libc 0.0.0", ] @@ -32,6 +34,7 @@ name = "alloc_system" version = "0.0.0" dependencies = [ "alloc 0.0.0", + "compiler_builtins 0.0.0", "core 0.0.0", "dlmalloc 0.0.0", "libc 0.0.0", @@ -541,6 +544,7 @@ name = "dlmalloc" version = "0.0.0" dependencies = [ "alloc 0.0.0", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -976,6 +980,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "libc" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -1254,6 +1259,7 @@ dependencies = [ name = "panic_abort" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", "libc 0.0.0", ] @@ -1263,6 +1269,7 @@ name = "panic_unwind" version = "0.0.0" dependencies = [ "alloc 0.0.0", + "compiler_builtins 0.0.0", "core 0.0.0", "libc 0.0.0", "unwind 0.0.0", @@ -1401,6 +1408,7 @@ name = "profiler_builtins" version = "0.0.0" dependencies = [ "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -1797,6 +1805,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -1942,6 +1951,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -1991,6 +2001,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -2130,6 +2141,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -2343,6 +2355,7 @@ dependencies = [ name = "std_unicode" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -2725,6 +2738,7 @@ dependencies = [ name = "unwind" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", "libc 0.0.0", ] diff --git a/src/liballoc/Cargo.toml b/src/liballoc/Cargo.toml index 3bf919b0c0016..2eb8ea1260446 100644 --- a/src/liballoc/Cargo.toml +++ b/src/liballoc/Cargo.toml @@ -10,6 +10,7 @@ path = "lib.rs" [dependencies] core = { path = "../libcore" } std_unicode = { path = "../libstd_unicode" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } [dev-dependencies] rand = "0.4" diff --git a/src/liballoc_jemalloc/Cargo.toml b/src/liballoc_jemalloc/Cargo.toml index 6d7d83dd99388..fd4a45530463d 100644 --- a/src/liballoc_jemalloc/Cargo.toml +++ b/src/liballoc_jemalloc/Cargo.toml @@ -16,6 +16,7 @@ alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } [build-dependencies] build_helper = { path = "../build_helper" } diff --git a/src/liballoc_system/Cargo.toml b/src/liballoc_system/Cargo.toml index f9a57f7d97a74..936e20a32e10e 100644 --- a/src/liballoc_system/Cargo.toml +++ b/src/liballoc_system/Cargo.toml @@ -13,6 +13,7 @@ doc = false alloc = { path = "../liballoc" } core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } # See comments in the source for what this dependency is [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] diff --git a/src/libpanic_abort/Cargo.toml b/src/libpanic_abort/Cargo.toml index e0eac41f49ec9..633d273b3b93c 100644 --- a/src/libpanic_abort/Cargo.toml +++ b/src/libpanic_abort/Cargo.toml @@ -12,3 +12,4 @@ doc = false [dependencies] core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/libpanic_unwind/Cargo.toml b/src/libpanic_unwind/Cargo.toml index a978ea16e9e74..74aaa4d5ae3db 100644 --- a/src/libpanic_unwind/Cargo.toml +++ b/src/libpanic_unwind/Cargo.toml @@ -14,3 +14,4 @@ alloc = { path = "../liballoc" } core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } unwind = { path = "../libunwind" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/libprofiler_builtins/Cargo.toml b/src/libprofiler_builtins/Cargo.toml index 04f456917b957..79192fbb6819c 100644 --- a/src/libprofiler_builtins/Cargo.toml +++ b/src/libprofiler_builtins/Cargo.toml @@ -13,6 +13,7 @@ doc = false [dependencies] core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } [build-dependencies] cc = "1.0.1" diff --git a/src/librustc_asan/Cargo.toml b/src/librustc_asan/Cargo.toml index 8f8ef1cc4a011..34d8b75a5bfb3 100644 --- a/src/librustc_asan/Cargo.toml +++ b/src/librustc_asan/Cargo.toml @@ -17,3 +17,4 @@ cmake = "0.1.18" alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/librustc_lsan/Cargo.toml b/src/librustc_lsan/Cargo.toml index 087c316211943..9c19b53742654 100644 --- a/src/librustc_lsan/Cargo.toml +++ b/src/librustc_lsan/Cargo.toml @@ -17,3 +17,4 @@ cmake = "0.1.18" alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/librustc_msan/Cargo.toml b/src/librustc_msan/Cargo.toml index 8d7279b29eb55..17ec2b96438ad 100644 --- a/src/librustc_msan/Cargo.toml +++ b/src/librustc_msan/Cargo.toml @@ -17,3 +17,4 @@ cmake = "0.1.18" alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/librustc_tsan/Cargo.toml b/src/librustc_tsan/Cargo.toml index 7b83985ba6731..8bb67c0bbac5f 100644 --- a/src/librustc_tsan/Cargo.toml +++ b/src/librustc_tsan/Cargo.toml @@ -17,3 +17,4 @@ cmake = "0.1.18" alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 6f6abfdd31e57..f9041ac8546b9 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -373,6 +373,7 @@ extern crate unwind; // compiler-rt intrinsics #[doc(masked)] +#[cfg(stage0)] extern crate compiler_builtins; // During testing, this crate is not actually the "real" std library, but rather diff --git a/src/libstd_unicode/Cargo.toml b/src/libstd_unicode/Cargo.toml index b3346dbe2fb12..283070a0e2cf7 100644 --- a/src/libstd_unicode/Cargo.toml +++ b/src/libstd_unicode/Cargo.toml @@ -15,3 +15,4 @@ path = "tests/lib.rs" [dependencies] core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8d42206c5ccff..8168db1905876 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -94,7 +94,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap, is_expanded: bool) -> io::Result<()> { let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded); - if is_expanded && !std_inject::injected_crate_name().is_none() { + if is_expanded && std_inject::injected_crate_name().is_some() { // We need to print `#![no_std]` (and its feature gate) so that // compiling pretty-printed source won't inject libstd again. // However we don't want these attributes in the AST because diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 63d7b3336a861..bba7a2d737736 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -44,27 +44,38 @@ thread_local! { } pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<&str>) -> ast::Crate { - let name = if attr::contains_name(&krate.attrs, "no_core") { + // the first name in this list is the crate name of the crate with the prelude + let names: &[&str] = if attr::contains_name(&krate.attrs, "no_core") { return krate; } else if attr::contains_name(&krate.attrs, "no_std") { - "core" + if attr::contains_name(&krate.attrs, "compiler_builtins") { + &["core"] + } else { + &["core", "compiler_builtins"] + } } else { - "std" + &["std"] }; - INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name))); + for name in names { + krate.module.items.insert(0, P(ast::Item { + attrs: vec![attr::mk_attr_outer(DUMMY_SP, + attr::mk_attr_id(), + attr::mk_word_item(ast::Ident::from_str("macro_use")))], + vis: dummy_spanned(ast::VisibilityKind::Inherited), + node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)), + ident: ast::Ident::from_str(name), + id: ast::DUMMY_NODE_ID, + span: DUMMY_SP, + tokens: None, + })); + } - krate.module.items.insert(0, P(ast::Item { - attrs: vec![attr::mk_attr_outer(DUMMY_SP, - attr::mk_attr_id(), - attr::mk_word_item(ast::Ident::from_str("macro_use")))], - vis: dummy_spanned(ast::VisibilityKind::Inherited), - node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)), - ident: ast::Ident::from_str(name), - id: ast::DUMMY_NODE_ID, - span: DUMMY_SP, - tokens: None, - })); + // the crates have been injected, the assumption is that the first one is the one with + // the prelude. + let name = names[0]; + + INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name))); let span = ignored_span(DUMMY_SP); krate.module.items.insert(0, P(ast::Item { diff --git a/src/libunwind/Cargo.toml b/src/libunwind/Cargo.toml index fbd9789d2f52d..4760461df64e3 100644 --- a/src/libunwind/Cargo.toml +++ b/src/libunwind/Cargo.toml @@ -14,3 +14,4 @@ doc = false [dependencies] core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/rustc/dlmalloc_shim/Cargo.toml b/src/rustc/dlmalloc_shim/Cargo.toml index cf8440c40da1a..d2fe159d80673 100644 --- a/src/rustc/dlmalloc_shim/Cargo.toml +++ b/src/rustc/dlmalloc_shim/Cargo.toml @@ -11,4 +11,5 @@ doc = false [dependencies] core = { path = "../../libcore" } +compiler_builtins = { path = "../../rustc/compiler_builtins_shim" } alloc = { path = "../../liballoc" } diff --git a/src/rustc/libc_shim/Cargo.toml b/src/rustc/libc_shim/Cargo.toml index 0c04402124a2d..e77897d643313 100644 --- a/src/rustc/libc_shim/Cargo.toml +++ b/src/rustc/libc_shim/Cargo.toml @@ -29,6 +29,8 @@ doc = false # # See https://github.com/rust-lang/rfcs/pull/1133. core = { path = "../../libcore" } +compiler_builtins = { path = "../compiler_builtins_shim" } + [features] # Certain parts of libc are conditionally compiled differently than when used