1
Fork 0

Update based on PR feedback

This commit is contained in:
Kevin Ballard 2014-08-27 21:34:03 -07:00 committed by Jakub Wieczorek
parent 8a60952100
commit 13e00e4a3d
11 changed files with 47 additions and 32 deletions

View file

@ -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 * `default_type_params` - Allows use of default type parameters. The future of
this feature is uncertain. 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 * `intrinsics` - Allows use of the "rust-intrinsics" ABI. Compiler intrinsics
are inherently unstable and no promise about them is made. are inherently unstable and no promise about them is made.

View file

@ -222,7 +222,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.add_node(expr.id, [then_exit, else_exit]) // 4, 5 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, _) => { ast::ExprWhile(ref cond, ref body, _) => {
// //

View file

@ -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, _) => { ast::ExprMatch(ref discr, ref arms, _) => {
let discr_cmt = return_if_err!(self.mc.cat_expr(&**discr)); let discr_cmt = return_if_err!(self.mc.cat_expr(&**discr));

View file

@ -481,7 +481,9 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
visit::walk_expr(ir, expr); visit::walk_expr(ir, expr);
} }
ExprIfLet(..) => fail!("non-desugared ExprIfLet"), ExprIfLet(..) => {
ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}
ExprForLoop(ref pat, _, _, _) => { ExprForLoop(ref pat, _, _, _) => {
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| { pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
debug!("adding local variable {} from for loop with bm {:?}", debug!("adding local variable {} from for loop with bm {:?}",
@ -1012,7 +1014,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**cond, ln) 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, _) => { ExprWhile(ref cond, ref blk, _) => {
self.propagate_through_loop(expr, WhileLoop(&**cond), &**blk, succ) self.propagate_through_loop(expr, WhileLoop(&**cond), &**blk, succ)
@ -1473,7 +1477,9 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
ExprPath(..) | ExprBox(..) => { ExprPath(..) | ExprBox(..) => {
visit::walk_expr(this, expr); visit::walk_expr(this, expr);
} }
ExprIfLet(..) => fail!("non-desugared ExprIfLet") ExprIfLet(..) => {
this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}
} }
} }

View file

@ -506,7 +506,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty)) 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");
}
} }
} }

View file

@ -3631,10 +3631,13 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
RvalueDpsExpr RvalueDpsExpr
} }
ast::ExprIfLet(..) => {
tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}
ast::ExprLit(ref lit) if lit_is_str(&**lit) => { ast::ExprLit(ref lit) if lit_is_str(&**lit) => {
RvalueDpsExpr RvalueDpsExpr
} }
ast::ExprIfLet(..) => fail!("non-desugared ExprIfLet"),
ast::ExprCast(..) => { ast::ExprCast(..) => {
match tcx.node_types.borrow().find(&(expr.id as uint)) { match tcx.node_types.borrow().find(&(expr.id as uint)) {

View file

@ -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), check_then_else(fcx, &**cond, &**then_blk, opt_else_expr.as_ref().map(|e| &**e),
id, expr.span, expected); 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, _) => { ast::ExprWhile(ref cond, ref body, _) => {
check_expr_has_type(fcx, &**cond, ty::mk_bool()); check_expr_has_type(fcx, &**cond, ty::mk_bool());
check_block_no_value(fcx, &**body); check_block_no_value(fcx, &**body);

View file

@ -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 // Desugar support for ExprIfLet in the ExprIf else position
ast::ExprIf(cond, blk, mut elseopt) => { ast::ExprIf(cond, blk, elseopt) => {
// NOTE: replace with 'if let' after snapshot let elseopt = elseopt.map(|els| match els.node {
match elseopt { ast::ExprIfLet(..) => {
Some(els) => match els.node { // wrap the if-let expr in a block
ast::ExprIfLet(..) => { let blk = P(ast::Block {
// wrap the if-let expr in a block view_items: vec![],
let blk = P(ast::Block { stmts: vec![],
view_items: vec![], expr: Some(els),
stmts: vec![], id: ast::DUMMY_NODE_ID,
expr: Some(els), rules: ast::DefaultBlock,
id: ast::DUMMY_NODE_ID, span: els.span
rules: ast::DefaultBlock, });
span: els.span fld.cx.expr_block(blk)
}); }
elseopt = Some(fld.cx.expr_block(blk)); _ => els
} });
_ => ()
},
None => ()
};
let if_expr = fld.cx.expr(e.span, ast::ExprIf(cond, blk, elseopt)); let if_expr = fld.cx.expr(e.span, ast::ExprIf(cond, blk, elseopt));
noop_fold_expr(if_expr, fld) noop_fold_expr(if_expr, fld)
} }

View file

@ -360,7 +360,7 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
} }
ast::ExprIfLet(..) => { ast::ExprIfLet(..) => {
self.gate_feature("if_let", e.span, self.gate_feature("if_let", e.span,
"`if let` desugaring is experimental"); "`if let` syntax is experimental");
} }
_ => {} _ => {}
} }

View file

@ -579,7 +579,9 @@ impl<'a> Parser<'a> {
if self.is_keyword(kw) { if self.is_keyword(kw) {
self.bump(); self.bump();
true true
} else { false } } else {
false
}
} }
/// If the given word is not a keyword, signal an error. /// If the given word is not a keyword, signal an error.