Skip to content

Commit 5d31b83

Browse files
committed
Always make compiler_builtins a private dependency
`compiler_builtins` is always available as an injected dependency, introduced in AST as `extern crate compiler_builtins as _`. This makes it indistinguishable from any other user-specified `extern crate`, meaning `is_private_dep` does not see it as a dependency that should be marked private; this is the reason that `compiler_builtins` sometimes leaks into diagnostics, and has slightly different behavior from other stdlib dependencies tested in [1]. There is no easy way to know that an instance of `extern crate compiler_builtins` was the injected version; however, `compiler_builtins` To get around this, always mark `compiler_builtins` private. The items in this crate are never used directly, and this is the most [1]: rust-lang#135278
1 parent aeba3c6 commit 5d31b83

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

compiler/rustc_builtin_macros/src/standard_library_imports.rs

+2
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_metadata/src/creader.rs

+6
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
414414

415415
let extern_private = self.sess.opts.externs.get(name.as_str()).map(|e| e.is_private_dep);
416416

417+
if name == sym::compiler_builtins {
418+
// compiler_builtins is a private implementation detail and should never show up in
419+
// diagnostics. See also the note referencing #113634 in
420+
// `rustc_builtin_macros::...::inject`.
421+
return true;
422+
}
417423
// Any descendants of `std` should be private. These crates are usually not marked
418424
// private in metadata, so we ignore that field.
419425
if extern_private.is_none()

0 commit comments

Comments
 (0)