Re-introduce cycle-check in assoc. item resolution.
This commit is contained in:
parent
8da2fe8ed7
commit
40a6734ae1
1 changed files with 32 additions and 6 deletions
|
@ -29,6 +29,7 @@ use infer::type_variable::TypeVariableOrigin;
|
||||||
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
|
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::symbol::Symbol;
|
use syntax::symbol::Symbol;
|
||||||
|
use syntax_pos::DUMMY_SP;
|
||||||
use ty::subst::Subst;
|
use ty::subst::Subst;
|
||||||
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
|
use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt};
|
||||||
use ty::fold::{TypeFoldable, TypeFolder};
|
use ty::fold::{TypeFoldable, TypeFolder};
|
||||||
|
@ -1317,13 +1318,38 @@ fn assoc_ty_def<'cx, 'gcx, 'tcx>(
|
||||||
assoc_ty_name: ast::Name)
|
assoc_ty_name: ast::Name)
|
||||||
-> Option<specialization_graph::NodeItem<ty::AssociatedItem>>
|
-> Option<specialization_graph::NodeItem<ty::AssociatedItem>>
|
||||||
{
|
{
|
||||||
let trait_def_id = selcx.tcx().impl_trait_ref(impl_def_id).unwrap().def_id;
|
let tcx = selcx.tcx();
|
||||||
let trait_def = selcx.tcx().trait_def(trait_def_id);
|
let trait_def_id = tcx.impl_trait_ref(impl_def_id).unwrap().def_id;
|
||||||
|
let trait_def = tcx.trait_def(trait_def_id);
|
||||||
|
|
||||||
trait_def
|
// This function may be called while we are still building the
|
||||||
.ancestors(selcx.tcx(), impl_def_id)
|
// specialization graph that is queried below (via TraidDef::ancestors()),
|
||||||
.defs(selcx.tcx(), assoc_ty_name, ty::AssociatedKind::Type)
|
// so, in order to avoid infinite recursion, we detect this case by
|
||||||
.next()
|
// seeing if a query of the specialization graph fails with a cycle error.
|
||||||
|
// If we are in cycle, and thus still building the graph, we perform a
|
||||||
|
// reduced version of the associated item lookup that does not need the
|
||||||
|
// specialization graph.
|
||||||
|
let specialization_graph_complete =
|
||||||
|
ty::queries::specialization_graph_of::try_get(tcx,
|
||||||
|
DUMMY_SP,
|
||||||
|
trait_def_id).is_ok();
|
||||||
|
if !specialization_graph_complete {
|
||||||
|
let impl_node = specialization_graph::Node::Impl(impl_def_id);
|
||||||
|
for item in impl_node.items(tcx) {
|
||||||
|
if item.kind == ty::AssociatedKind::Type && item.name == assoc_ty_name {
|
||||||
|
return Some(specialization_graph::NodeItem {
|
||||||
|
node: specialization_graph::Node::Impl(impl_def_id),
|
||||||
|
item: item,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
trait_def
|
||||||
|
.ancestors(tcx, impl_def_id)
|
||||||
|
.defs(tcx, assoc_ty_name, ty::AssociatedKind::Type)
|
||||||
|
.next()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// # Cache
|
// # Cache
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue