Skip to content

Commit fc9e2c1

Browse files
authored
Rollup merge of #106834 - compiler-errors:new-solver-did-changed, r=lcnr
new trait solver: only consider goal changed if response is not identity I think this is the right way of implementing it.. r? `@lcnr`
2 parents 4ee5e09 + 148e4f7 commit fc9e2c1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/rustc_middle/src/infer/canonical.rs

+16
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ pub struct CanonicalVarValues<'tcx> {
6868
pub var_values: IndexVec<BoundVar, GenericArg<'tcx>>,
6969
}
7070

71+
impl CanonicalVarValues<'_> {
72+
pub fn is_identity(&self) -> bool {
73+
self.var_values.iter_enumerated().all(|(bv, arg)| match arg.unpack() {
74+
ty::GenericArgKind::Lifetime(r) => {
75+
matches!(*r, ty::ReLateBound(ty::INNERMOST, br) if br.var == bv)
76+
}
77+
ty::GenericArgKind::Type(ty) => {
78+
matches!(*ty.kind(), ty::Bound(ty::INNERMOST, bt) if bt.var == bv)
79+
}
80+
ty::GenericArgKind::Const(ct) => {
81+
matches!(ct.kind(), ty::ConstKind::Bound(ty::INNERMOST, bc) if bc == bv)
82+
}
83+
})
84+
}
85+
}
86+
7187
/// When we canonicalize a value to form a query, we wind up replacing
7288
/// various parts of it with canonical variables. This struct stores
7389
/// those replaced bits to remember for when we process the query

compiler/rustc_trait_selection/src/solve/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'tcx> EvalCtxt<'tcx> {
178178
let canonical_goal = infcx.canonicalize_query(goal, &mut orig_values);
179179
let canonical_response = self.evaluate_canonical_goal(canonical_goal)?;
180180
Ok((
181-
true, // FIXME: check whether `var_values` are an identity substitution.
181+
!canonical_response.value.var_values.is_identity(),
182182
instantiate_canonical_query_response(infcx, &orig_values, canonical_response),
183183
))
184184
}

0 commit comments

Comments
 (0)