Rollup merge of #126013 - nnethercote:unreachable_pub, r=Urgau
Add `#[warn(unreachable_pub)]` to a bunch of compiler crates By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal. There are plenty more crates to do but this seems like enough for a first PR. r? `@compiler-errors`
This commit is contained in:
@@ -15,7 +15,7 @@ use crate::llvm::debuginfo::{DILocation, DIScope};
|
||||
|
||||
/// Produces DIScope DIEs for each MIR Scope which has variables defined in it.
|
||||
// FIXME(eddyb) almost all of this should be in `rustc_codegen_ssa::mir::debuginfo`.
|
||||
pub fn compute_mir_scopes<'ll, 'tcx>(
|
||||
pub(crate) fn compute_mir_scopes<'ll, 'tcx>(
|
||||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
mir: &Body<'tcx>,
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::value::Value;
|
||||
|
||||
/// Inserts a side-effect free instruction sequence that makes sure that the
|
||||
/// .debug_gdb_scripts global is referenced, so it isn't removed by the linker.
|
||||
pub fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Builder<'_, '_, '_>) {
|
||||
pub(crate) fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Builder<'_, '_, '_>) {
|
||||
if needs_gdb_debug_scripts_section(bx) {
|
||||
let gdb_debug_scripts_section = get_or_insert_gdb_debug_scripts_section_global(bx);
|
||||
// Load just the first byte as that's all that's necessary to force
|
||||
@@ -30,7 +30,9 @@ pub fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Builder<'_,
|
||||
|
||||
/// Allocates the global variable responsible for the .debug_gdb_scripts binary
|
||||
/// section.
|
||||
pub fn get_or_insert_gdb_debug_scripts_section_global<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll Value {
|
||||
pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
|
||||
cx: &CodegenCx<'ll, '_>,
|
||||
) -> &'ll Value {
|
||||
let c_section_var_name = c"__rustc_debug_gdb_scripts_section__";
|
||||
let section_var_name = c_section_var_name.to_str().unwrap();
|
||||
|
||||
@@ -82,7 +84,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global<'ll>(cx: &CodegenCx<'ll, '
|
||||
})
|
||||
}
|
||||
|
||||
pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
|
||||
pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
|
||||
let omit_gdb_pretty_printer_section =
|
||||
attr::contains_name(cx.tcx.hir().krate_attrs(), sym::omit_gdb_pretty_printer_section);
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ const NO_GENERICS: for<'ll> fn(&CodegenCx<'ll, '_>) -> SmallVec<&'ll DIType> = |
|
||||
|
||||
// SmallVec is used quite a bit in this module, so create a shorthand.
|
||||
// The actual number of elements is not so important.
|
||||
pub type SmallVec<T> = smallvec::SmallVec<[T; 16]>;
|
||||
type SmallVec<T> = smallvec::SmallVec<[T; 16]>;
|
||||
|
||||
mod enums;
|
||||
mod type_map;
|
||||
@@ -425,7 +425,7 @@ fn build_slice_type_di_node<'ll, 'tcx>(
|
||||
///
|
||||
/// This function will look up the debuginfo node in the TypeMap. If it can't find it, it
|
||||
/// will create the node by dispatching to the corresponding `build_*_di_node()` function.
|
||||
pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
|
||||
pub(crate) fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
|
||||
let unique_type_id = UniqueTypeId::for_ty(cx.tcx, t);
|
||||
|
||||
if let Some(existing_di_node) = debug_context(cx).type_map.di_node_for_unique_id(unique_type_id)
|
||||
@@ -531,7 +531,7 @@ fn hex_encode(data: &[u8]) -> String {
|
||||
hex_string
|
||||
}
|
||||
|
||||
pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) -> &'ll DIFile {
|
||||
pub(crate) fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) -> &'ll DIFile {
|
||||
let cache_key = Some((source_file.stable_id, source_file.src_hash));
|
||||
return debug_context(cx)
|
||||
.created_files
|
||||
@@ -644,7 +644,7 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unknown_file_metadata<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
|
||||
fn unknown_file_metadata<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
|
||||
debug_context(cx).created_files.borrow_mut().entry(None).or_insert_with(|| unsafe {
|
||||
let file_name = "<unknown>";
|
||||
let directory = "";
|
||||
@@ -859,7 +859,7 @@ fn build_param_type_di_node<'ll, 'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_compile_unit_di_node<'ll, 'tcx>(
|
||||
pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
codegen_unit_name: &str,
|
||||
debug_context: &CodegenUnitDebugContext<'ll, 'tcx>,
|
||||
@@ -1319,7 +1319,11 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
|
||||
/// Creates debug information for the given global variable.
|
||||
///
|
||||
/// Adds the created debuginfo nodes directly to the crate's IR.
|
||||
pub fn build_global_var_di_node<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId, global: &'ll Value) {
|
||||
pub(crate) fn build_global_var_di_node<'ll>(
|
||||
cx: &CodegenCx<'ll, '_>,
|
||||
def_id: DefId,
|
||||
global: &'ll Value,
|
||||
) {
|
||||
if cx.dbg_cx.is_none() {
|
||||
return;
|
||||
}
|
||||
@@ -1559,7 +1563,7 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>(
|
||||
/// given type.
|
||||
///
|
||||
/// Adds the created metadata nodes directly to the crate's IR.
|
||||
pub fn create_vtable_di_node<'ll, 'tcx>(
|
||||
pub(crate) fn create_vtable_di_node<'ll, 'tcx>(
|
||||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
poly_trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
||||
@@ -1604,7 +1608,7 @@ pub fn create_vtable_di_node<'ll, 'tcx>(
|
||||
}
|
||||
|
||||
/// Creates an "extension" of an existing `DIScope` into another file.
|
||||
pub fn extend_scope_to_file<'ll>(
|
||||
pub(crate) fn extend_scope_to_file<'ll>(
|
||||
cx: &CodegenCx<'ll, '_>,
|
||||
scope_metadata: &'ll DIScope,
|
||||
file: &SourceFile,
|
||||
@@ -1613,7 +1617,7 @@ pub fn extend_scope_to_file<'ll>(
|
||||
unsafe { llvm::LLVMRustDIBuilderCreateLexicalBlockFile(DIB(cx), scope_metadata, file_metadata) }
|
||||
}
|
||||
|
||||
pub fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
|
||||
fn tuple_field_name(field_index: usize) -> Cow<'static, str> {
|
||||
const TUPLE_FIELD_NAMES: [&'static str; 16] = [
|
||||
"__0", "__1", "__2", "__3", "__4", "__5", "__6", "__7", "__8", "__9", "__10", "__11",
|
||||
"__12", "__13", "__14", "__15",
|
||||
|
||||
@@ -257,7 +257,7 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>(
|
||||
/// ---> DW_TAG_structure_type (type of variant 3)
|
||||
///
|
||||
/// ```
|
||||
pub fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
|
||||
fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
|
||||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
variant_index: VariantIdx,
|
||||
coroutine_type_and_layout: TyAndLayout<'tcx>,
|
||||
|
||||
@@ -22,7 +22,7 @@ mod private {
|
||||
// `UniqueTypeId` from being constructed directly, without asserting
|
||||
// the preconditions.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, HashStable)]
|
||||
pub struct HiddenZst;
|
||||
pub(crate) struct HiddenZst;
|
||||
}
|
||||
|
||||
/// A unique identifier for anything that we create a debuginfo node for.
|
||||
@@ -48,17 +48,17 @@ pub(super) enum UniqueTypeId<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> UniqueTypeId<'tcx> {
|
||||
pub fn for_ty(tcx: TyCtxt<'tcx>, t: Ty<'tcx>) -> Self {
|
||||
pub(crate) fn for_ty(tcx: TyCtxt<'tcx>, t: Ty<'tcx>) -> Self {
|
||||
assert_eq!(t, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t));
|
||||
UniqueTypeId::Ty(t, private::HiddenZst)
|
||||
}
|
||||
|
||||
pub fn for_enum_variant_part(tcx: TyCtxt<'tcx>, enum_ty: Ty<'tcx>) -> Self {
|
||||
pub(crate) fn for_enum_variant_part(tcx: TyCtxt<'tcx>, enum_ty: Ty<'tcx>) -> Self {
|
||||
assert_eq!(enum_ty, tcx.normalize_erasing_regions(ParamEnv::reveal_all(), enum_ty));
|
||||
UniqueTypeId::VariantPart(enum_ty, private::HiddenZst)
|
||||
}
|
||||
|
||||
pub fn for_enum_variant_struct_type(
|
||||
pub(crate) fn for_enum_variant_struct_type(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
enum_ty: Ty<'tcx>,
|
||||
variant_idx: VariantIdx,
|
||||
@@ -67,7 +67,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
|
||||
UniqueTypeId::VariantStructType(enum_ty, variant_idx, private::HiddenZst)
|
||||
}
|
||||
|
||||
pub fn for_enum_variant_struct_type_wrapper(
|
||||
pub(crate) fn for_enum_variant_struct_type_wrapper(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
enum_ty: Ty<'tcx>,
|
||||
variant_idx: VariantIdx,
|
||||
@@ -76,7 +76,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
|
||||
UniqueTypeId::VariantStructTypeCppLikeWrapper(enum_ty, variant_idx, private::HiddenZst)
|
||||
}
|
||||
|
||||
pub fn for_vtable_ty(
|
||||
pub(crate) fn for_vtable_ty(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
self_type: Ty<'tcx>,
|
||||
implemented_trait: Option<PolyExistentialTraitRef<'tcx>>,
|
||||
@@ -93,7 +93,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
|
||||
/// argument of the various `LLVMRustDIBuilderCreate*Type()` methods.
|
||||
///
|
||||
/// Right now this takes the form of a hex-encoded opaque hash value.
|
||||
pub fn generate_unique_id_string(self, tcx: TyCtxt<'tcx>) -> String {
|
||||
fn generate_unique_id_string(self, tcx: TyCtxt<'tcx>) -> String {
|
||||
let mut hasher = StableHasher::new();
|
||||
tcx.with_stable_hashing_context(|mut hcx| {
|
||||
hcx.while_hashing_spans(false, |hcx| self.hash_stable(hcx, &mut hasher))
|
||||
@@ -101,7 +101,7 @@ impl<'tcx> UniqueTypeId<'tcx> {
|
||||
hasher.finish::<Fingerprint>().to_hex()
|
||||
}
|
||||
|
||||
pub fn expect_ty(self) -> Ty<'tcx> {
|
||||
pub(crate) fn expect_ty(self) -> Ty<'tcx> {
|
||||
match self {
|
||||
UniqueTypeId::Ty(ty, _) => ty,
|
||||
_ => bug!("Expected `UniqueTypeId::Ty` but found `{:?}`", self),
|
||||
@@ -133,25 +133,25 @@ impl<'ll, 'tcx> TypeMap<'ll, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DINodeCreationResult<'ll> {
|
||||
pub(crate) struct DINodeCreationResult<'ll> {
|
||||
pub di_node: &'ll DIType,
|
||||
pub already_stored_in_typemap: bool,
|
||||
}
|
||||
|
||||
impl<'ll> DINodeCreationResult<'ll> {
|
||||
pub fn new(di_node: &'ll DIType, already_stored_in_typemap: bool) -> Self {
|
||||
pub(crate) fn new(di_node: &'ll DIType, already_stored_in_typemap: bool) -> Self {
|
||||
DINodeCreationResult { di_node, already_stored_in_typemap }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub enum Stub<'ll> {
|
||||
pub(crate) enum Stub<'ll> {
|
||||
Struct,
|
||||
Union,
|
||||
VTableTy { vtable_holder: &'ll DIType },
|
||||
}
|
||||
|
||||
pub struct StubInfo<'ll, 'tcx> {
|
||||
pub(crate) struct StubInfo<'ll, 'tcx> {
|
||||
metadata: &'ll DIType,
|
||||
unique_type_id: UniqueTypeId<'tcx>,
|
||||
}
|
||||
|
||||
@@ -40,13 +40,13 @@ use crate::llvm::debuginfo::{
|
||||
use crate::value::Value;
|
||||
|
||||
mod create_scope_map;
|
||||
pub mod gdb;
|
||||
pub mod metadata;
|
||||
mod gdb;
|
||||
pub(crate) mod metadata;
|
||||
mod namespace;
|
||||
mod utils;
|
||||
|
||||
pub use self::create_scope_map::compute_mir_scopes;
|
||||
pub use self::metadata::build_global_var_di_node;
|
||||
use self::create_scope_map::compute_mir_scopes;
|
||||
pub(crate) use self::metadata::build_global_var_di_node;
|
||||
|
||||
#[allow(non_upper_case_globals)]
|
||||
const DW_TAG_auto_variable: c_uint = 0x100;
|
||||
@@ -54,7 +54,7 @@ const DW_TAG_auto_variable: c_uint = 0x100;
|
||||
const DW_TAG_arg_variable: c_uint = 0x101;
|
||||
|
||||
/// A context object for maintaining all state needed by the debuginfo module.
|
||||
pub struct CodegenUnitDebugContext<'ll, 'tcx> {
|
||||
pub(crate) struct CodegenUnitDebugContext<'ll, 'tcx> {
|
||||
llcontext: &'ll llvm::Context,
|
||||
llmod: &'ll llvm::Module,
|
||||
builder: &'ll mut DIBuilder<'ll>,
|
||||
@@ -74,7 +74,7 @@ impl Drop for CodegenUnitDebugContext<'_, '_> {
|
||||
}
|
||||
|
||||
impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
|
||||
pub fn new(llmod: &'ll llvm::Module) -> Self {
|
||||
pub(crate) fn new(llmod: &'ll llvm::Module) -> Self {
|
||||
debug!("CodegenUnitDebugContext::new");
|
||||
let builder = unsafe { llvm::LLVMRustDIBuilderCreate(llmod) };
|
||||
// DIBuilder inherits context from the module, so we'd better use the same one
|
||||
@@ -90,7 +90,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn finalize(&self, sess: &Session) {
|
||||
pub(crate) fn finalize(&self, sess: &Session) {
|
||||
unsafe {
|
||||
llvm::LLVMRustDIBuilderFinalize(self.builder);
|
||||
|
||||
@@ -134,7 +134,7 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
|
||||
}
|
||||
|
||||
/// Creates any deferred debug metadata nodes
|
||||
pub fn finalize(cx: &CodegenCx<'_, '_>) {
|
||||
pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
|
||||
if let Some(dbg_cx) = &cx.dbg_cx {
|
||||
debug!("finalize");
|
||||
|
||||
@@ -241,13 +241,13 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
|
||||
// FIXME(eddyb) rename this to better indicate it's a duplicate of
|
||||
// `rustc_span::Loc` rather than `DILocation`, perhaps by making
|
||||
// `lookup_char_pos` return the right information instead.
|
||||
pub struct DebugLoc {
|
||||
struct DebugLoc {
|
||||
/// Information about the original source file.
|
||||
pub file: Lrc<SourceFile>,
|
||||
file: Lrc<SourceFile>,
|
||||
/// The (1-based) line number.
|
||||
pub line: u32,
|
||||
line: u32,
|
||||
/// The (1-based) column number.
|
||||
pub col: u32,
|
||||
col: u32,
|
||||
}
|
||||
|
||||
impl CodegenCx<'_, '_> {
|
||||
@@ -255,7 +255,7 @@ impl CodegenCx<'_, '_> {
|
||||
// FIXME(eddyb) rename this to better indicate it's a duplicate of
|
||||
// `lookup_char_pos` rather than `dbg_loc`, perhaps by making
|
||||
// `lookup_char_pos` return the right information instead.
|
||||
pub fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
|
||||
fn lookup_debug_loc(&self, pos: BytePos) -> DebugLoc {
|
||||
let (file, line, col) = match self.sess().source_map().lookup_line(pos) {
|
||||
Ok(SourceFileAndLine { sf: file, line }) => {
|
||||
let line_pos = file.lines()[line];
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::common::CodegenCx;
|
||||
use crate::llvm;
|
||||
use crate::llvm::debuginfo::DIScope;
|
||||
|
||||
pub fn mangled_name_of_instance<'a, 'tcx>(
|
||||
pub(crate) fn mangled_name_of_instance<'a, 'tcx>(
|
||||
cx: &CodegenCx<'a, 'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
) -> ty::SymbolName<'tcx> {
|
||||
@@ -17,7 +17,7 @@ pub fn mangled_name_of_instance<'a, 'tcx>(
|
||||
tcx.symbol_name(instance)
|
||||
}
|
||||
|
||||
pub fn item_namespace<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
|
||||
pub(crate) fn item_namespace<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
|
||||
if let Some(&scope) = debug_context(cx).namespace_map.borrow().get(&def_id) {
|
||||
return scope;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::common::CodegenCx;
|
||||
use crate::llvm;
|
||||
use crate::llvm::debuginfo::{DIArray, DIBuilder, DIDescriptor, DIScope};
|
||||
|
||||
pub fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool {
|
||||
pub(crate) fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool {
|
||||
// The is_local_to_unit flag indicates whether a function is local to the
|
||||
// current compilation unit (i.e., if it is *static* in the C-sense). The
|
||||
// *reachable* set should provide a good approximation of this, as it
|
||||
@@ -24,7 +24,7 @@ pub fn is_node_local_to_unit(cx: &CodegenCx<'_, '_>, def_id: DefId) -> bool {
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn create_DIArray<'ll>(
|
||||
pub(crate) fn create_DIArray<'ll>(
|
||||
builder: &DIBuilder<'ll>,
|
||||
arr: &[Option<&'ll DIDescriptor>],
|
||||
) -> &'ll DIArray {
|
||||
@@ -32,7 +32,7 @@ pub fn create_DIArray<'ll>(
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn debug_context<'a, 'll, 'tcx>(
|
||||
pub(crate) fn debug_context<'a, 'll, 'tcx>(
|
||||
cx: &'a CodegenCx<'ll, 'tcx>,
|
||||
) -> &'a CodegenUnitDebugContext<'ll, 'tcx> {
|
||||
cx.dbg_cx.as_ref().unwrap()
|
||||
@@ -40,11 +40,11 @@ pub fn debug_context<'a, 'll, 'tcx>(
|
||||
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn DIB<'a, 'll>(cx: &'a CodegenCx<'ll, '_>) -> &'a DIBuilder<'ll> {
|
||||
pub(crate) fn DIB<'a, 'll>(cx: &'a CodegenCx<'ll, '_>) -> &'a DIBuilder<'ll> {
|
||||
cx.dbg_cx.as_ref().unwrap().builder
|
||||
}
|
||||
|
||||
pub fn get_namespace_for_item<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
|
||||
pub(crate) fn get_namespace_for_item<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
|
||||
item_namespace(cx, cx.tcx.parent(def_id))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user