From 3fc0f76e3245769102a0982cad1258567b8dc6c1 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 28 Jan 2025 22:04:36 +0000 Subject: [PATCH] Force `compiler_builtins` to be a private dependency `compiler_builtins` is an injected dependency, introduced in AST as `extern crate compiler_builtins as _`. This means that `is_private_dep` has no way of knowing this should be private. To get around this, always mark `compiler_builtins` private. The items in this crate are never used --- .../rustc_builtin_macros/src/standard_library_imports.rs | 2 ++ compiler/rustc_metadata/src/creader.rs | 7 +++++++ compiler/rustc_resolve/src/build_reduced_graph.rs | 1 + 3 files changed, 10 insertions(+) diff --git a/compiler/rustc_builtin_macros/src/standard_library_imports.rs b/compiler/rustc_builtin_macros/src/standard_library_imports.rs index 1a3f4d2d44908..b8feb609325b7 100644 --- a/compiler/rustc_builtin_macros/src/standard_library_imports.rs +++ b/compiler/rustc_builtin_macros/src/standard_library_imports.rs @@ -53,6 +53,8 @@ pub fn inject( // // FIXME(#113634) We should inject this during post-processing like // we do for the panic runtime, profiler runtime, etc. + // + // See also `is_private_dep` within `rustc_metadata`. cx.item( span, Ident::new(kw::Underscore, ident_span), diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 0930fd4b3a229..7a2d9e007ab6e 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -402,6 +402,13 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { /// command parameter is set to `public-dependency` fn is_private_dep(&self, name: Symbol, private_dep: Option) -> bool { let extern_private = self.sess.opts.externs.get(name.as_str()).map(|e| e.is_private_dep); + if name == sym::compiler_builtins { + // compiler_builtins is a private implementation detail and should never show up in + // diagnostics. See also the note referencing #113634 in + // `rustc_builtin_macros::...::inject`. + return true; + } + match (extern_private, private_dep) { // Explicit non-private via `--extern`, explicit non-private from metadata, or // unspecified with default to public. diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index eec9e9a851503..0883ab435a7d9 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -730,6 +730,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { /// Constructs the reduced graph for one item. fn build_reduced_graph_for_item(&mut self, item: &'a Item) { let parent_scope = &self.parent_scope; + let ps2 = self.parent_scope.clone(); let parent = parent_scope.module; let expansion = parent_scope.expansion; let ident = item.ident;