Compute all_traits_impls during resolution.
This commit is contained in:
parent
26eeec0baf
commit
635978041d
@ -383,15 +383,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
this.lower_trait_ref(trait_ref, ImplTraitContext::disallowed())
|
||||
});
|
||||
|
||||
if let Some(ref trait_ref) = trait_ref {
|
||||
if let Res::Def(DefKind::Trait, def_id) = trait_ref.path.res {
|
||||
this.trait_impls
|
||||
.entry(def_id)
|
||||
.or_default()
|
||||
.push(lowered_trait_def_id);
|
||||
}
|
||||
}
|
||||
|
||||
let lowered_ty = this.lower_ty(ty, ImplTraitContext::disallowed());
|
||||
|
||||
(trait_ref, lowered_ty)
|
||||
|
@ -104,8 +104,6 @@ struct LoweringContext<'a, 'hir: 'a> {
|
||||
owners: IndexVec<LocalDefId, Option<hir::OwnerNode<'hir>>>,
|
||||
bodies: BTreeMap<hir::BodyId, hir::Body<'hir>>,
|
||||
|
||||
trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
|
||||
|
||||
modules: BTreeMap<LocalDefId, hir::ModuleItems>,
|
||||
|
||||
generator_kind: Option<hir::GeneratorKind>,
|
||||
@ -324,7 +322,6 @@ pub fn lower_crate<'a, 'hir>(
|
||||
arena,
|
||||
owners: IndexVec::default(),
|
||||
bodies: BTreeMap::new(),
|
||||
trait_impls: BTreeMap::new(),
|
||||
modules: BTreeMap::new(),
|
||||
attrs: BTreeMap::default(),
|
||||
catch_scopes: Vec::new(),
|
||||
@ -512,7 +509,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
let krate = hir::Crate {
|
||||
owners: self.owners,
|
||||
bodies: self.bodies,
|
||||
trait_impls: self.trait_impls,
|
||||
modules: self.modules,
|
||||
proc_macros,
|
||||
trait_map,
|
||||
|
@ -672,7 +672,6 @@ pub struct ModuleItems {
|
||||
pub struct Crate<'hir> {
|
||||
pub owners: IndexVec<LocalDefId, Option<OwnerNode<'hir>>>,
|
||||
pub bodies: BTreeMap<BodyId, Body<'hir>>,
|
||||
pub trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
|
||||
|
||||
/// A list of modules written out in the order in which they
|
||||
/// appear in the crate. This includes the main crate module.
|
||||
|
@ -170,7 +170,7 @@ pub fn provide(providers: &mut Providers) {
|
||||
}
|
||||
};
|
||||
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local());
|
||||
providers.all_local_trait_impls = |tcx, ()| &tcx.hir_crate(()).trait_impls;
|
||||
providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
|
||||
providers.expn_that_defined = |tcx, id| {
|
||||
let id = id.expect_local();
|
||||
tcx.resolutions(()).definitions.expansion_that_defined(id)
|
||||
|
@ -44,6 +44,7 @@ use rustc_span::Span;
|
||||
use rustc_target::abi::Align;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::BTreeMap;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::ControlFlow;
|
||||
use std::{fmt, ptr, str};
|
||||
@ -132,6 +133,7 @@ pub struct ResolverOutputs {
|
||||
/// via `extern crate` item and not `--extern` option or compiler built-in.
|
||||
pub extern_prelude: FxHashMap<Symbol, bool>,
|
||||
pub main_def: Option<MainDefinition>,
|
||||
pub trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
@ -1281,7 +1281,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
this.with_self_rib(Res::SelfTy(None, None), |this| {
|
||||
// Resolve the trait reference, if necessary.
|
||||
this.with_optional_trait_ref(opt_trait_reference.as_ref(), |this, trait_id| {
|
||||
let item_def_id = this.r.local_def_id(item_id).to_def_id();
|
||||
let item_def_id = this.r.local_def_id(item_id);
|
||||
|
||||
// Register the trait definitions from here.
|
||||
if let Some(trait_id) = trait_id {
|
||||
this.r.trait_impls.entry(trait_id).or_default().push(item_def_id);
|
||||
}
|
||||
|
||||
let item_def_id = item_def_id.to_def_id();
|
||||
this.with_self_rib(Res::SelfTy(trait_id, Some((item_def_id, false))), |this| {
|
||||
if let Some(trait_ref) = opt_trait_reference.as_ref() {
|
||||
// Resolve type arguments in the trait path.
|
||||
|
@ -60,7 +60,7 @@ use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::ops::ControlFlow;
|
||||
use std::{cmp, fmt, iter, ptr};
|
||||
use tracing::debug;
|
||||
@ -1034,6 +1034,7 @@ pub struct Resolver<'a> {
|
||||
item_generics_num_lifetimes: FxHashMap<LocalDefId, usize>,
|
||||
|
||||
main_def: Option<MainDefinition>,
|
||||
trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
|
||||
}
|
||||
|
||||
/// Nothing really interesting here; it just provides memory for the rest of the crate.
|
||||
@ -1398,6 +1399,7 @@ impl<'a> Resolver<'a> {
|
||||
legacy_const_generic_args: Default::default(),
|
||||
item_generics_num_lifetimes: Default::default(),
|
||||
main_def: Default::default(),
|
||||
trait_impls: Default::default(),
|
||||
};
|
||||
|
||||
let root_parent_scope = ParentScope::module(graph_root, &resolver);
|
||||
@ -1455,6 +1457,7 @@ impl<'a> Resolver<'a> {
|
||||
.map(|(ident, entry)| (ident.name, entry.introduced_by_item))
|
||||
.collect(),
|
||||
main_def,
|
||||
trait_impls: self.trait_impls,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1474,6 +1477,7 @@ impl<'a> Resolver<'a> {
|
||||
.map(|(ident, entry)| (ident.name, entry.introduced_by_item))
|
||||
.collect(),
|
||||
main_def: self.main_def.clone(),
|
||||
trait_impls: self.trait_impls.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
|
||||
}
|
||||
|
||||
pub fn check_coherence(tcx: TyCtxt<'_>) {
|
||||
for &trait_def_id in tcx.hir().krate().trait_impls.keys() {
|
||||
for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
|
||||
tcx.ensure().coherent_trait(trait_def_id);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user