Rollup merge of #141059 - samueltardieu:push-trvpulpskwwp, r=compiler-errors

HIR: explain in comment why `ExprKind::If` "then" is an `Expr`

One could be tempted to replace the "then" `hir::Expr` with kind `hir::ExprKind::Block` by a `hir::Block`. Explain why this would not be a good idea.

I've been there.

r? ``@compiler-errors``
This commit is contained in:
Matthias Krüger 2025-05-17 10:33:11 +02:00 committed by GitHub
commit 59ad0cbd04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2744,6 +2744,8 @@ pub enum ExprKind<'hir> {
///
/// The "then" expr is always `ExprKind::Block`. If present, the "else" expr is always
/// `ExprKind::Block` (for `else`) or `ExprKind::If` (for `else if`).
/// Note that using an `Expr` instead of a `Block` for the "then" part is intentional,
/// as it simplifies the type coercion machinery.
If(&'hir Expr<'hir>, &'hir Expr<'hir>, Option<&'hir Expr<'hir>>),
/// A conditionless loop (can be exited with `break`, `continue`, or `return`).
///