Skip to content

Commit

Permalink
Rollup merge of #98219 - eggyal:gatsubstcollector-without-folding, r=…
Browse files Browse the repository at this point in the history
…jackh726

Skip late bound regions in GATSubstCollector

#93227 liberated late bound regions when collecting GAT substs in wfcheck.  It should simply skip late bound regions instead.

r? ``@compiler-errors``
  • Loading branch information
Dylan-DPC authored Jun 19, 2022
2 parents 88cb597 + c51f508 commit cf3245e
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
// The bounds we that we would require from `to_check`
let mut bounds = FxHashSet::default();

let (regions, types) = GATSubstCollector::visit(tcx, gat_def_id.to_def_id(), to_check);
let (regions, types) = GATSubstCollector::visit(gat_def_id.to_def_id(), to_check);

// If both regions and types are empty, then this GAT isn't in the
// set of types we are checking, and we shouldn't try to do clause analysis
Expand Down Expand Up @@ -664,7 +664,6 @@ fn resolve_regions_with_wf_tys<'tcx>(
/// the two vectors, `regions` and `types` (depending on their kind). For each
/// parameter `Pi` also track the index `i`.
struct GATSubstCollector<'tcx> {
tcx: TyCtxt<'tcx>,
gat: DefId,
// Which region appears and which parameter index its substituted for
regions: FxHashSet<(ty::Region<'tcx>, usize)>,
Expand All @@ -674,16 +673,11 @@ struct GATSubstCollector<'tcx> {

impl<'tcx> GATSubstCollector<'tcx> {
fn visit<T: TypeFoldable<'tcx>>(
tcx: TyCtxt<'tcx>,
gat: DefId,
t: T,
) -> (FxHashSet<(ty::Region<'tcx>, usize)>, FxHashSet<(Ty<'tcx>, usize)>) {
let mut visitor = GATSubstCollector {
tcx,
gat,
regions: FxHashSet::default(),
types: FxHashSet::default(),
};
let mut visitor =
GATSubstCollector { gat, regions: FxHashSet::default(), types: FxHashSet::default() };
t.visit_with(&mut visitor);
(visitor.regions, visitor.types)
}
Expand All @@ -692,19 +686,12 @@ impl<'tcx> GATSubstCollector<'tcx> {
impl<'tcx> TypeVisitor<'tcx> for GATSubstCollector<'tcx> {
type BreakTy = !;

fn visit_binder<T: TypeFoldable<'tcx>>(
&mut self,
t: &ty::Binder<'tcx, T>,
) -> ControlFlow<Self::BreakTy> {
self.tcx.liberate_late_bound_regions(self.gat, t.clone()).visit_with(self)
}

fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
match t.kind() {
ty::Projection(p) if p.item_def_id == self.gat => {
for (idx, subst) in p.substs.iter().enumerate() {
match subst.unpack() {
GenericArgKind::Lifetime(lt) => {
GenericArgKind::Lifetime(lt) if !lt.is_late_bound() => {
self.regions.insert((lt, idx));
}
GenericArgKind::Type(t) => {
Expand Down

0 comments on commit cf3245e

Please sign in to comment.