Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a36bbad

Browse files
committed
Auto merge of rust-lang#135501 - tgross35:stdlib-dependencies-private, r=<try>
Resolve `compiler_builtins` not being treated as private; clean up rust-lang#135278 Follow up of rust-lang#135278 try-job: test-various
2 parents bf1b174 + 9c9ea48 commit a36bbad

File tree

8 files changed

+47
-43
lines changed

8 files changed

+47
-43
lines changed

compiler/rustc_builtin_macros/src/standard_library_imports.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub fn inject(
5353
//
5454
// FIXME(#113634) We should inject this during post-processing like
5555
// we do for the panic runtime, profiler runtime, etc.
56+
//
57+
// See also `is_private_dep` within `rustc_metadata`.
5658
cx.item(
5759
span,
5860
Ident::new(kw::Underscore, ident_span),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644
1616

1717
[dependencies]
1818
core = { path = "../core" }
19-
-compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std'] }
20-
+compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std', 'no-f16-f128'] }
19+
-compiler_builtins = { version = "=0.1.144", features = ['rustc-dep-of-std'] }
20+
+compiler_builtins = { version = "=0.1.144", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

2222
[dev-dependencies]
2323
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

compiler/rustc_metadata/src/creader.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_session::lint::{self, BuiltinLintDiag};
2929
use rustc_session::output::validate_crate_name;
3030
use rustc_session::search_paths::PathKind;
3131
use rustc_span::edition::Edition;
32-
use rustc_span::{DUMMY_SP, Ident, STDLIB_STABLE_CRATES, Span, Symbol, sym};
32+
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
3333
use rustc_target::spec::{PanicStrategy, Target, TargetTuple};
3434
use tracing::{debug, info, trace};
3535

@@ -400,26 +400,12 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
400400
/// Sometimes the directly dependent crate is not specified by `--extern`, in this case,
401401
/// `private-dep` is none during loading. This is equivalent to the scenario where the
402402
/// command parameter is set to `public-dependency`
403-
fn is_private_dep(
404-
&self,
405-
name: Symbol,
406-
private_dep: Option<bool>,
407-
dep_root: Option<&CratePaths>,
408-
) -> bool {
409-
// Standard library crates are never private.
410-
if STDLIB_STABLE_CRATES.contains(&name) {
411-
tracing::info!("returning false for {name} is private");
412-
return false;
413-
}
414-
403+
fn is_private_dep(&self, name: Symbol, private_dep: Option<bool>) -> bool {
415404
let extern_private = self.sess.opts.externs.get(name.as_str()).map(|e| e.is_private_dep);
416-
417-
// Any descendants of `std` should be private. These crates are usually not marked
418-
// private in metadata, so we ignore that field.
419-
if extern_private.is_none()
420-
&& let Some(dep) = dep_root
421-
&& STDLIB_STABLE_CRATES.contains(&dep.name)
422-
{
405+
if name == sym::compiler_builtins {
406+
// compiler_builtins is a private implementation detail and should never show up in
407+
// diagnostics. See also the note referencing #113634 in
408+
// `rustc_builtin_macros::...::inject`.
423409
return true;
424410
}
425411

@@ -447,7 +433,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
447433
let Library { source, metadata } = lib;
448434
let crate_root = metadata.get_root();
449435
let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash());
450-
let private_dep = self.is_private_dep(name, private_dep, dep_root);
436+
let private_dep = self.is_private_dep(name, private_dep);
451437

452438
// Claim this crate number and cache it
453439
let feed = self.cstore.intern_stable_crate_id(&crate_root, self.tcx)?;
@@ -470,7 +456,8 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
470456
&crate_paths
471457
};
472458

473-
let cnum_map = self.resolve_crate_deps(dep_root, &crate_root, &metadata, cnum, dep_kind)?;
459+
let cnum_map =
460+
self.resolve_crate_deps(dep_root, &crate_root, &metadata, cnum, dep_kind, private_dep)?;
474461

475462
let raw_proc_macros = if crate_root.is_proc_macro_crate() {
476463
let temp_root;
@@ -573,15 +560,16 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
573560
dep_kind: CrateDepKind,
574561
) -> Option<CrateNum> {
575562
self.used_extern_options.insert(name);
576-
match self.maybe_resolve_crate(name, dep_kind, None) {
563+
match self.maybe_resolve_crate(name, dep_kind, None, false) {
577564
Ok(cnum) => {
578565
self.cstore.set_used_recursively(cnum);
579566
Some(cnum)
580567
}
581568
Err(err) => {
582569
debug!("failed to resolve crate {} {:?}", name, dep_kind);
583-
let missing_core =
584-
self.maybe_resolve_crate(sym::core, CrateDepKind::Explicit, None).is_err();
570+
let missing_core = self
571+
.maybe_resolve_crate(sym::core, CrateDepKind::Explicit, None, false)
572+
.is_err();
585573
err.report(self.sess, span, missing_core);
586574
None
587575
}
@@ -593,6 +581,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
593581
name: Symbol,
594582
mut dep_kind: CrateDepKind,
595583
dep_of: Option<(&'b CratePaths, &'b CrateDep)>,
584+
parent_is_private: bool,
596585
) -> Result<CrateNum, CrateError> {
597586
info!("resolving crate `{}`", name);
598587
if !name.as_str().is_ascii() {
@@ -605,7 +594,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
605594
let host_hash = dep.map(|d| d.host_hash).flatten();
606595
let extra_filename = dep.map(|d| &d.extra_filename[..]);
607596
let path_kind = if dep.is_some() { PathKind::Dependency } else { PathKind::Crate };
608-
let private_dep = dep.map(|d| d.is_private);
597+
let private_dep = dep.map(|d| d.is_private || parent_is_private);
609598

610599
let result = if let Some(cnum) = self.existing_match(name, hash, path_kind) {
611600
(LoadResult::Previous(cnum), None)
@@ -643,7 +632,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
643632
// not specified by `--extern` on command line parameters, it may be
644633
// `private-dependency` when `register_crate` is called for the first time. Then it must be updated to
645634
// `public-dependency` here.
646-
let private_dep = self.is_private_dep(name, private_dep, dep_root);
635+
let private_dep = self.is_private_dep(name, private_dep);
647636
let data = self.cstore.get_crate_data_mut(cnum);
648637
if data.is_proc_macro_crate() {
649638
dep_kind = CrateDepKind::MacrosOnly;
@@ -702,6 +691,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
702691
metadata: &MetadataBlob,
703692
krate: CrateNum,
704693
dep_kind: CrateDepKind,
694+
parent_is_private: bool,
705695
) -> Result<CrateNumMap, CrateError> {
706696
debug!(
707697
"resolving deps of external crate `{}` with dep root `{}`",
@@ -720,17 +710,23 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
720710
crate_num_map.push(krate);
721711
for dep in deps {
722712
info!(
723-
"resolving dep `{}`->`{}` hash: `{}` extra filename: `{}`",
713+
"resolving dep `{}`->`{}` hash: `{}` extra filename: `{}` private {}",
724714
crate_root.name(),
725715
dep.name,
726716
dep.hash,
727-
dep.extra_filename
717+
dep.extra_filename,
718+
dep.is_private,
728719
);
729720
let dep_kind = match dep_kind {
730721
CrateDepKind::MacrosOnly => CrateDepKind::MacrosOnly,
731722
_ => dep.kind,
732723
};
733-
let cnum = self.maybe_resolve_crate(dep.name, dep_kind, Some((dep_root, &dep)))?;
724+
let cnum = self.maybe_resolve_crate(
725+
dep.name,
726+
dep_kind,
727+
Some((dep_root, &dep)),
728+
parent_is_private,
729+
)?;
734730
crate_num_map.push(cnum);
735731
}
736732

@@ -1147,7 +1143,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
11471143
}
11481144

11491145
pub fn maybe_process_path_extern(&mut self, name: Symbol) -> Option<CrateNum> {
1150-
self.maybe_resolve_crate(name, CrateDepKind::Explicit, None).ok()
1146+
self.maybe_resolve_crate(name, CrateDepKind::Explicit, None, false).ok()
11511147
}
11521148
}
11531149

library/Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ dependencies = [
6161

6262
[[package]]
6363
name = "compiler_builtins"
64-
version = "0.1.143"
64+
version = "0.1.144"
6565
source = "registry+https://github.com/rust-lang/crates.io-index"
66-
checksum = "c85ba2077e3eab3dd81be4ece6b7fb2ad0887c1fb813e9a45400baf75c6c7c29"
66+
checksum = "d18a7b7b5a56aa131e62314b4d862c9f6aa2860f615f3770094ec9064d7ec572"
6767
dependencies = [
6868
"cc",
6969
"rustc-std-workspace-core",

library/alloc/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
cargo-features = ["public-dependency"]
2+
13
[package]
24
name = "alloc"
35
version = "0.0.0"
@@ -9,8 +11,8 @@ autobenches = false
911
edition = "2021"
1012

1113
[dependencies]
12-
core = { path = "../core" }
13-
compiler_builtins = { version = "=0.1.143", features = ['rustc-dep-of-std'] }
14+
core = { path = "../core", public = true }
15+
compiler_builtins = { version = "=0.1.144", features = ['rustc-dep-of-std'] }
1416

1517
[dev-dependencies]
1618
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1717
panic_unwind = { path = "../panic_unwind", optional = true }
1818
panic_abort = { path = "../panic_abort" }
1919
core = { path = "../core", public = true }
20-
compiler_builtins = { version = "=0.1.143" }
20+
compiler_builtins = { version = "=0.1.144" }
2121
unwind = { path = "../unwind" }
2222
hashbrown = { version = "0.15", default-features = false, features = [
2323
'rustc-dep-of-std',

library/sysroot/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
cargo-features = ["public-dependency"]
2+
13
[package]
24
name = "sysroot"
35
version = "0.0.0"
46
edition = "2021"
57

68
# this is a dummy crate to ensure that all required crates appear in the sysroot
79
[dependencies]
8-
proc_macro = { path = "../proc_macro" }
10+
proc_macro = { path = "../proc_macro", public = true }
911
profiler_builtins = { path = "../profiler_builtins", optional = true }
10-
std = { path = "../std" }
11-
test = { path = "../test" }
12+
std = { path = "../std", public = true }
13+
test = { path = "../test", public = true }
1214

1315
# Forward features to the `std` crate as necessary
1416
[features]

library/test/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
cargo-features = ["public-dependency"]
2+
13
[package]
24
name = "test"
35
version = "0.0.0"
46
edition = "2021"
57

68
[dependencies]
79
getopts = { version = "0.2.21", features = ['rustc-dep-of-std'] }
8-
std = { path = "../std" }
9-
core = { path = "../core" }
10+
std = { path = "../std", public = true }
11+
core = { path = "../core", public = true }
1012

1113
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
1214
libc = { version = "0.2.150", default-features = false }

0 commit comments

Comments
 (0)