Skip to content

Commit 13e00e4

Browse files
lilyballJakub Wieczorek
authored andcommitted
Update based on PR feedback
1 parent 8a60952 commit 13e00e4

File tree

11 files changed

+47
-32
lines changed

11 files changed

+47
-32
lines changed

src/doc/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,7 @@ The currently implemented features of the reference compiler are:
24412441
* `default_type_params` - Allows use of default type parameters. The future of
24422442
this feature is uncertain.
24432443

2444-
* `if_let` - Allows use of the `if let` desugaring syntax.
2444+
* `if_let` - Allows use of the `if let` syntax.
24452445

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

src/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
% The Rust Reference Manual
22

3-
The manual has moved, and is now called [the reference](reference.html).
3+
The manual has moved, and is now called [the reference](reference.html).

src/librustc/middle/cfg/construct.rs

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

225-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
225+
ast::ExprIfLet(..) => {
226+
self.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
227+
}
226228

227229
ast::ExprWhile(ref cond, ref body, _) => {
228230
//

src/librustc/middle/expr_use_visitor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
374374
}
375375
}
376376

377-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
377+
ast::ExprIfLet(..) => {
378+
self.tcx().sess.span_bug(expr.span, "non-desugared ExprIfLet");
379+
}
378380

379381
ast::ExprMatch(ref discr, ref arms, _) => {
380382
let discr_cmt = return_if_err!(self.mc.cat_expr(&**discr));

src/librustc/middle/liveness.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
481481
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
482482
visit::walk_expr(ir, expr);
483483
}
484-
ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
484+
ExprIfLet(..) => {
485+
ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
486+
}
485487
ExprForLoop(ref pat, _, _, _) => {
486488
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
487489
debug!("adding local variable {} from for loop with bm {:?}",
@@ -1012,7 +1014,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10121014
self.propagate_through_expr(&**cond, ln)
10131015
}
10141016

1015-
ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
1017+
ExprIfLet(..) => {
1018+
self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
1019+
}
10161020

10171021
ExprWhile(ref cond, ref blk, _) => {
10181022
self.propagate_through_loop(expr, WhileLoop(&**cond), &**blk, succ)
@@ -1473,7 +1477,9 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14731477
ExprPath(..) | ExprBox(..) => {
14741478
visit::walk_expr(this, expr);
14751479
}
1476-
ExprIfLet(..) => fail!("non-desugared ExprIfLet")
1480+
ExprIfLet(..) => {
1481+
this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
1482+
}
14771483
}
14781484
}
14791485

src/librustc/middle/mem_categorization.rs

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

509-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet")
509+
ast::ExprIfLet(..) => {
510+
self.tcx().sess.span_bug(expr.span, "non-desugared ExprIfLet");
511+
}
510512
}
511513
}
512514

src/librustc/middle/ty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3631,10 +3631,13 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
36313631
RvalueDpsExpr
36323632
}
36333633

3634+
ast::ExprIfLet(..) => {
3635+
tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
3636+
}
3637+
36343638
ast::ExprLit(ref lit) if lit_is_str(&**lit) => {
36353639
RvalueDpsExpr
36363640
}
3637-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
36383641

36393642
ast::ExprCast(..) => {
36403643
match tcx.node_types.borrow().find(&(expr.id as uint)) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4106,7 +4106,9 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
41064106
check_then_else(fcx, &**cond, &**then_blk, opt_else_expr.as_ref().map(|e| &**e),
41074107
id, expr.span, expected);
41084108
}
4109-
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
4109+
ast::ExprIfLet(..) => {
4110+
tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
4111+
}
41104112
ast::ExprWhile(ref cond, ref body, _) => {
41114113
check_expr_has_type(fcx, &**cond, ty::mk_bool());
41124114
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
@@ -132,26 +132,22 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
132132
}
133133

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

src/libsyntax/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
360360
}
361361
ast::ExprIfLet(..) => {
362362
self.gate_feature("if_let", e.span,
363-
"`if let` desugaring is experimental");
363+
"`if let` syntax is experimental");
364364
}
365365
_ => {}
366366
}

src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ impl<'a> Parser<'a> {
579579
if self.is_keyword(kw) {
580580
self.bump();
581581
true
582-
} else { false }
582+
} else {
583+
false
584+
}
583585
}
584586

585587
/// If the given word is not a keyword, signal an error.

0 commit comments

Comments
 (0)