Skip to content

Commit 837f3e3

Browse files
committed
Use () for inherent_impls.
1 parent 3aa6f3e commit 837f3e3

File tree

7 files changed

+19
-26
lines changed

7 files changed

+19
-26
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,13 +944,12 @@ impl EncodeContext<'a, 'tcx> {
944944
record!(self.tables.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id));
945945
}
946946
}
947-
let inherent_impls = tcx.crate_inherent_impls(LOCAL_CRATE);
947+
let inherent_impls = tcx.crate_inherent_impls(());
948948
for (def_id, implementations) in inherent_impls.inherent_impls.iter() {
949-
assert!(def_id.is_local());
950949
if implementations.is_empty() {
951950
continue;
952951
}
953-
record!(self.tables.inherent_impls[def_id] <- implementations.iter().map(|&def_id| {
952+
record!(self.tables.inherent_impls[def_id.to_def_id()] <- implementations.iter().map(|&def_id| {
954953
assert!(def_id.is_local());
955954
def_id.index
956955
}));

compiler/rustc_middle/src/query/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,18 +740,15 @@ rustc_queries! {
740740

741741
/// Gets a complete map from all types to their inherent impls.
742742
/// Not meant to be used directly outside of coherence.
743-
/// (Defined only for `LOCAL_CRATE`.)
744-
query crate_inherent_impls(k: CrateNum)
745-
-> CrateInherentImpls {
743+
query crate_inherent_impls(k: ()) -> CrateInherentImpls {
746744
storage(ArenaCacheSelector<'tcx>)
747745
eval_always
748-
desc { "all inherent impls defined in crate `{:?}`", k }
746+
desc { "all inherent impls defined in crate" }
749747
}
750748

751749
/// Checks all types in the crate for overlap in their inherent impls. Reports errors.
752750
/// Not meant to be used directly outside of coherence.
753-
/// (Defined only for `LOCAL_CRATE`.)
754-
query crate_inherent_impls_overlap_check(_: CrateNum)
751+
query crate_inherent_impls_overlap_check(_: ())
755752
-> () {
756753
eval_always
757754
desc { "check for overlap between inherent impls defined in this crate" }

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_data_structures::sync::{self, par_iter, ParallelIterator};
3636
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
3737
use rustc_hir as hir;
3838
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
39-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
39+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, CRATE_DEF_INDEX};
4040
use rustc_hir::{Constness, Node};
4141
use rustc_macros::HashStable;
4242
use rustc_span::hygiene::ExpnId;
@@ -1983,7 +1983,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
19831983
/// (constructing this map requires touching the entire crate).
19841984
#[derive(Clone, Debug, Default, HashStable)]
19851985
pub struct CrateInherentImpls {
1986-
pub inherent_impls: DefIdMap<Vec<DefId>>,
1986+
pub inherent_impls: LocalDefIdMap<Vec<DefId>>,
19871987
}
19881988

19891989
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)]

compiler/rustc_typeck/src/coherence/inherent_impls.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
1010
use rustc_errors::struct_span_err;
1111
use rustc_hir as hir;
12-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
12+
use rustc_hir::def_id::{DefId, LocalDefId};
1313
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1414
use rustc_middle::ty::{self, CrateInherentImpls, TyCtxt};
1515

1616
use rustc_span::Span;
1717

1818
/// On-demand query: yields a map containing all types mapped to their inherent impls.
19-
pub fn crate_inherent_impls(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateInherentImpls {
20-
assert_eq!(crate_num, LOCAL_CRATE);
21-
19+
pub fn crate_inherent_impls(tcx: TyCtxt<'_>, (): ()) -> CrateInherentImpls {
2220
let krate = tcx.hir().krate();
2321
let mut collect = InherentCollect { tcx, impls_map: Default::default() };
2422
krate.visit_all_item_likes(&mut collect);
@@ -27,9 +25,9 @@ pub fn crate_inherent_impls(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateInhere
2725

2826
/// On-demand query: yields a vector of the inherent impls for a specific type.
2927
pub fn inherent_impls(tcx: TyCtxt<'_>, ty_def_id: DefId) -> &[DefId] {
30-
assert!(ty_def_id.is_local());
28+
let ty_def_id = ty_def_id.expect_local();
3129

32-
let crate_map = tcx.crate_inherent_impls(ty_def_id.krate);
30+
let crate_map = tcx.crate_inherent_impls(());
3331
match crate_map.inherent_impls.get(&ty_def_id) {
3432
Some(v) => &v[..],
3533
None => &[],
@@ -364,7 +362,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
364362

365363
impl InherentCollect<'tcx> {
366364
fn check_def_id(&mut self, item: &hir::Item<'_>, def_id: DefId) {
367-
if def_id.is_local() {
365+
if let Some(def_id) = def_id.as_local() {
368366
// Add the implementation to the mapping from implementation to base
369367
// type def ID, if there is a base type for this implementation and
370368
// the implementation does not have any associated traits.

compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
22
use rustc_errors::struct_span_err;
33
use rustc_hir as hir;
4-
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
4+
use rustc_hir::def_id::DefId;
55
use rustc_hir::itemlikevisit::ItemLikeVisitor;
66
use rustc_middle::ty::{self, TyCtxt};
77
use rustc_span::Symbol;
88
use rustc_trait_selection::traits::{self, SkipLeakCheck};
99
use smallvec::SmallVec;
1010
use std::collections::hash_map::Entry;
1111

12-
pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, crate_num: CrateNum) {
13-
assert_eq!(crate_num, LOCAL_CRATE);
12+
pub fn crate_inherent_impls_overlap_check(tcx: TyCtxt<'_>, (): ()) {
1413
let krate = tcx.hir().krate();
1514
krate.visit_all_item_likes(&mut InherentOverlapChecker { tcx });
1615
}

compiler/rustc_typeck/src/coherence/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// mappings. That mapping code resides here.
77

88
use rustc_errors::struct_span_err;
9-
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
9+
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_middle::ty::query::Providers;
1111
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
1212
use rustc_span::Span;
@@ -203,8 +203,8 @@ pub fn check_coherence(tcx: TyCtxt<'_>) {
203203
tcx.sess.time("orphan_checking", || orphan::check(tcx));
204204

205205
// these queries are executed for side-effects (error reporting):
206-
tcx.ensure().crate_inherent_impls(LOCAL_CRATE);
207-
tcx.ensure().crate_inherent_impls_overlap_check(LOCAL_CRATE);
206+
tcx.ensure().crate_inherent_impls(());
207+
tcx.ensure().crate_inherent_impls_overlap_check(());
208208
}
209209

210210
/// Checks whether an impl overlaps with the automatic `impl Trait for dyn Trait`.

src/tools/clippy/clippy_lints/src/inherent_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::in_macro;
55
use rustc_hir::def_id::DefIdMap;
6-
use rustc_hir::{def_id, Crate, Impl, Item, ItemKind};
6+
use rustc_hir::{Crate, Impl, Item, ItemKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
99
use rustc_span::Span;
@@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
6868
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, krate: &'tcx Crate<'_>) {
6969
if !krate.items.is_empty() {
7070
// Retrieve all inherent implementations from the crate, grouped by type
71-
for impls in cx.tcx.crate_inherent_impls(def_id::LOCAL_CRATE).inherent_impls.values() {
71+
for impls in cx.tcx.crate_inherent_impls(()).inherent_impls.values() {
7272
// Filter out implementations that have generic params (type or lifetime)
7373
let mut impl_spans = impls.iter().filter_map(|impl_def| self.impls.get(impl_def));
7474
if let Some(initial_span) = impl_spans.next() {

0 commit comments

Comments
 (0)