Skip to content

Commit f07097a

Browse files
committed
Add comment
1 parent 8aa55e7 commit f07097a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/libsyntax_ext/assert.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<'cx, 'a: 'cx> Context<'cx, 'a> {
310310
CondExpr::literal(lit.node.clone()),
311311
escape_format_string(&unescape_printable_unicode(&pprust::expr_to_string(&expr))),
312312
),
313-
// Otherwise capture and stop recursing.
313+
// Otherwise capture it and stop recursing.
314314
_ => self.scan_capture_expr(P(expr), BindingMode::ByValue(Mutability::Immutable)),
315315
}
316316
}
@@ -329,8 +329,8 @@ impl<'cx, 'a: 'cx> Context<'cx, 'a> {
329329
expr_str: pprust::expr_to_string(&expr),
330330
var: capture,
331331
decl: if mode.is_by_ref() {
332-
// `#[allow(unused)] let __capture{} = Unevaluated;`
333-
// Can be unused if the variable cannot be seen from any branch.
332+
// Placeholder variable: `#[allow(unused)] let __capture{} = Unevaluated;`
333+
// Can be unused if the variable is shadowed in all branches.
334334
let allow_unused = {
335335
let word = self.ecx
336336
.meta_list_item_word(self.sp, Symbol::intern("unused"));
@@ -399,16 +399,23 @@ impl<'cx, 'a: 'cx> Context<'cx, 'a> {
399399
//
400400
// ```rust
401401
// // By-reference capture: eagerly evaluated
402-
// match &expr {
403-
// __captureN => if ... { action(__captureN) }
402+
// match expr0 { ref __capture0 =>
403+
// match expr1 { ref __capture1 =>
404+
// if __capture0 && __capture1 { .. }
405+
// // Both are evaluated even if `!expr0`
406+
// }
404407
// }
405408
//
406409
// // By-value capture: lazily evaluated
407-
// if ... { action({ let tmp = expr; ... }) }
410+
// if { let tmp = expr0; ...; tmp }
411+
// && { let tmp = expr1; ...; tmp } { .. }
412+
// // `expr1` is evaluated only if `expr0` is true
408413
// ```
409414

410415
match expr.node {
411416
CondExprKind::BinOp(op, left, right) => {
417+
// Evaluates `left` first and then `right`.
418+
412419
let left_by_ref = left.is_by_ref_capture();
413420
let right_by_ref = right.is_by_ref_capture();
414421

@@ -475,6 +482,7 @@ impl<'cx, 'a: 'cx> Context<'cx, 'a> {
475482
}
476483
CondExprKind::Capture(expr, idx, mode) => {
477484
if mode.is_by_ref() {
485+
// Shadows the placeholder variable.
478486
let ident = Ident::from_str(&format!("__capture{}", idx));
479487
self.single_match(
480488
expr,
@@ -575,6 +583,7 @@ impl<'cx, 'a: 'cx> Context<'cx, 'a> {
575583
))
576584
}
577585

586+
/// Generates `match expr { __tmpN => f(__tmpN) }`.
578587
fn tmp_match<F: FnOnce(P<Expr>) -> P<Expr>>(
579588
&self,
580589
expr: P<Expr>,

0 commit comments

Comments
 (0)