Skip to content

Commit a5daf17

Browse files
committed
Update based on PR feedback
1 parent 21852e4 commit a5daf17

File tree

11 files changed

+49
-33
lines changed

11 files changed

+49
-33
lines changed

src/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2457,7 +2457,7 @@ The currently implemented features of the reference compiler are:
24572457
whether this will continue as a feature or not. For these reasons,
24582458
the glob import statement has been hidden behind this feature flag.
24592459

2460-
* `if_let` - Allows use of the `if let` desugaring syntax.
2460+
* `if_let` - Allows use of the `if let` syntax.
24612461

24622462
* `intrinsics` - Allows use of the "rust-intrinsics" ABI. Compiler intrinsics
24632463
are inherently unstable and no promise about them is made.

src/librustc/front/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'a> Visitor<()> for Context<'a> {
347347
// should not have happened, but the ExprMatch check is included just
348348
// in case.
349349
self.gate_feature("if_let", e.span,
350-
"`if let` desugaring is experimental");
350+
"`if let` syntax is experimental");
351351
}
352352
_ => {}
353353
}

src/librustc/middle/cfg/construct.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ impl<'a> CFGBuilder<'a> {
225225
self.add_node(expr.id, [then_exit, else_exit]) // 4, 5
226226
}
227227

228-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
228+
ast::ExprIfLet(..) => {
229+
self.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
230+
}
229231

230232
ast::ExprWhile(ref cond, ref body) => {
231233
//

src/librustc/middle/expr_use_visitor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
356356
}
357357
}
358358

359-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
359+
ast::ExprIfLet(..) => {
360+
self.tcx().sess.span_bug(expr.span, "non-desugared ExprIfLet");
361+
}
360362

361363
ast::ExprMatch(ref discr, ref arms, _) => {
362364
// treatment of the discriminant is handled while

src/librustc/middle/liveness.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
491491
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
492492
visit::walk_expr(ir, expr, ());
493493
}
494-
ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
494+
ExprIfLet(..) => {
495+
ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
496+
}
495497
ExprForLoop(ref pat, _, _, _) => {
496498
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
497499
debug!("adding local variable {} from for loop with bm {:?}",
@@ -1018,7 +1020,9 @@ impl<'a> Liveness<'a> {
10181020
self.propagate_through_expr(&**cond, ln)
10191021
}
10201022

1021-
ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
1023+
ExprIfLet(..) => {
1024+
self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
1025+
}
10221026

10231027
ExprWhile(ref cond, ref blk) => {
10241028
self.propagate_through_loop(expr,
@@ -1461,7 +1465,9 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14611465
ExprPath(..) | ExprBox(..) | ExprForLoop(..) => {
14621466
visit::walk_expr(this, expr, ());
14631467
}
1464-
ExprIfLet(..) => fail!("non-desugared ExprIfLet")
1468+
ExprIfLet(..) => {
1469+
this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
1470+
}
14651471
}
14661472
}
14671473

src/librustc/middle/mem_categorization.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,9 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> {
515515
Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty))
516516
}
517517

518-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet")
518+
ast::ExprIfLet(..) => {
519+
self.tcx().sess.span_bug(expr.span, "non-desugared ExprIfLet");
520+
}
519521
}
520522
}
521523

src/librustc/middle/ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3429,7 +3429,9 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
34293429
RvalueDpsExpr
34303430
}
34313431

3432-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
3432+
ast::ExprIfLet(..) => {
3433+
tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
3434+
}
34333435

34343436
ast::ExprLit(lit) if lit_is_str(lit) => {
34353437
RvalueDpsExpr

src/librustc/middle/typeck/check/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3430,7 +3430,9 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
34303430
check_then_else(fcx, &**cond, &**then_blk, opt_else_expr.clone(),
34313431
id, expr.span, expected);
34323432
}
3433-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
3433+
ast::ExprIfLet(..) => {
3434+
tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
3435+
}
34343436
ast::ExprWhile(ref cond, ref body) => {
34353437
check_expr_has_type(fcx, &**cond, ty::mk_bool());
34363438
check_block_no_value(fcx, &**body);

src/libsyntax/ext/expand.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,22 @@ fn expand_expr(e: Gc<ast::Expr>, fld: &mut MacroExpander) -> Gc<ast::Expr> {
127127
}
128128

129129
// Desugar support for ExprIfLet in the ExprIf else position
130-
ast::ExprIf(cond, blk, mut elseopt) => {
131-
// NOTE: replace with 'if let' after snapshot
132-
match elseopt {
133-
Some(els) => match els.node {
134-
ast::ExprIfLet(..) => {
135-
// wrap the if-let expr in a block
136-
let blk = P(ast::Block {
137-
view_items: vec![],
138-
stmts: vec![],
139-
expr: Some(els),
140-
id: ast::DUMMY_NODE_ID,
141-
rules: ast::DefaultBlock,
142-
span: els.span
143-
});
144-
elseopt = Some(fld.cx.expr_block(blk));
145-
}
146-
_ => ()
147-
},
148-
None => ()
149-
};
130+
ast::ExprIf(cond, blk, elseopt) => {
131+
let elseopt = elseopt.map(|els| match els.node {
132+
ast::ExprIfLet(..) => {
133+
// wrap the if-let expr in a block
134+
let blk = P(ast::Block {
135+
view_items: vec![],
136+
stmts: vec![],
137+
expr: Some(els),
138+
id: ast::DUMMY_NODE_ID,
139+
rules: ast::DefaultBlock,
140+
span: els.span
141+
});
142+
fld.cx.expr_block(blk)
143+
}
144+
_ => els
145+
});
150146
let if_expr = fld.cx.expr(e.span, ast::ExprIf(cond, blk, elseopt));
151147
noop_fold_expr(if_expr, fld)
152148
}

src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ impl<'a> Parser<'a> {
572572
if self.is_keyword(kw) {
573573
self.bump();
574574
true
575-
} else { false }
575+
} else {
576+
false
577+
}
576578
}
577579

578580
/// If the given word is not a keyword, signal an error.
@@ -2739,7 +2741,9 @@ impl<'a> Parser<'a> {
27392741
let thn = self.parse_block();
27402742
let els = if self.eat_keyword(keywords::Else) {
27412743
Some(self.parse_else_expr())
2742-
} else { None };
2744+
} else {
2745+
None
2746+
};
27432747
let hi = els.map_or(thn.span.hi, |expr| expr.span.hi);
27442748
self.mk_expr(lo, hi, ExprIfLet(pat, expr, thn, els))
27452749
}

src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ impl<'a> State<'a> {
14891489
try!(self.print_if(&**test, &**blk, elseopt));
14901490
}
14911491
ast::ExprIfLet(ref pat, ref expr, ref blk, elseopt) => {
1492-
try!(self.print_if_let(&**pat, &**expr, &** blk, elseopt));
1492+
try!(self.print_if_let(&**pat, &**expr, &**blk, elseopt));
14931493
}
14941494
ast::ExprWhile(ref test, ref blk) => {
14951495
try!(self.head("while"));

0 commit comments

Comments
 (0)