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

Commit 601453a

Browse files
committed
Use () for HIR queries.
1 parent 3a72991 commit 601453a

File tree

6 files changed

+18
-27
lines changed

6 files changed

+18
-27
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'_, 'hir> {
150150

151151
impl<'hir> Map<'hir> {
152152
pub fn krate(&self) -> &'hir Crate<'hir> {
153-
self.tcx.hir_crate(LOCAL_CRATE)
153+
self.tcx.hir_crate(())
154154
}
155155

156156
#[inline]
@@ -489,7 +489,7 @@ impl<'hir> Map<'hir> {
489489
}
490490

491491
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [LocalDefId] {
492-
self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
492+
self.tcx.all_local_trait_impls(()).get(&trait_did).map_or(&[], |xs| &xs[..])
493493
}
494494

495495
/// Gets the attributes on the crate. This is preferable to
@@ -928,9 +928,7 @@ impl<'hir> intravisit::Map<'hir> for Map<'hir> {
928928
}
929929
}
930930

931-
pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx IndexedHir<'tcx> {
932-
assert_eq!(cnum, LOCAL_CRATE);
933-
931+
pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx IndexedHir<'tcx> {
934932
let _prof_timer = tcx.sess.prof.generic_activity("build_hir_map");
935933

936934
let hcx = tcx.create_stable_hashing_context();
@@ -943,10 +941,12 @@ pub(super) fn index_hir<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx Indexe
943941
}
944942

945943
pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
944+
assert_eq!(crate_num, LOCAL_CRATE);
945+
946946
let mut hcx = tcx.create_stable_hashing_context();
947947

948948
let mut hir_body_nodes: Vec<_> = tcx
949-
.index_hir(crate_num)
949+
.index_hir(())
950950
.map
951951
.iter_enumerated()
952952
.filter_map(|(def_id, hod)| {

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast::Attribute;
1313
use rustc_data_structures::fingerprint::Fingerprint;
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
16-
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
16+
use rustc_hir::def_id::LocalDefId;
1717
use rustc_hir::*;
1818
use rustc_index::vec::IndexVec;
1919
use rustc_span::DUMMY_SP;
@@ -123,14 +123,14 @@ pub fn provide(providers: &mut Providers) {
123123
let hir = tcx.hir();
124124
hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)))
125125
};
126-
providers.hir_crate = |tcx, _| tcx.untracked_crate;
126+
providers.hir_crate = |tcx, ()| tcx.untracked_crate;
127127
providers.index_hir = map::index_hir;
128128
providers.crate_hash = map::crate_hash;
129129
providers.hir_module_items = |tcx, id| &tcx.untracked_crate.modules[&id];
130-
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
131-
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref();
130+
providers.hir_owner = |tcx, id| tcx.index_hir(()).map[id].signature;
131+
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(()).map[id].with_bodies.as_deref();
132132
providers.hir_owner_parent = |tcx, id| {
133-
let index = tcx.index_hir(LOCAL_CRATE);
133+
let index = tcx.index_hir(());
134134
index.parenting.get(&id).copied().unwrap_or(CRATE_HIR_ID)
135135
};
136136
providers.hir_attrs = |tcx, id| AttributeMap { map: &tcx.untracked_crate.attrs, prefix: id };
@@ -151,4 +151,5 @@ pub fn provide(providers: &mut Providers) {
151151
}
152152
};
153153
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local());
154+
providers.all_local_trait_impls = |tcx, ()| &tcx.hir_crate(()).trait_impls;
154155
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ rustc_queries! {
2020
/// This is because the `hir_crate` query gives you access to all other items.
2121
/// To avoid this fate, do not call `tcx.hir().krate()`; instead,
2222
/// prefer wrappers like `tcx.visit_all_items_in_krate()`.
23-
query hir_crate(key: CrateNum) -> &'tcx Crate<'tcx> {
23+
query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
2424
eval_always
2525
no_hash
2626
desc { "get the crate HIR" }
2727
}
2828

2929
/// The indexed HIR. This can be conveniently accessed by `tcx.hir()`.
3030
/// Avoid calling this query directly.
31-
query index_hir(_: CrateNum) -> &'tcx crate::hir::IndexedHir<'tcx> {
31+
query index_hir(_: ()) -> &'tcx crate::hir::IndexedHir<'tcx> {
3232
eval_always
3333
no_hash
3434
desc { "index HIR" }
@@ -965,7 +965,7 @@ rustc_queries! {
965965
/// Passing in any other crate will cause an ICE.
966966
///
967967
/// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
968-
query all_local_trait_impls(local_crate: CrateNum) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
968+
query all_local_trait_impls(_: ()) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
969969
desc { "local trait impls" }
970970
}
971971

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
19701970
super::util::bug::provide(providers);
19711971
*providers = ty::query::Providers {
19721972
trait_impls_of: trait_def::trait_impls_of_provider,
1973-
all_local_trait_impls: trait_def::all_local_trait_impls,
19741973
type_uninhabited_from: inhabitedness::type_uninhabited_from,
19751974
const_param_default: consts::const_param_default,
19761975
..*providers

compiler/rustc_middle/src/ty/trait_def.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ use crate::ty::fast_reject;
44
use crate::ty::fold::TypeFoldable;
55
use crate::ty::{Ty, TyCtxt};
66
use rustc_hir as hir;
7-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
7+
use rustc_hir::def_id::DefId;
88
use rustc_hir::definitions::DefPathHash;
99

1010
use rustc_data_structures::fx::FxHashMap;
1111
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1212
use rustc_errors::ErrorReported;
1313
use rustc_macros::HashStable;
14-
use std::collections::BTreeMap;
1514

1615
/// A trait's definition with type information.
1716
#[derive(HashStable)]
@@ -209,14 +208,6 @@ impl<'tcx> TyCtxt<'tcx> {
209208
}
210209
}
211210

212-
// Query provider for `all_local_trait_impls`.
213-
pub(super) fn all_local_trait_impls<'tcx>(
214-
tcx: TyCtxt<'tcx>,
215-
krate: CrateNum,
216-
) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
217-
&tcx.hir_crate(krate).trait_impls
218-
}
219-
220211
// Query provider for `trait_impls_of`.
221212
pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> TraitImpls {
222213
let mut impls = TraitImpls::default();

src/tools/clippy/clippy_lints/src/derive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_middle::hir::map::Map;
1313
use rustc_middle::ty::{self, Ty};
1414
use rustc_session::{declare_lint_pass, declare_tool_lint};
15-
use rustc_span::{def_id::LOCAL_CRATE, source_map::Span};
15+
use rustc_span::{source_map::Span};
1616

1717
declare_clippy_lint! {
1818
/// **What it does:** Checks for deriving `Hash` but implementing `PartialEq`
@@ -312,7 +312,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &T
312312
if ty_subs.non_erasable_generics().next().is_some() {
313313
let has_copy_impl = cx
314314
.tcx
315-
.all_local_trait_impls(LOCAL_CRATE)
315+
.all_local_trait_impls(())
316316
.get(&copy_id)
317317
.map_or(false, |impls| {
318318
impls

0 commit comments

Comments
 (0)