Skip to content

Commit

Permalink
Update based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyball authored and Jakub Wieczorek committed Sep 30, 2014
1 parent 8a60952 commit 13e00e4
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/doc/reference.md
Expand Up @@ -2441,7 +2441,7 @@ The currently implemented features of the reference compiler are:
* `default_type_params` - Allows use of default type parameters. The future of
this feature is uncertain.

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

* `intrinsics` - Allows use of the "rust-intrinsics" ABI. Compiler intrinsics
are inherently unstable and no promise about them is made.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rust.md
@@ -1,3 +1,3 @@
% The Rust Reference Manual

The manual has moved, and is now called [the reference](reference.html).
The manual has moved, and is now called [the reference](reference.html).
4 changes: 3 additions & 1 deletion src/librustc/middle/cfg/construct.rs
Expand Up @@ -222,7 +222,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.add_node(expr.id, [then_exit, else_exit]) // 4, 5
}

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

ast::ExprWhile(ref cond, ref body, _) => {
//
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -374,7 +374,9 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
}
}

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

ast::ExprMatch(ref discr, ref arms, _) => {
let discr_cmt = return_if_err!(self.mc.cat_expr(&**discr));
Expand Down
12 changes: 9 additions & 3 deletions src/librustc/middle/liveness.rs
Expand Up @@ -481,7 +481,9 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
visit::walk_expr(ir, expr);
}
ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
ExprIfLet(..) => {
ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}
ExprForLoop(ref pat, _, _, _) => {
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
debug!("adding local variable {} from for loop with bm {:?}",
Expand Down Expand Up @@ -1012,7 +1014,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**cond, ln)
}

ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
ExprIfLet(..) => {
self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}

ExprWhile(ref cond, ref blk, _) => {
self.propagate_through_loop(expr, WhileLoop(&**cond), &**blk, succ)
Expand Down Expand Up @@ -1473,7 +1477,9 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
ExprPath(..) | ExprBox(..) => {
visit::walk_expr(this, expr);
}
ExprIfLet(..) => fail!("non-desugared ExprIfLet")
ExprIfLet(..) => {
this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -506,7 +506,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty))
}

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

Expand Down
5 changes: 4 additions & 1 deletion src/librustc/middle/ty.rs
Expand Up @@ -3631,10 +3631,13 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
RvalueDpsExpr
}

ast::ExprIfLet(..) => {
tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}

ast::ExprLit(ref lit) if lit_is_str(&**lit) => {
RvalueDpsExpr
}
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),

ast::ExprCast(..) => {
match tcx.node_types.borrow().find(&(expr.id as uint)) {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -4106,7 +4106,9 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
check_then_else(fcx, &**cond, &**then_blk, opt_else_expr.as_ref().map(|e| &**e),
id, expr.span, expected);
}
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
ast::ExprIfLet(..) => {
tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}
ast::ExprWhile(ref cond, ref body, _) => {
check_expr_has_type(fcx, &**cond, ty::mk_bool());
check_block_no_value(fcx, &**body);
Expand Down
36 changes: 16 additions & 20 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -132,26 +132,22 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
}

// Desugar support for ExprIfLet in the ExprIf else position
ast::ExprIf(cond, blk, mut elseopt) => {
// NOTE: replace with 'if let' after snapshot
match elseopt {
Some(els) => match els.node {
ast::ExprIfLet(..) => {
// wrap the if-let expr in a block
let blk = P(ast::Block {
view_items: vec![],
stmts: vec![],
expr: Some(els),
id: ast::DUMMY_NODE_ID,
rules: ast::DefaultBlock,
span: els.span
});
elseopt = Some(fld.cx.expr_block(blk));
}
_ => ()
},
None => ()
};
ast::ExprIf(cond, blk, elseopt) => {
let elseopt = elseopt.map(|els| match els.node {
ast::ExprIfLet(..) => {
// wrap the if-let expr in a block
let blk = P(ast::Block {
view_items: vec![],
stmts: vec![],
expr: Some(els),
id: ast::DUMMY_NODE_ID,
rules: ast::DefaultBlock,
span: els.span
});
fld.cx.expr_block(blk)
}
_ => els
});
let if_expr = fld.cx.expr(e.span, ast::ExprIf(cond, blk, elseopt));
noop_fold_expr(if_expr, fld)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/feature_gate.rs
Expand Up @@ -360,7 +360,7 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
}
ast::ExprIfLet(..) => {
self.gate_feature("if_let", e.span,
"`if let` desugaring is experimental");
"`if let` syntax is experimental");
}
_ => {}
}
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -579,7 +579,9 @@ impl<'a> Parser<'a> {
if self.is_keyword(kw) {
self.bump();
true
} else { false }
} else {
false
}
}

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

0 comments on commit 13e00e4

Please sign in to comment.