about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-01-17 20:21:26 +0100
committerGitHub <noreply@github.com>2023-01-17 20:21:26 +0100
commitfc9e2c1081354753346ab63ceebb3f44c7e384ae (patch)
treecb1872a518fcc7fdb479584ed40b710dcc04dccc
parent4ee5e09e19eccf6f61799122e63caa126ace3d97 (diff)
parent148e4f73dcc4bab82d0ad1689d2900e908133614 (diff)
downloadrust-fc9e2c1081354753346ab63ceebb3f44c7e384ae.tar.gz
rust-fc9e2c1081354753346ab63ceebb3f44c7e384ae.zip
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`
-rw-r--r--compiler/rustc_middle/src/infer/canonical.rs16
-rw-r--r--compiler/rustc_trait_selection/src/solve/mod.rs2
2 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs
index 614cf1a0051..7f3567c08be 100644
--- a/compiler/rustc_middle/src/infer/canonical.rs
+++ b/compiler/rustc_middle/src/infer/canonical.rs
@@ -68,6 +68,22 @@ pub struct CanonicalVarValues<'tcx> {
     pub var_values: IndexVec<BoundVar, GenericArg<'tcx>>,
 }
 
+impl CanonicalVarValues<'_> {
+    pub fn is_identity(&self) -> bool {
+        self.var_values.iter_enumerated().all(|(bv, arg)| match arg.unpack() {
+            ty::GenericArgKind::Lifetime(r) => {
+                matches!(*r, ty::ReLateBound(ty::INNERMOST, br) if br.var == bv)
+            }
+            ty::GenericArgKind::Type(ty) => {
+                matches!(*ty.kind(), ty::Bound(ty::INNERMOST, bt) if bt.var == bv)
+            }
+            ty::GenericArgKind::Const(ct) => {
+                matches!(ct.kind(), ty::ConstKind::Bound(ty::INNERMOST, bc) if bc == bv)
+            }
+        })
+    }
+}
+
 /// When we canonicalize a value to form a query, we wind up replacing
 /// various parts of it with canonical variables. This struct stores
 /// those replaced bits to remember for when we process the query
diff --git a/compiler/rustc_trait_selection/src/solve/mod.rs b/compiler/rustc_trait_selection/src/solve/mod.rs
index 042ba96b379..80775b7aaf2 100644
--- a/compiler/rustc_trait_selection/src/solve/mod.rs
+++ b/compiler/rustc_trait_selection/src/solve/mod.rs
@@ -178,7 +178,7 @@ impl<'tcx> EvalCtxt<'tcx> {
         let canonical_goal = infcx.canonicalize_query(goal, &mut orig_values);
         let canonical_response = self.evaluate_canonical_goal(canonical_goal)?;
         Ok((
-            true, // FIXME: check whether `var_values` are an identity substitution.
+            !canonical_response.value.var_values.is_identity(),
             instantiate_canonical_query_response(infcx, &orig_values, canonical_response),
         ))
     }