From 7c5cb737357518c9a704994e007b32ed0da214f3 Mon Sep 17 00:00:00 2001 From: kadmin Date: Tue, 20 Dec 2022 21:11:19 +0000 Subject: [PATCH] Check for duplicates --- .../src/traits/const_evaluatable.rs | 18 +++++++++++++++--- 1 file 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 8530b96796f2..c4d5cf0309b9 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