Skip to content

Commit

Permalink
[breaking-change] don't glob export ast::Expr_ variants
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 11, 2016
1 parent 1c4d437 commit 80bf9ae
Show file tree
Hide file tree
Showing 29 changed files with 420 additions and 428 deletions.
2 changes: 1 addition & 1 deletion src/librustc_driver/pretty.rs
Expand Up @@ -653,7 +653,7 @@ impl fold::Folder for ReplaceBodyWithLoop {

let empty_block = expr_to_block(BlockCheckMode::Default, None);
let loop_expr = P(ast::Expr {
node: ast::ExprLoop(empty_block, None),
node: ast::ExprKind::Loop(empty_block, None),
id: ast::DUMMY_NODE_ID,
span: codemap::DUMMY_SP,
attrs: None,
Expand Down
74 changes: 37 additions & 37 deletions src/librustc_front/lowering.rs
Expand Up @@ -986,12 +986,12 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
// }
//
// But for now there are type-inference issues doing that.
ExprBox(ref e) => {
ExprKind::Box(ref e) => {
hir::ExprBox(lower_expr(lctx, e))
}

// Desugar ExprBox: `in (PLACE) EXPR`
ExprInPlace(ref placer, ref value_expr) => {
ExprKind::InPlace(ref placer, ref value_expr) => {
// to:
//
// let p = PLACE;
Expand Down Expand Up @@ -1099,57 +1099,57 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
});
}

ExprVec(ref exprs) => {
ExprKind::Vec(ref exprs) => {
hir::ExprVec(exprs.iter().map(|x| lower_expr(lctx, x)).collect())
}
ExprRepeat(ref expr, ref count) => {
ExprKind::Repeat(ref expr, ref count) => {
let expr = lower_expr(lctx, expr);
let count = lower_expr(lctx, count);
hir::ExprRepeat(expr, count)
}
ExprTup(ref elts) => {
ExprKind::Tup(ref elts) => {
hir::ExprTup(elts.iter().map(|x| lower_expr(lctx, x)).collect())
}
ExprCall(ref f, ref args) => {
ExprKind::Call(ref f, ref args) => {
let f = lower_expr(lctx, f);
hir::ExprCall(f, args.iter().map(|x| lower_expr(lctx, x)).collect())
}
ExprMethodCall(i, ref tps, ref args) => {
ExprKind::MethodCall(i, ref tps, ref args) => {
let tps = tps.iter().map(|x| lower_ty(lctx, x)).collect();
let args = args.iter().map(|x| lower_expr(lctx, x)).collect();
hir::ExprMethodCall(respan(i.span, i.node.name), tps, args)
}
ExprBinary(binop, ref lhs, ref rhs) => {
ExprKind::Binary(binop, ref lhs, ref rhs) => {
let binop = lower_binop(lctx, binop);
let lhs = lower_expr(lctx, lhs);
let rhs = lower_expr(lctx, rhs);
hir::ExprBinary(binop, lhs, rhs)
}
ExprUnary(op, ref ohs) => {
ExprKind::Unary(op, ref ohs) => {
let op = lower_unop(lctx, op);
let ohs = lower_expr(lctx, ohs);
hir::ExprUnary(op, ohs)
}
ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
ExprCast(ref expr, ref ty) => {
ExprKind::Lit(ref l) => hir::ExprLit(P((**l).clone())),
ExprKind::Cast(ref expr, ref ty) => {
let expr = lower_expr(lctx, expr);
hir::ExprCast(expr, lower_ty(lctx, ty))
}
ExprType(ref expr, ref ty) => {
ExprKind::Type(ref expr, ref ty) => {
let expr = lower_expr(lctx, expr);
hir::ExprType(expr, lower_ty(lctx, ty))
}
ExprAddrOf(m, ref ohs) => {
ExprKind::AddrOf(m, ref ohs) => {
let m = lower_mutability(lctx, m);
let ohs = lower_expr(lctx, ohs);
hir::ExprAddrOf(m, ohs)
}
// More complicated than you might expect because the else branch
// might be `if let`.
ExprIf(ref cond, ref blk, ref else_opt) => {
ExprKind::If(ref cond, ref blk, ref else_opt) => {
let else_opt = else_opt.as_ref().map(|els| {
match els.node {
ExprIfLet(..) => {
ExprKind::IfLet(..) => {
cache_ids(lctx, e.id, |lctx| {
// wrap the if-let expr in a block
let span = els.span;
Expand All @@ -1171,47 +1171,47 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {

hir::ExprIf(lower_expr(lctx, cond), lower_block(lctx, blk), else_opt)
}
ExprWhile(ref cond, ref body, opt_ident) => {
ExprKind::While(ref cond, ref body, opt_ident) => {
hir::ExprWhile(lower_expr(lctx, cond), lower_block(lctx, body),
opt_ident.map(|ident| lower_ident(lctx, ident)))
}
ExprLoop(ref body, opt_ident) => {
ExprKind::Loop(ref body, opt_ident) => {
hir::ExprLoop(lower_block(lctx, body),
opt_ident.map(|ident| lower_ident(lctx, ident)))
}
ExprMatch(ref expr, ref arms) => {
ExprKind::Match(ref expr, ref arms) => {
hir::ExprMatch(lower_expr(lctx, expr),
arms.iter().map(|x| lower_arm(lctx, x)).collect(),
hir::MatchSource::Normal)
}
ExprClosure(capture_clause, ref decl, ref body) => {
ExprKind::Closure(capture_clause, ref decl, ref body) => {
hir::ExprClosure(lower_capture_clause(lctx, capture_clause),
lower_fn_decl(lctx, decl),
lower_block(lctx, body))
}
ExprBlock(ref blk) => hir::ExprBlock(lower_block(lctx, blk)),
ExprAssign(ref el, ref er) => {
ExprKind::Block(ref blk) => hir::ExprBlock(lower_block(lctx, blk)),
ExprKind::Assign(ref el, ref er) => {
hir::ExprAssign(lower_expr(lctx, el), lower_expr(lctx, er))
}
ExprAssignOp(op, ref el, ref er) => {
ExprKind::AssignOp(op, ref el, ref er) => {
hir::ExprAssignOp(lower_binop(lctx, op),
lower_expr(lctx, el),
lower_expr(lctx, er))
}
ExprField(ref el, ident) => {
ExprKind::Field(ref el, ident) => {
hir::ExprField(lower_expr(lctx, el), respan(ident.span, ident.node.name))
}
ExprTupField(ref el, ident) => {
ExprKind::TupField(ref el, ident) => {
hir::ExprTupField(lower_expr(lctx, el), ident)
}
ExprIndex(ref el, ref er) => {
ExprKind::Index(ref el, ref er) => {
hir::ExprIndex(lower_expr(lctx, el), lower_expr(lctx, er))
}
ExprRange(ref e1, ref e2) => {
ExprKind::Range(ref e1, ref e2) => {
hir::ExprRange(e1.as_ref().map(|x| lower_expr(lctx, x)),
e2.as_ref().map(|x| lower_expr(lctx, x)))
}
ExprPath(ref qself, ref path) => {
ExprKind::Path(ref qself, ref path) => {
let hir_qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
hir::QSelf {
ty: lower_ty(lctx, ty),
Expand All @@ -1220,14 +1220,14 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
});
hir::ExprPath(hir_qself, lower_path_full(lctx, path, qself.is_none()))
}
ExprBreak(opt_ident) => hir::ExprBreak(opt_ident.map(|sp_ident| {
ExprKind::Break(opt_ident) => hir::ExprBreak(opt_ident.map(|sp_ident| {
respan(sp_ident.span, lower_ident(lctx, sp_ident.node))
})),
ExprAgain(opt_ident) => hir::ExprAgain(opt_ident.map(|sp_ident| {
ExprKind::Again(opt_ident) => hir::ExprAgain(opt_ident.map(|sp_ident| {
respan(sp_ident.span, lower_ident(lctx, sp_ident.node))
})),
ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(lctx, x))),
ExprInlineAsm(InlineAsm {
ExprKind::Ret(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(lctx, x))),
ExprKind::InlineAsm(InlineAsm {
ref inputs,
ref outputs,
ref asm,
Expand Down Expand Up @@ -1259,12 +1259,12 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
dialect: dialect,
expn_id: expn_id,
}),
ExprStruct(ref path, ref fields, ref maybe_expr) => {
ExprKind::Struct(ref path, ref fields, ref maybe_expr) => {
hir::ExprStruct(lower_path(lctx, path),
fields.iter().map(|x| lower_field(lctx, x)).collect(),
maybe_expr.as_ref().map(|x| lower_expr(lctx, x)))
}
ExprParen(ref ex) => {
ExprKind::Paren(ref ex) => {
// merge attributes into the inner expression.
return lower_expr(lctx, ex).map(|mut ex| {
ex.attrs.update(|attrs| {
Expand All @@ -1276,7 +1276,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {

// Desugar ExprIfLet
// From: `if let <pat> = <sub_expr> <body> [<else_opt>]`
ExprIfLet(ref pat, ref sub_expr, ref body, ref else_opt) => {
ExprKind::IfLet(ref pat, ref sub_expr, ref body, ref else_opt) => {
// to:
//
// match <sub_expr> {
Expand Down Expand Up @@ -1364,7 +1364,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {

// Desugar ExprWhileLet
// From: `[opt_ident]: while let <pat> = <sub_expr> <body>`
ExprWhileLet(ref pat, ref sub_expr, ref body, opt_ident) => {
ExprKind::WhileLet(ref pat, ref sub_expr, ref body, opt_ident) => {
// to:
//
// [opt_ident]: loop {
Expand Down Expand Up @@ -1410,7 +1410,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {

// Desugar ExprForLoop
// From: `[opt_ident]: for <pat> in <head> <body>`
ExprForLoop(ref pat, ref head, ref body, opt_ident) => {
ExprKind::ForLoop(ref pat, ref head, ref body, opt_ident) => {
// to:
//
// {
Expand Down Expand Up @@ -1524,7 +1524,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
});
}

ExprMac(_) => panic!("Shouldn't exist here"),
ExprKind::Mac(_) => panic!("Shouldn't exist here"),
},
span: e.span,
attrs: e.attrs.clone(),
Expand Down
45 changes: 23 additions & 22 deletions src/librustc_lint/unused.rs
Expand Up @@ -293,7 +293,7 @@ pub struct UnusedParens;
impl UnusedParens {
fn check_unused_parens_core(&self, cx: &EarlyContext, value: &ast::Expr, msg: &str,
struct_lit_needs_parens: bool) {
if let ast::ExprParen(ref inner) = value.node {
if let ast::ExprKind::Paren(ref inner) = value.node {
let necessary = struct_lit_needs_parens && contains_exterior_struct_lit(&**inner);
if !necessary {
cx.span_lint(UNUSED_PARENS, value.span,
Expand All @@ -308,26 +308,26 @@ impl UnusedParens {
/// y: 1 }) == foo` does not.
fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
match value.node {
ast::ExprStruct(..) => true,
ast::ExprKind::Struct(..) => true,

ast::ExprAssign(ref lhs, ref rhs) |
ast::ExprAssignOp(_, ref lhs, ref rhs) |
ast::ExprBinary(_, ref lhs, ref rhs) => {
ast::ExprKind::Assign(ref lhs, ref rhs) |
ast::ExprKind::AssignOp(_, ref lhs, ref rhs) |
ast::ExprKind::Binary(_, ref lhs, ref rhs) => {
// X { y: 1 } + X { y: 2 }
contains_exterior_struct_lit(&**lhs) ||
contains_exterior_struct_lit(&**rhs)
}
ast::ExprUnary(_, ref x) |
ast::ExprCast(ref x, _) |
ast::ExprType(ref x, _) |
ast::ExprField(ref x, _) |
ast::ExprTupField(ref x, _) |
ast::ExprIndex(ref x, _) => {
ast::ExprKind::Unary(_, ref x) |
ast::ExprKind::Cast(ref x, _) |
ast::ExprKind::Type(ref x, _) |
ast::ExprKind::Field(ref x, _) |
ast::ExprKind::TupField(ref x, _) |
ast::ExprKind::Index(ref x, _) => {
// &X { y: 1 }, X { y: 1 }.y
contains_exterior_struct_lit(&**x)
}

ast::ExprMethodCall(_, _, ref exprs) => {
ast::ExprKind::MethodCall(_, _, ref exprs) => {
// X { y: 1 }.bar(...)
contains_exterior_struct_lit(&*exprs[0])
}
Expand All @@ -346,17 +346,18 @@ impl LintPass for UnusedParens {

impl EarlyLintPass for UnusedParens {
fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) {
use syntax::ast::ExprKind::*;
let (value, msg, struct_lit_needs_parens) = match e.node {
ast::ExprIf(ref cond, _, _) => (cond, "`if` condition", true),
ast::ExprWhile(ref cond, _, _) => (cond, "`while` condition", true),
ast::ExprIfLet(_, ref cond, _, _) => (cond, "`if let` head expression", true),
ast::ExprWhileLet(_, ref cond, _, _) => (cond, "`while let` head expression", true),
ast::ExprForLoop(_, ref cond, _, _) => (cond, "`for` head expression", true),
ast::ExprMatch(ref head, _) => (head, "`match` head expression", true),
ast::ExprRet(Some(ref value)) => (value, "`return` value", false),
ast::ExprAssign(_, ref value) => (value, "assigned value", false),
ast::ExprAssignOp(_, _, ref value) => (value, "assigned value", false),
ast::ExprInPlace(_, ref value) => (value, "emplacement value", false),
If(ref cond, _, _) => (cond, "`if` condition", true),
While(ref cond, _, _) => (cond, "`while` condition", true),
IfLet(_, ref cond, _, _) => (cond, "`if let` head expression", true),
WhileLet(_, ref cond, _, _) => (cond, "`while let` head expression", true),
ForLoop(_, ref cond, _, _) => (cond, "`for` head expression", true),
Match(ref head, _) => (head, "`match` head expression", true),
Ret(Some(ref value)) => (value, "`return` value", false),
Assign(_, ref value) => (value, "assigned value", false),
AssignOp(_, _, ref value) => (value, "assigned value", false),
InPlace(_, ref value) => (value, "emplacement value", false),
_ => return
};
self.check_unused_parens_core(cx, &**value, msg, struct_lit_needs_parens);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/const_fn.rs
Expand Up @@ -38,7 +38,7 @@ impl<'a, 'v> Visitor<'v> for CheckBlock<'a> {
CheckConstFn{ sess: self.sess}.visit_block(block);
}
fn visit_expr(&mut self, e: &'v ast::Expr) {
if let ast::ExprClosure(..) = e.node {
if let ast::ExprKind::Closure(..) = e.node {
CheckConstFn{ sess: self.sess}.visit_expr(e);
} else {
visit::walk_expr(self, e);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/no_asm.rs
Expand Up @@ -32,8 +32,8 @@ struct CheckNoAsm<'a> {
impl<'a, 'v> Visitor<'v> for CheckNoAsm<'a> {
fn visit_expr(&mut self, e: &ast::Expr) {
match e.node {
ast::ExprInlineAsm(_) => span_err!(self.sess, e.span, E0472,
"asm! is unsupported on this target"),
ast::ExprKind::InlineAsm(_) => span_err!(self.sess, e.span, E0472,
"asm! is unsupported on this target"),
_ => {},
}
visit::walk_expr(self, e)
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_trans/save/dump_csv.rs
Expand Up @@ -1083,23 +1083,23 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
fn visit_expr(&mut self, ex: &ast::Expr) {
self.process_macro_use(ex.span, ex.id);
match ex.node {
ast::ExprCall(ref _f, ref _args) => {
ast::ExprKind::Call(ref _f, ref _args) => {
// Don't need to do anything for function calls,
// because just walking the callee path does what we want.
visit::walk_expr(self, ex);
}
ast::ExprPath(_, ref path) => {
ast::ExprKind::Path(_, ref path) => {
self.process_path(ex.id, path, None);
visit::walk_expr(self, ex);
}
ast::ExprStruct(ref path, ref fields, ref base) => {
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
let hir_expr = lower_expr(self.save_ctxt.lcx, ex);
let adt = self.tcx.expr_ty(&hir_expr).ty_adt_def().unwrap();
let def = self.tcx.resolve_expr(&hir_expr);
self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base)
}
ast::ExprMethodCall(_, _, ref args) => self.process_method_call(ex, args),
ast::ExprField(ref sub_ex, _) => {
ast::ExprKind::MethodCall(_, _, ref args) => self.process_method_call(ex, args),
ast::ExprKind::Field(ref sub_ex, _) => {
self.visit_expr(&sub_ex);

if let Some(field_data) = self.save_ctxt.get_expr_data(ex) {
Expand All @@ -1111,7 +1111,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
field_data.scope);
}
}
ast::ExprTupField(ref sub_ex, idx) => {
ast::ExprKind::TupField(ref sub_ex, idx) => {
self.visit_expr(&**sub_ex);

let hir_node = lower_expr(self.save_ctxt.lcx, sub_ex);
Expand All @@ -1131,7 +1131,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
ty)),
}
}
ast::ExprClosure(_, ref decl, ref body) => {
ast::ExprKind::Closure(_, ref decl, ref body) => {
let mut id = String::from("$");
id.push_str(&ex.id.to_string());
self.process_formals(&decl.inputs, &id);
Expand All @@ -1148,14 +1148,14 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
// walk the body
self.nest(ex.id, |v| v.visit_block(&**body));
}
ast::ExprForLoop(ref pattern, ref subexpression, ref block, _) |
ast::ExprWhileLet(ref pattern, ref subexpression, ref block, _) => {
ast::ExprKind::ForLoop(ref pattern, ref subexpression, ref block, _) |
ast::ExprKind::WhileLet(ref pattern, ref subexpression, ref block, _) => {
let value = self.span.snippet(mk_sp(ex.span.lo, subexpression.span.hi));
self.process_var_decl(pattern, value);
visit::walk_expr(self, subexpression);
visit::walk_block(self, block);
}
ast::ExprIfLet(ref pattern, ref subexpression, ref block, ref opt_else) => {
ast::ExprKind::IfLet(ref pattern, ref subexpression, ref block, ref opt_else) => {
let value = self.span.snippet(mk_sp(ex.span.lo, subexpression.span.hi));
self.process_var_decl(pattern, value);
visit::walk_expr(self, subexpression);
Expand Down

0 comments on commit 80bf9ae

Please sign in to comment.