Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726
Ensure valid TraitRefs are created for GATs This fixes `ProjectionTy::trait_ref` to use the correct substs. Places that need all of the substs have been updated to not use `trait_ref`. r? ````@jackh726````
This commit is contained in:
commit
66211f6657
34 changed files with 542 additions and 239 deletions
|
@ -77,6 +77,12 @@ trait DefIdVisitor<'tcx> {
|
|||
fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
self.skeleton().visit_trait(trait_ref)
|
||||
}
|
||||
fn visit_projection_ty(
|
||||
&mut self,
|
||||
projection: ty::ProjectionTy<'tcx>,
|
||||
) -> ControlFlow<Self::BreakTy> {
|
||||
self.skeleton().visit_projection_ty(projection)
|
||||
}
|
||||
fn visit_predicates(
|
||||
&mut self,
|
||||
predicates: ty::GenericPredicates<'tcx>,
|
||||
|
@ -101,6 +107,20 @@ where
|
|||
if self.def_id_visitor.shallow() { ControlFlow::CONTINUE } else { substs.visit_with(self) }
|
||||
}
|
||||
|
||||
fn visit_projection_ty(
|
||||
&mut self,
|
||||
projection: ty::ProjectionTy<'tcx>,
|
||||
) -> ControlFlow<V::BreakTy> {
|
||||
let (trait_ref, assoc_substs) =
|
||||
projection.trait_ref_and_own_substs(self.def_id_visitor.tcx());
|
||||
self.visit_trait(trait_ref)?;
|
||||
if self.def_id_visitor.shallow() {
|
||||
ControlFlow::CONTINUE
|
||||
} else {
|
||||
assoc_substs.iter().try_for_each(|subst| subst.visit_with(self))
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<V::BreakTy> {
|
||||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref }, _) => {
|
||||
|
@ -108,7 +128,7 @@ where
|
|||
}
|
||||
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, ty }) => {
|
||||
ty.visit_with(self)?;
|
||||
self.visit_trait(projection_ty.trait_ref(self.def_id_visitor.tcx()))
|
||||
self.visit_projection_ty(projection_ty)
|
||||
}
|
||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty, _region)) => {
|
||||
ty.visit_with(self)
|
||||
|
@ -197,7 +217,7 @@ where
|
|||
return ControlFlow::CONTINUE;
|
||||
}
|
||||
// This will also visit substs if necessary, so we don't need to recurse.
|
||||
return self.visit_trait(proj.trait_ref(tcx));
|
||||
return self.visit_projection_ty(proj);
|
||||
}
|
||||
ty::Dynamic(predicates, ..) => {
|
||||
// All traits in the list are considered the "primary" part of the type
|
||||
|
@ -1203,10 +1223,9 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
|
|||
}
|
||||
|
||||
for (poly_predicate, _) in bounds.projection_bounds {
|
||||
let tcx = self.tcx;
|
||||
if self.visit(poly_predicate.skip_binder().ty).is_break()
|
||||
|| self
|
||||
.visit_trait(poly_predicate.skip_binder().projection_ty.trait_ref(tcx))
|
||||
.visit_projection_ty(poly_predicate.skip_binder().projection_ty)
|
||||
.is_break()
|
||||
{
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue