Skip to content

Commit 12e0a8d

Browse files
authored
Rollup merge of #135501 - tgross35:stdlib-dependencies-private, r=bjorn3
Inject `compiler_builtins` during postprocessing and ensure it is made private Follow up of #135278 Do the following: * Inject `compiler_builtins` during postprocessing, rather than injecting `extern crate compiler_builtins as _` into the AST * Do not make dependencies of `std` private by default (this was added in #135278) * Make sure sysroot crates correctly mark their dependencies private/public * Ensure that marking a dependency private makes its dependents private by default as well, unless otherwise specified * Do the `compiler_builtins` update that has been blocked on this There is more detail in the commit messages. This includes the changes I was working on in #136226. try-job: test-various try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: i686-mingw-1 try-job: i686-mingw-2
2 parents 15469f8 + 9392580 commit 12e0a8d

21 files changed

+226
-109
lines changed

Diff for: compiler/rustc_builtin_macros/src/standard_library_imports.rs

+13-36
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ pub fn inject(
1919
let edition = sess.psess.edition;
2020

2121
// the first name in this list is the crate name of the crate with the prelude
22-
let names: &[Symbol] = if attr::contains_name(pre_configured_attrs, sym::no_core) {
22+
let name: Symbol = if attr::contains_name(pre_configured_attrs, sym::no_core) {
2323
return 0;
2424
} else if attr::contains_name(pre_configured_attrs, sym::no_std) {
25-
if attr::contains_name(pre_configured_attrs, sym::compiler_builtins) {
26-
&[sym::core]
27-
} else {
28-
&[sym::core, sym::compiler_builtins]
29-
}
25+
sym::core
3026
} else {
31-
&[sym::std]
27+
sym::std
3228
};
3329

3430
let expn_id = resolver.expansion_for_ast_pass(
@@ -43,36 +39,16 @@ pub fn inject(
4339
let ecfg = ExpansionConfig::default("std_lib_injection".to_string(), features);
4440
let cx = ExtCtxt::new(sess, ecfg, resolver, None);
4541

46-
// .rev() to preserve ordering above in combination with insert(0, ...)
47-
for &name in names.iter().rev() {
48-
let ident_span = if edition >= Edition2018 { span } else { call_site };
49-
let item = if name == sym::compiler_builtins {
50-
// compiler_builtins is a private implementation detail. We only
51-
// need to insert it into the crate graph for linking and should not
52-
// expose any of its public API.
53-
//
54-
// FIXME(#113634) We should inject this during post-processing like
55-
// we do for the panic runtime, profiler runtime, etc.
56-
cx.item(
57-
span,
58-
Ident::new(kw::Underscore, ident_span),
59-
thin_vec![],
60-
ast::ItemKind::ExternCrate(Some(name)),
61-
)
62-
} else {
63-
cx.item(
64-
span,
65-
Ident::new(name, ident_span),
66-
thin_vec![cx.attr_word(sym::macro_use, span)],
67-
ast::ItemKind::ExternCrate(None),
68-
)
69-
};
70-
krate.items.insert(0, item);
71-
}
42+
let ident_span = if edition >= Edition2018 { span } else { call_site };
7243

73-
// The crates have been injected, the assumption is that the first one is
74-
// the one with the prelude.
75-
let name = names[0];
44+
let item = cx.item(
45+
span,
46+
Ident::new(name, ident_span),
47+
thin_vec![cx.attr_word(sym::macro_use, span)],
48+
ast::ItemKind::ExternCrate(None),
49+
);
50+
51+
krate.items.insert(0, item);
7652

7753
let root = (edition == Edition2015).then_some(kw::PathRoot);
7854

@@ -88,6 +64,7 @@ pub fn inject(
8864
.map(|&symbol| Ident::new(symbol, span))
8965
.collect();
9066

67+
// Inject the relevant crate's prelude.
9168
let use_item = cx.item(
9269
span,
9370
Ident::empty(),

Diff for: compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ index 7165c3e48af..968552ad435 100644
1515
edition = "2021"
1616

1717
[dependencies]
18-
core = { path = "../core" }
18+
core = { path = "../core", public = true }
1919
-compiler_builtins = { version = "=0.1.146", features = ['rustc-dep-of-std'] }
2020
+compiler_builtins = { version = "=0.1.146", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

Diff for: compiler/rustc_metadata/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ metadata_crate_dep_rustc_driver =
4747
metadata_crate_location_unknown_type =
4848
extern location for {$crate_name} is of an unknown type: {$path}
4949
50+
metadata_crate_not_compiler_builtins =
51+
the crate `{$crate_name}` resolved as `compiler_builtins` but is not `#![compiler_builtins]`
52+
5053
metadata_crate_not_panic_runtime =
5154
the crate `{$crate_name}` is not a panic runtime
5255

0 commit comments

Comments
 (0)