Skip to content

Commit 11a6127

Browse files
committed
quote unquote Simplify coerce_from_inference_variable logic
1 parent d62f33a commit 11a6127

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
@@ -279,22 +279,21 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
279279
debug_assert!(self.shallow_resolve(b) == b);
280280

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

300299
debug!(

0 commit comments

Comments
 (0)