Skip to content

Commit 7c5cb73

Browse files
committed
Check for duplicates
1 parent b79a9a0 commit 7c5cb73

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ fn satisfied_from_param_env<'tcx>(
181181
&& ocx.eq(&ObligationCause::dummy(), self.param_env, c, self.ct).is_ok()
182182
&& ocx.select_all_or_error().is_empty()
183183
}) {
184-
self.single_match =
185-
if self.single_match.is_none() { Some(Ok(c)) } else { Some(Err(())) };
184+
self.single_match = match self.single_match {
185+
None => Some(Ok(c)),
186+
Some(Ok(o)) if o == c => Some(Ok(c)),
187+
Some(_) => Some(Err(())),
188+
};
186189
ControlFlow::CONTINUE
187190
} else if let ty::ConstKind::Expr(e) = c.kind() {
188191
e.visit_with(self)
@@ -207,8 +210,17 @@ fn satisfied_from_param_env<'tcx>(
207210
let b_ct = tcx.expand_abstract_consts(ce);
208211
let mut v = Visitor { ct, infcx, param_env, single_match: None };
209212
let _ = b_ct.visit_with(&mut v);
213+
210214
if let Some(inner) = v.single_match {
211-
single_match = if single_match.is_none() { Some(inner) } else { Some(Err(())) };
215+
single_match = if let Ok(inner) = inner {
216+
match single_match {
217+
None => Some(Ok(inner)),
218+
Some(Ok(prev)) if prev == inner => Some(Ok(prev)),
219+
Some(_) => Some(Err(())),
220+
}
221+
} else {
222+
Some(Err(()))
223+
};
212224
}
213225
}
214226
_ => {} // don't care

0 commit comments

Comments
 (0)