Skip to content

Commit bcf2490

Browse files
authored
Rollup merge of #140572 - nnethercote:comment-ExprKind-If, r=compiler-errors
Add useful comments on `ExprKind::If` variants. Things that aren't obvious and took me a while to work out. r? `@BoxyUwU`
2 parents bfb8f73 + 0ea204a commit bcf2490

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

compiler/rustc_ast/src/ast.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,9 @@ pub enum ExprKind {
16331633
/// An `if` block, with an optional `else` block.
16341634
///
16351635
/// `if expr { block } else { expr }`
1636+
///
1637+
/// If present, the "else" expr is always `ExprKind::Block` (for `else`) or
1638+
/// `ExprKind::If` (for `else if`).
16361639
If(P<Expr>, P<Block>, Option<P<Expr>>),
16371640
/// A while loop, with an optional label.
16381641
///

compiler/rustc_hir/src/hir.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2741,6 +2741,9 @@ pub enum ExprKind<'hir> {
27412741
/// An `if` block, with an optional else block.
27422742
///
27432743
/// I.e., `if <expr> { <expr> } else { <expr> }`.
2744+
///
2745+
/// The "then" expr is always `ExprKind::Block`. If present, the "else" expr is always
2746+
/// `ExprKind::Block` (for `else`) or `ExprKind::If` (for `else if`).
27442747
If(&'hir Expr<'hir>, &'hir Expr<'hir>, Option<&'hir Expr<'hir>>),
27452748
/// A conditionless loop (can be exited with `break`, `continue`, or `return`).
27462749
///

compiler/rustc_middle/src/thir.rs

+3
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ pub enum ExprKind<'tcx> {
292292
If {
293293
if_then_scope: region::Scope,
294294
cond: ExprId,
295+
/// `then` is always `ExprKind::Block`.
295296
then: ExprId,
297+
/// If present, the `else_opt` expr is always `ExprKind::Block` (for
298+
/// `else`) or `ExprKind::If` (for `else if`).
296299
else_opt: Option<ExprId>,
297300
},
298301
/// A function call. Method calls and overloaded operators are converted to plain function calls.

0 commit comments

Comments
 (0)