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

Commit 3a72991

Browse files
committed
Use () in reachable_set.
1 parent 85a14d7 commit 3a72991

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::expand::allocator::ALLOCATOR_METHODS;
44
use rustc_data_structures::fingerprint::Fingerprint;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_hir as hir;
7-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
7+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
88
use rustc_hir::Node;
99
use rustc_index::vec::IndexVec;
1010
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@@ -60,7 +60,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
6060
tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE);
6161

6262
let mut reachable_non_generics: DefIdMap<_> = tcx
63-
.reachable_set(LOCAL_CRATE)
63+
.reachable_set(())
6464
.iter()
6565
.filter_map(|&def_id| {
6666
// We want to ignore some FFI functions that are not exposed from
@@ -355,12 +355,8 @@ fn upstream_drop_glue_for_provider<'tcx>(
355355
}
356356
}
357357

358-
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
359-
if let Some(def_id) = def_id.as_local() {
360-
!tcx.reachable_set(LOCAL_CRATE).contains(&def_id)
361-
} else {
362-
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
363-
}
358+
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
359+
!tcx.reachable_set(()).contains(&def_id)
364360
}
365361

366362
pub fn provide(providers: &mut Providers) {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ rustc_queries! {
855855
desc { "checking for private elements in public interfaces" }
856856
}
857857

858-
query reachable_set(_: CrateNum) -> FxHashSet<LocalDefId> {
858+
query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
859859
storage(ArenaCacheSelector<'tcx>)
860860
desc { "reachability" }
861861
}
@@ -1141,10 +1141,10 @@ rustc_queries! {
11411141
query is_reachable_non_generic(def_id: DefId) -> bool {
11421142
desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
11431143
}
1144-
query is_unreachable_local_definition(def_id: DefId) -> bool {
1144+
query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
11451145
desc { |tcx|
11461146
"checking whether `{}` is reachable from outside the crate",
1147-
tcx.def_path_str(def_id),
1147+
tcx.def_path_str(def_id.to_def_id()),
11481148
}
11491149
}
11501150

compiler/rustc_mir/src/monomorphize/partitioning/default.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ fn mono_item_visibility(
451451
let is_generic = instance.substs.non_erasable_generics().next().is_some();
452452

453453
// Upstream `DefId` instances get different handling than local ones.
454-
if !def_id.is_local() {
454+
let def_id = if let Some(def_id) = def_id.as_local() {
455+
def_id
456+
} else {
455457
return if export_generics && is_generic {
456458
// If it is a upstream monomorphization and we export generics, we must make
457459
// it available to downstream crates.
@@ -460,7 +462,7 @@ fn mono_item_visibility(
460462
} else {
461463
Visibility::Hidden
462464
};
463-
}
465+
};
464466

465467
if is_generic {
466468
if export_generics {
@@ -470,7 +472,7 @@ fn mono_item_visibility(
470472
} else {
471473
// This instance might be useful in a downstream crate.
472474
*can_be_internalized = false;
473-
default_visibility(tcx, def_id, true)
475+
default_visibility(tcx, def_id.to_def_id(), true)
474476
}
475477
} else {
476478
// We are not exporting generics or the definition is not reachable
@@ -481,10 +483,10 @@ fn mono_item_visibility(
481483
// If this isn't a generic function then we mark this a `Default` if
482484
// this is a reachable item, meaning that it's a symbol other crates may
483485
// access when they link to us.
484-
if tcx.is_reachable_non_generic(def_id) {
486+
if tcx.is_reachable_non_generic(def_id.to_def_id()) {
485487
*can_be_internalized = false;
486488
debug_assert!(!is_generic);
487-
return default_visibility(tcx, def_id, false);
489+
return default_visibility(tcx, def_id.to_def_id(), false);
488490
}
489491

490492
// If this isn't reachable then we're gonna tag this with `Hidden`

compiler/rustc_passes/src/reachable.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashSet;
99
use rustc_hir as hir;
1010
use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::def_id::LOCAL_CRATE;
12-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
12+
use rustc_hir::def_id::{DefId, LocalDefId};
1313
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1414
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1515
use rustc_hir::Node;
@@ -386,9 +386,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
386386
}
387387
}
388388

389-
fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> FxHashSet<LocalDefId> {
390-
debug_assert!(crate_num == LOCAL_CRATE);
391-
389+
fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
392390
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
393391

394392
let any_library =

0 commit comments

Comments
 (0)