about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_trait_selection/src/traits/const_evaluatable.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
index 8530b96796f..c4d5cf0309b 100644
--- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
+++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
@@ -181,8 +181,11 @@ fn satisfied_from_param_env<'tcx>(
                     && ocx.eq(&ObligationCause::dummy(), self.param_env, c, self.ct).is_ok()
                     && ocx.select_all_or_error().is_empty()
             }) {
-                self.single_match =
-                    if self.single_match.is_none() { Some(Ok(c)) } else { Some(Err(())) };
+                self.single_match = match self.single_match {
+                    None => Some(Ok(c)),
+                    Some(Ok(o)) if o == c => Some(Ok(c)),
+                    Some(_) => Some(Err(())),
+                };
                 ControlFlow::CONTINUE
             } else if let ty::ConstKind::Expr(e) = c.kind() {
                 e.visit_with(self)
@@ -207,8 +210,17 @@ fn satisfied_from_param_env<'tcx>(
                 let b_ct = tcx.expand_abstract_consts(ce);
                 let mut v = Visitor { ct, infcx, param_env, single_match: None };
                 let _ = b_ct.visit_with(&mut v);
+
                 if let Some(inner) = v.single_match {
-                    single_match = if single_match.is_none() { Some(inner) } else { Some(Err(())) };
+                    single_match = if let Ok(inner) = inner {
+                        match single_match {
+                            None => Some(Ok(inner)),
+                            Some(Ok(prev)) if prev == inner => Some(Ok(prev)),
+                            Some(_) => Some(Err(())),
+                        }
+                    } else {
+                        Some(Err(()))
+                    };
                 }
             }
             _ => {} // don't care