Skip to content

Commit 2eb1c08

Browse files
Use local key in providers
1 parent a01b4cc commit 2eb1c08

File tree

65 files changed

+458
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+458
-395
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
@@ -41,9 +41,7 @@ pub fn crates_export_threshold(crate_types: &[CrateType]) -> SymbolExportLevel {
4141
}
4242
}
4343

44-
fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<SymbolExportInfo> {
45-
assert_eq!(cnum, LOCAL_CRATE);
46-
44+
fn reachable_non_generics_provider(tcx: TyCtxt<'_>, (): ()) -> DefIdMap<SymbolExportInfo> {
4745
if !tcx.sess.opts.output_types.should_codegen() {
4846
return Default::default();
4947
}
@@ -154,10 +152,10 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
154152
reachable_non_generics
155153
}
156154

157-
fn is_reachable_non_generic_provider_local(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
155+
fn is_reachable_non_generic_provider_local(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
158156
let export_threshold = threshold(tcx);
159157

160-
if let Some(&info) = tcx.reachable_non_generics(def_id.krate).get(&def_id) {
158+
if let Some(&info) = tcx.reachable_non_generics(LOCAL_CRATE).get(&def_id.to_def_id()) {
161159
info.level.is_below_threshold(export_threshold)
162160
} else {
163161
false
@@ -170,10 +168,8 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
170168

171169
fn exported_symbols_provider_local(
172170
tcx: TyCtxt<'_>,
173-
cnum: CrateNum,
171+
(): (),
174172
) -> &[(ExportedSymbol<'_>, SymbolExportInfo)] {
175-
assert_eq!(cnum, LOCAL_CRATE);
176-
177173
if !tcx.sess.opts.output_types.should_codegen() {
178174
return &[];
179175
}

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage {
4343
}
4444
}
4545

46-
fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
46+
fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
4747
if cfg!(debug_assertions) {
4848
let def_kind = tcx.def_kind(did);
4949
assert!(
@@ -52,7 +52,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
5252
);
5353
}
5454

55-
let did = did.expect_local();
5655
let attrs = tcx.hir().attrs(tcx.hir().local_def_id_to_hir_id(did));
5756
let mut codegen_fn_attrs = CodegenFnAttrs::new();
5857
if tcx.should_inherit_track_caller(did) {

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
3232
/// it is a trait impl/function, return if it has a `const` modifier. If it is an intrinsic,
3333
/// report whether said intrinsic has a `rustc_const_{un,}stable` attribute. Otherwise, return
3434
/// `Constness::NotConst`.
35-
fn constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
36-
let def_id = def_id.expect_local();
35+
fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
3736
let node = tcx.hir().get_by_def_id(def_id);
3837

3938
match node {

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
246246
self.check_local_or_return_ty(return_ty.skip_binder(), RETURN_PLACE);
247247
}
248248

249-
if !tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) {
249+
if !tcx.has_attr(def_id, sym::rustc_do_not_const_check) {
250250
self.visit_body(&body);
251251
}
252252

compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn check_live_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) {
3030
return;
3131
}
3232

33-
if tcx.has_attr(def_id.to_def_id(), sym::rustc_do_not_const_check) {
33+
if tcx.has_attr(def_id, sym::rustc_do_not_const_check) {
3434
return;
3535
}
3636

compiler/rustc_hir/src/hir_id.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ impl From<OwnerId> for HirId {
2222
}
2323
}
2424

25+
impl From<OwnerId> for DefId {
26+
fn from(value: OwnerId) -> Self {
27+
value.to_def_id()
28+
}
29+
}
30+
2531
impl OwnerId {
2632
#[inline]
2733
pub fn to_def_id(self) -> DefId {

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
11611161
def.destructor(tcx); // force the destructor to be evaluated
11621162

11631163
if def.variants().is_empty() {
1164-
if let Some(attr) = tcx.get_attrs(def_id.to_def_id(), sym::repr).next() {
1164+
if let Some(attr) = tcx.get_attrs(def_id, sym::repr).next() {
11651165
struct_span_err!(
11661166
tcx.sess,
11671167
attr.span,

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,13 @@ fn compare_asyncness<'tcx>(
583583
#[instrument(skip(tcx), level = "debug", ret)]
584584
pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
585585
tcx: TyCtxt<'tcx>,
586-
def_id: DefId,
586+
impl_m_def_id: LocalDefId,
587587
) -> Result<&'tcx FxHashMap<DefId, Ty<'tcx>>, ErrorGuaranteed> {
588-
let impl_m = tcx.opt_associated_item(def_id).unwrap();
588+
let impl_m = tcx.opt_associated_item(impl_m_def_id.to_def_id()).unwrap();
589589
let trait_m = tcx.opt_associated_item(impl_m.trait_item_def_id.unwrap()).unwrap();
590590
let impl_trait_ref =
591591
tcx.impl_trait_ref(impl_m.impl_container(tcx).unwrap()).unwrap().subst_identity();
592-
let param_env = tcx.param_env(def_id);
592+
let param_env = tcx.param_env(impl_m_def_id);
593593

594594
// First, check a few of the same things as `compare_impl_method`,
595595
// just so we don't ICE during substitution later.
@@ -599,7 +599,6 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
599599

600600
let trait_to_impl_substs = impl_trait_ref.substs;
601601

602-
let impl_m_def_id = impl_m.def_id.expect_local();
603602
let impl_m_hir_id = tcx.hir().local_def_id_to_hir_id(impl_m_def_id);
604603
let return_span = tcx.hir().fn_decl_by_hir_id(impl_m_hir_id).unwrap().output.span();
605604
let cause = ObligationCause::new(

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pub fn provide(providers: &mut Providers) {
109109
};
110110
}
111111

112-
fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
113-
tcx.calculate_dtor(def_id, dropck::check_drop_impl)
112+
fn adt_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Destructor> {
113+
tcx.calculate_dtor(def_id.to_def_id(), dropck::check_drop_impl)
114114
}
115115

116116
/// Given a `DefId` for an opaque type in return position, find its parent item's return

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,8 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
368368
}
369369
}
370370

371-
pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedInfo {
371+
pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: LocalDefId) -> CoerceUnsizedInfo {
372372
debug!("compute_coerce_unsized_info(impl_did={:?})", impl_did);
373-
374-
// this provider should only get invoked for local def-ids
375-
let impl_did = impl_did.expect_local();
376373
let span = tcx.def_span(impl_did);
377374

378375
let coerce_unsized_trait = tcx.require_lang_item(LangItem::CoerceUnsized, Some(span));

0 commit comments

Comments
 (0)