Skip to content

Commit 679657b

Browse files
committed
Inject the compiler_builtins crate whenever the core crate is injected
1 parent ee1014e commit 679657b

File tree

18 files changed

+57
-16
lines changed

18 files changed

+57
-16
lines changed

src/Cargo.lock

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/liballoc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ path = "lib.rs"
1010
[dependencies]
1111
core = { path = "../libcore" }
1212
std_unicode = { path = "../libstd_unicode" }
13+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
1314

1415
[dev-dependencies]
1516
rand = "0.4"

src/liballoc_jemalloc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ alloc = { path = "../liballoc" }
1616
alloc_system = { path = "../liballoc_system" }
1717
core = { path = "../libcore" }
1818
libc = { path = "../rustc/libc_shim" }
19+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
1920

2021
[build-dependencies]
2122
build_helper = { path = "../build_helper" }

src/liballoc_system/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ doc = false
1313
alloc = { path = "../liballoc" }
1414
core = { path = "../libcore" }
1515
libc = { path = "../rustc/libc_shim" }
16+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
1617

1718
# See comments in the source for what this dependency is
1819
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]

src/libpanic_abort/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ doc = false
1212
[dependencies]
1313
core = { path = "../libcore" }
1414
libc = { path = "../rustc/libc_shim" }
15+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

src/libpanic_unwind/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ alloc = { path = "../liballoc" }
1414
core = { path = "../libcore" }
1515
libc = { path = "../rustc/libc_shim" }
1616
unwind = { path = "../libunwind" }
17+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

src/libprofiler_builtins/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ doc = false
1313

1414
[dependencies]
1515
core = { path = "../libcore" }
16+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }
1617

1718
[build-dependencies]
1819
cc = "1.0.1"

src/librustc_asan/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ cmake = "0.1.18"
1717
alloc = { path = "../liballoc" }
1818
alloc_system = { path = "../liballoc_system" }
1919
core = { path = "../libcore" }
20+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

src/librustc_lsan/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ cmake = "0.1.18"
1717
alloc = { path = "../liballoc" }
1818
alloc_system = { path = "../liballoc_system" }
1919
core = { path = "../libcore" }
20+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

src/librustc_msan/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ cmake = "0.1.18"
1717
alloc = { path = "../liballoc" }
1818
alloc_system = { path = "../liballoc_system" }
1919
core = { path = "../libcore" }
20+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

src/librustc_tsan/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ cmake = "0.1.18"
1717
alloc = { path = "../liballoc" }
1818
alloc_system = { path = "../liballoc_system" }
1919
core = { path = "../libcore" }
20+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ extern crate unwind;
373373

374374
// compiler-rt intrinsics
375375
#[doc(masked)]
376+
#[cfg(stage0)]
376377
extern crate compiler_builtins;
377378

378379
// During testing, this crate is not actually the "real" std library, but rather

src/libstd_unicode/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ path = "tests/lib.rs"
1515

1616
[dependencies]
1717
core = { path = "../libcore" }
18+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
9494
is_expanded: bool) -> io::Result<()> {
9595
let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded);
9696

97-
if is_expanded && !std_inject::injected_crate_name().is_none() {
97+
if is_expanded && std_inject::injected_crate_name().is_some() {
9898
// We need to print `#![no_std]` (and its feature gate) so that
9999
// compiling pretty-printed source won't inject libstd again.
100100
// However we don't want these attributes in the AST because

src/libsyntax/std_inject.rs

+26-15
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,38 @@ thread_local! {
4444
}
4545

4646
pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<&str>) -> ast::Crate {
47-
let name = if attr::contains_name(&krate.attrs, "no_core") {
47+
// the first name in this list is the crate name of the crate with the prelude
48+
let names: &[&str] = if attr::contains_name(&krate.attrs, "no_core") {
4849
return krate;
4950
} else if attr::contains_name(&krate.attrs, "no_std") {
50-
"core"
51+
if attr::contains_name(&krate.attrs, "compiler_builtins") {
52+
&["core"]
53+
} else {
54+
&["core", "compiler_builtins"]
55+
}
5156
} else {
52-
"std"
57+
&["std"]
5358
};
5459

55-
INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name)));
60+
for name in names {
61+
krate.module.items.insert(0, P(ast::Item {
62+
attrs: vec![attr::mk_attr_outer(DUMMY_SP,
63+
attr::mk_attr_id(),
64+
attr::mk_word_item(ast::Ident::from_str("macro_use")))],
65+
vis: dummy_spanned(ast::VisibilityKind::Inherited),
66+
node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)),
67+
ident: ast::Ident::from_str(name),
68+
id: ast::DUMMY_NODE_ID,
69+
span: DUMMY_SP,
70+
tokens: None,
71+
}));
72+
}
5673

57-
krate.module.items.insert(0, P(ast::Item {
58-
attrs: vec![attr::mk_attr_outer(DUMMY_SP,
59-
attr::mk_attr_id(),
60-
attr::mk_word_item(ast::Ident::from_str("macro_use")))],
61-
vis: dummy_spanned(ast::VisibilityKind::Inherited),
62-
node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)),
63-
ident: ast::Ident::from_str(name),
64-
id: ast::DUMMY_NODE_ID,
65-
span: DUMMY_SP,
66-
tokens: None,
67-
}));
74+
// the crates have been injected, the assumption is that the first one is the one with
75+
// the prelude.
76+
let name = names[0];
77+
78+
INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name)));
6879

6980
let span = ignored_span(DUMMY_SP);
7081
krate.module.items.insert(0, P(ast::Item {

src/libunwind/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ doc = false
1414
[dependencies]
1515
core = { path = "../libcore" }
1616
libc = { path = "../rustc/libc_shim" }
17+
compiler_builtins = { path = "../rustc/compiler_builtins_shim" }

src/rustc/dlmalloc_shim/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ doc = false
1111

1212
[dependencies]
1313
core = { path = "../../libcore" }
14+
compiler_builtins = { path = "../../rustc/compiler_builtins_shim" }
1415
alloc = { path = "../../liballoc" }

src/rustc/libc_shim/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ doc = false
2929
#
3030
# See https://github.com/rust-lang/rfcs/pull/1133.
3131
core = { path = "../../libcore" }
32+
compiler_builtins = { path = "../compiler_builtins_shim" }
33+
3234

3335
[features]
3436
# Certain parts of libc are conditionally compiled differently than when used

0 commit comments

Comments
 (0)