mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 18:53:39 +00:00
Update trait_impls
This commit is contained in:
parent
270ee7eca3
commit
072449c0dc
@ -4,7 +4,7 @@ pub use self::definitions::{
|
||||
};
|
||||
|
||||
use crate::arena::Arena;
|
||||
use crate::dep_graph::{DepGraph, DepKind, DepNode, DepNodeIndex};
|
||||
use crate::dep_graph::{DepGraph, DepNodeIndex};
|
||||
use crate::hir::{HirOwner, HirOwnerItems};
|
||||
use crate::middle::cstore::CrateStoreDyn;
|
||||
use crate::ty::query::Providers;
|
||||
@ -13,7 +13,7 @@ use rustc_ast::ast::{self, Name, NodeId};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, DefIndex, LocalDefId};
|
||||
use rustc_hir::def_id::{DefId, DefIndex, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::print::Nested;
|
||||
@ -532,11 +532,7 @@ impl<'hir> Map<'hir> {
|
||||
}
|
||||
|
||||
pub fn trait_impls(&self, trait_did: DefId) -> &'hir [HirId] {
|
||||
self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls));
|
||||
|
||||
// N.B., intentionally bypass `self.krate()` so that we
|
||||
// do not trigger a read of the whole krate here
|
||||
self.krate.trait_impls.get(&trait_did).map_or(&[], |xs| &xs[..])
|
||||
self.tcx.all_local_trait_impls(LOCAL_CRATE).get(&trait_did).map_or(&[], |xs| &xs[..])
|
||||
}
|
||||
|
||||
/// Gets the attributes on the crate. This is preferable to
|
||||
|
@ -671,6 +671,9 @@ rustc_queries! {
|
||||
}
|
||||
|
||||
TypeChecking {
|
||||
query all_local_trait_impls(key: CrateNum) -> &'tcx BTreeMap<DefId, Vec<hir::HirId>> {
|
||||
desc { "local trait impls" }
|
||||
}
|
||||
query trait_impls_of(key: DefId) -> &'tcx ty::trait_def::TraitImpls {
|
||||
desc { |tcx| "trait impls of `{}`", tcx.def_path_str(key) }
|
||||
}
|
||||
|
@ -3142,8 +3142,11 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
|
||||
context::provide(providers);
|
||||
erase_regions::provide(providers);
|
||||
layout::provide(providers);
|
||||
*providers =
|
||||
ty::query::Providers { trait_impls_of: trait_def::trait_impls_of_provider, ..*providers };
|
||||
*providers = ty::query::Providers {
|
||||
trait_impls_of: trait_def::trait_impls_of_provider,
|
||||
all_local_trait_impls: trait_def::all_local_trait_impls,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
||||
/// A map for the local crate mapping each type to a vector of its
|
||||
|
@ -56,6 +56,7 @@ use rustc_attr as attr;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::BTreeMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
|
@ -5,11 +5,13 @@ use crate::ty::fast_reject;
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
use crate::ty::{Ty, TyCtxt};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::def_id::{CrateNum, DefId};
|
||||
use rustc_hir::HirId;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_macros::HashStable;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// A trait's definition with type information.
|
||||
#[derive(HashStable)]
|
||||
@ -146,6 +148,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
// Query provider for `all_local_trait_impls`.
|
||||
pub(super) fn all_local_trait_impls<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
krate: CrateNum,
|
||||
) -> &'tcx BTreeMap<DefId, Vec<HirId>> {
|
||||
&tcx.hir_crate(krate).trait_impls
|
||||
}
|
||||
|
||||
// Query provider for `trait_impls_of`.
|
||||
pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> &TraitImpls {
|
||||
let mut impls = TraitImpls::default();
|
||||
|
Loading…
Reference in New Issue
Block a user