Skip to content

Commit a889c93

Browse files
committed
quote unquote Simplify coerce_from_inference_variable logic
1 parent 292db4a commit a889c93

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,22 +281,21 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
281281
debug_assert!(self.shallow_resolve(b) == b);
282282

283283
if b.is_ty_var() {
284-
// Two unresolved type variables: create a `Coerce` predicate.
285-
let target_ty = if self.use_lub { self.next_ty_var(self.cause.span) } else { b };
286-
287284
let mut obligations = PredicateObligations::with_capacity(2);
288-
for &source_ty in &[a, b] {
289-
if source_ty != target_ty {
290-
obligations.push(Obligation::new(
291-
self.tcx(),
292-
self.cause.clone(),
293-
self.param_env,
294-
ty::Binder::dummy(ty::PredicateKind::Coerce(ty::CoercePredicate {
295-
a: source_ty,
296-
b: target_ty,
297-
})),
298-
));
299-
}
285+
let mut push_coerce_obligation = |a, b| {
286+
obligations.push(Obligation::new(
287+
self.tcx(),
288+
self.cause.clone(),
289+
self.param_env,
290+
ty::Binder::dummy(ty::PredicateKind::Coerce(ty::CoercePredicate { a, b })),
291+
));
292+
};
293+
294+
let target_ty = self.use_lub.then(|| self.next_ty_var(self.cause.span)).unwrap_or(b);
295+
296+
push_coerce_obligation(a, target_ty);
297+
if self.use_lub {
298+
push_coerce_obligation(b, target_ty);
300299
}
301300

302301
debug!(

0 commit comments

Comments
 (0)