Skip to content

Commit b4b03ef

Browse files
committed
Update trait_impls
1 parent 1c4616d commit b4b03ef

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ pub use self::definitions::{
44
};
55

66
use crate::arena::Arena;
7-
use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex};
7+
use crate::dep_graph::{DepGraph, DepNodeIndex};
88
use crate::hir::{HirOwner, HirOwnerItems};
99
use crate::middle::cstore::CrateStoreDyn;
1010
use crate::ty::query::Providers;
1111
use crate::ty::TyCtxt;
1212
use rustc_data_structures::fx::FxHashMap;
1313
use rustc_data_structures::svh::Svh;
1414
use rustc_hir::def::{DefKind, Res};
15-
use rustc_hir::def_id::{DefId, DefIndex, LocalDefId};
15+
use rustc_hir::def_id::{DefId, DefIndex, LocalDefId, LOCAL_CRATE};
1616
use rustc_hir::intravisit;
1717
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1818
use rustc_hir::print::Nested;
@@ -537,11 +537,7 @@ impl<'hir> Map<'hir> {
537537
}
538538

539539
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [HirId] {
540-
self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls));
541-
542-
// N.B., intentionally bypass `self.krate()` so that we
543-
// do not trigger a read of the whole krate here
544-
self.krate.trait_impls.get(&trait_did).map_or(&[], |xs| &xs[..])
540+
self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
545541
}
546542

547543
/// Gets the attributes on the crate. This is preferable to

src/librustc/query/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ rustc_queries! {
662662
}
663663

664664
TypeChecking {
665+
query all_local_trait_impls(key: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
666+
desc { "local trait impls" }
667+
}
665668
query trait_impls_of(key: DefId) -> &'tcx ty::trait_def::TraitImpls {
666669
desc { |tcx| "trait impls of `{}`", tcx.def_path_str(key) }
667670
}

src/librustc/ty/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,8 +3012,11 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
30123012
context::provide(providers);
30133013
erase_regions::provide(providers);
30143014
layout::provide(providers);
3015-
*providers =
3016-
ty::query::Providers { trait_impls_of: trait_def::trait_impls_of_provider, ..*providers };
3015+
*providers = ty::query::Providers {
3016+
trait_impls_of: trait_def::trait_impls_of_provider,
3017+
all_local_trait_impls: trait_def::all_local_trait_impls,
3018+
..*providers
3019+
};
30173020
}
30183021

30193022
/// A map for the local crate mapping each type to a vector of its

src/librustc/ty/query/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use rustc_span::symbol::Symbol;
5656
use rustc_span::{Span, DUMMY_SP};
5757
use std::any::type_name;
5858
use std::borrow::Cow;
59+
use std::collections::BTreeMap;
5960
use std::ops::Deref;
6061
use std::sync::Arc;
6162
use syntax::ast;

src/librustc/ty/trait_def.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use crate::ty::fast_reject;
55
use crate::ty::fold::TypeFoldable;
66
use crate::ty::{Ty, TyCtxt};
77
use rustc_hir as hir;
8-
use rustc_hir::def_id::DefId;
8+
use rustc_hir::def_id::{CrateNum, DefId};
9+
use rustc_hir::HirId;
910

1011
use rustc_data_structures::fx::FxHashMap;
1112
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1213
use rustc_macros::HashStable;
14+
use std::collections::BTreeMap;
1315

1416
/// A trait's definition with type information.
1517
#[derive(HashStable)]
@@ -146,6 +148,14 @@ impl<'tcx> TyCtxt<'tcx> {
146148
}
147149
}
148150

151+
// Query provider for `all_local_trait_impls`.
152+
pub(super) fn all_local_trait_impls<'tcx>(
153+
tcx: TyCtxt<'tcx>,
154+
krate: CrateNum,
155+
) -> &'tcx BTreeMap<DefId, Vec<HirId>> {
156+
&tcx.hir_crate(krate).trait_impls
157+
}
158+
149159
// Query provider for `trait_impls_of`.
150160
pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> &TraitImpls {
151161
let mut impls = TraitImpls::default();

0 commit comments

Comments
 (0)