Rollup merge of #118243 - lcnr:commit-if-ok, r=compiler-errors

EvalCtxt::commit_if_ok don't inherit nested goals

we use it to check whether an alias is rigid, so we want to avoid considering an alias rigid simply because the inference constraints from normalizing it caused another nested goal fail

r? `@compiler-errors`
This commit is contained in:
Michael Goulet 2023-11-24 07:29:12 -08:00 committed by GitHub
commit 193e6687e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -1,4 +1,4 @@
use super::EvalCtxt;
use super::{EvalCtxt, NestedGoals};
use crate::solve::inspect;
use rustc_middle::traits::query::NoSolution;
@ -14,7 +14,7 @@ pub(in crate::solve) fn commit_if_ok<T>(
predefined_opaques_in_body: self.predefined_opaques_in_body,
max_input_universe: self.max_input_universe,
search_graph: self.search_graph,
nested_goals: self.nested_goals.clone(),
nested_goals: NestedGoals::new(),
tainted: self.tainted,
inspect: self.inspect.new_probe(),
};
@ -32,7 +32,7 @@ pub(in crate::solve) fn commit_if_ok<T>(
tainted,
inspect,
} = nested_ecx;
self.nested_goals = nested_goals;
self.nested_goals.extend(nested_goals);
self.tainted = tainted;
self.inspect.integrate_snapshot(inspect);
} else {

View File

@ -108,7 +108,7 @@ pub(super) struct NestedGoals<'tcx> {
pub(super) goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
}
impl NestedGoals<'_> {
impl<'tcx> NestedGoals<'tcx> {
pub(super) fn new() -> Self {
Self { normalizes_to_hack_goal: None, goals: Vec::new() }
}
@ -116,6 +116,11 @@ pub(super) fn new() -> Self {
pub(super) fn is_empty(&self) -> bool {
self.normalizes_to_hack_goal.is_none() && self.goals.is_empty()
}
pub(super) fn extend(&mut self, other: NestedGoals<'tcx>) {
assert_eq!(other.normalizes_to_hack_goal, None);
self.goals.extend(other.goals)
}
}
#[derive(PartialEq, Eq, Debug, Hash, HashStable, Clone, Copy)]

View File

@ -334,11 +334,6 @@ fn try_normalize_ty_recur(
}
}
// FIXME(@lcnr): If the normalization of the alias adds an inference constraint which
// causes a previously added goal to fail, then we treat the alias as rigid.
//
// These feels like a potential issue, I should look into writing some tests here
// and then probably changing `commit_if_ok` to not inherit the parent goals.
match self.commit_if_ok(|this| {
let normalized_ty = this.next_ty_infer();
let normalizes_to_goal = Goal::new(