Skip to content

Commit d0fc6e7

Browse files
committed
Add comment
1 parent 94946be commit d0fc6e7

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,14 +1519,21 @@ impl<'tcx> CoerceMany<'tcx> {
15191519

15201520
// Handle the actual type unification etc.
15211521
let result = if let Some(expression) = expression {
1522+
// For the *first* expression being coerced, we call `fcx.coerce`,
1523+
// which will actually end up using `Sub` rather tha `Lub`.
1524+
// This is not the most ideal thing to do (we should probably only
1525+
// be doing this when there is *only* one expression), but this
1526+
// breaks all over the place when removing this special-case.
1527+
// So, for now, to keep things *logically* a bit more simple, we
1528+
// have a `force_lub` option that callers can use (currently only
1529+
// is set in match coercion) to guarantee that all expressions use
1530+
// Lub coercion.
15221531
if !self.force_lub && self.expressions.is_empty() {
1523-
// Special-case the first expression we are coercing.
1524-
// To be honest, I'm not entirely sure why we do this.
1525-
// We don't allow two-phase borrows, see comment in try_find_coercion_lub for why
15261532
fcx.coerce(
15271533
expression,
15281534
expression_ty,
15291535
self.expected_ty,
1536+
// We don't allow two-phase borrows, see comment in try_find_coercion_lub for why
15301537
AllowTwoPhase::No,
15311538
Some(cause.clone()),
15321539
)

0 commit comments

Comments
 (0)