Skip to content

Commit 072449c

Browse files
committed
Update trait_impls
1 parent 270ee7e commit 072449c

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,7 +4,7 @@ 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;
@@ -13,7 +13,7 @@ use rustc_ast::ast::{self, Name, NodeId};
1313
use rustc_data_structures::fx::FxHashMap;
1414
use rustc_data_structures::svh::Svh;
1515
use rustc_hir::def::{DefKind, Res};
16-
use rustc_hir::def_id::{DefId, DefIndex, LocalDefId};
16+
use rustc_hir::def_id::{DefId, DefIndex, LocalDefId, LOCAL_CRATE};
1717
use rustc_hir::intravisit;
1818
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1919
use rustc_hir::print::Nested;
@@ -532,11 +532,7 @@ impl<'hir> Map<'hir> {
532532
}
533533

534534
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [HirId] {
535-
self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls));
536-
537-
// N.B., intentionally bypass `self.krate()` so that we
538-
// do not trigger a read of the whole krate here
539-
self.krate.trait_impls.get(&trait_did).map_or(&[], |xs| &xs[..])
535+
self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
540536
}
541537

542538
/// 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
@@ -671,6 +671,9 @@ rustc_queries! {
671671
}
672672

673673
TypeChecking {
674+
query all_local_trait_impls(key: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
675+
desc { "local trait impls" }
676+
}
674677
query trait_impls_of(key: DefId) -> &'tcx ty::trait_def::TraitImpls {
675678
desc { |tcx| "trait impls of `{}`", tcx.def_path_str(key) }
676679
}

src/librustc/ty/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,8 +3142,11 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
31423142
context::provide(providers);
31433143
erase_regions::provide(providers);
31443144
layout::provide(providers);
3145-
*providers =
3146-
ty::query::Providers { trait_impls_of: trait_def::trait_impls_of_provider, ..*providers };
3145+
*providers = ty::query::Providers {
3146+
trait_impls_of: trait_def::trait_impls_of_provider,
3147+
all_local_trait_impls: trait_def::all_local_trait_impls,
3148+
..*providers
3149+
};
31473150
}
31483151

31493152
/// 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_attr as attr;
5656
use rustc_span::symbol::Symbol;
5757
use rustc_span::{Span, DUMMY_SP};
5858
use std::borrow::Cow;
59+
use std::collections::BTreeMap;
5960
use std::convert::TryFrom;
6061
use std::ops::Deref;
6162
use std::sync::Arc;

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)