Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unconstrained terms should account for infer vars being equated #108879

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,42 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
};

// Guard against `<T as Trait<?0>>::Assoc = ?0>`.
struct ContainsTerm<'tcx> {
struct ContainsTerm<'a, 'tcx> {
term: ty::Term<'tcx>,
infcx: &'a InferCtxt<'tcx>,
}
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ContainsTerm<'tcx> {
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ContainsTerm<'_, 'tcx> {
type BreakTy = ();
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if t.needs_infer() {
if ty::Term::from(t) == self.term {
ControlFlow::Break(())
} else {
t.super_visit_with(self)
}
if let Some(vid) = t.ty_vid()
&& let ty::TermKind::Ty(term) = self.term.unpack()
&& let Some(term_vid) = term.ty_vid()
&& self.infcx.root_var(vid) == self.infcx.root_var(term_vid)
{
ControlFlow::Break(())
} else if t.has_non_region_infer() {
t.super_visit_with(self)
} else {
ControlFlow::Continue(())
}
}

fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if c.needs_infer() {
if ty::Term::from(c) == self.term {
ControlFlow::Break(())
} else {
c.super_visit_with(self)
}
if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = c.kind()
&& let ty::TermKind::Const(term) = self.term.unpack()
&& let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
&& self.infcx.root_const_var(vid) == self.infcx.root_const_var(term_vid)
{
ControlFlow::Break(())
} else if c.has_non_region_infer() {
c.super_visit_with(self)
} else {
ControlFlow::Continue(())
}
}
}

let mut visitor = ContainsTerm { term: goal.predicate.term };
let mut visitor = ContainsTerm { infcx: self.infcx, term: goal.predicate.term };

term_is_infer
&& goal.predicate.projection_ty.visit_with(&mut visitor).is_continue()
Expand Down