Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make more use of autoderef throughout the compiler #31524

Merged
merged 15 commits into from
Feb 13, 2016
Merged
6 changes: 3 additions & 3 deletions src/librustc/front/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ impl<'a> FnLikeNode<'a> {
item_fn(ItemFnParts {
id: i.id,
name: i.name,
decl: &**decl,
decl: &decl,
unsafety: unsafety,
body: &**block,
body: &block,
generics: generics,
abi: abi,
vis: i.vis,
Expand All @@ -246,7 +246,7 @@ impl<'a> FnLikeNode<'a> {
}
map::NodeExpr(e) => match e.node {
ast::ExprClosure(_, ref decl, ref block) =>
closure(ClosureParts::new(&**decl, &**block, e.id, e.span)),
closure(ClosureParts::new(&decl, &block, e.id, e.span)),
_ => panic!("expr FnLikeNode that is not fn-like"),
},
_ => panic!("other FnLikeNode that is not fn-like"),
Expand Down
30 changes: 15 additions & 15 deletions src/librustc/front/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
loop {
match map.find(id) {
None => return None,
Some(NodeItem(item)) if item_is_mod(&*item) =>
Some(NodeItem(item)) if item_is_mod(&item) =>
return Some((id, item.name)),
_ => {}
}
Expand Down Expand Up @@ -967,16 +967,16 @@ pub trait NodePrinter {
impl<'a> NodePrinter for pprust::State<'a> {
fn print_node(&mut self, node: &Node) -> io::Result<()> {
match *node {
NodeItem(a) => self.print_item(&*a),
NodeForeignItem(a) => self.print_foreign_item(&*a),
NodeItem(a) => self.print_item(&a),
NodeForeignItem(a) => self.print_foreign_item(&a),
NodeTraitItem(a) => self.print_trait_item(a),
NodeImplItem(a) => self.print_impl_item(a),
NodeVariant(a) => self.print_variant(&*a),
NodeExpr(a) => self.print_expr(&*a),
NodeStmt(a) => self.print_stmt(&*a),
NodePat(a) => self.print_pat(&*a),
NodeBlock(a) => self.print_block(&*a),
NodeLifetime(a) => self.print_lifetime(&*a),
NodeVariant(a) => self.print_variant(&a),
NodeExpr(a) => self.print_expr(&a),
NodeStmt(a) => self.print_stmt(&a),
NodePat(a) => self.print_pat(&a),
NodeBlock(a) => self.print_block(&a),
NodeLifetime(a) => self.print_lifetime(&a),
NodeTyParam(_) => panic!("cannot print TyParam"),
// these cases do not carry enough information in the
// ast_map to reconstruct their full structure for pretty
Expand Down Expand Up @@ -1055,26 +1055,26 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
map.path_to_string(id), id_str)
}
Some(NodeExpr(ref expr)) => {
format!("expr {}{}", pprust::expr_to_string(&**expr), id_str)
format!("expr {}{}", pprust::expr_to_string(&expr), id_str)
}
Some(NodeStmt(ref stmt)) => {
format!("stmt {}{}", pprust::stmt_to_string(&**stmt), id_str)
format!("stmt {}{}", pprust::stmt_to_string(&stmt), id_str)
}
Some(NodeLocal(ref pat)) => {
format!("local {}{}", pprust::pat_to_string(&**pat), id_str)
format!("local {}{}", pprust::pat_to_string(&pat), id_str)
}
Some(NodePat(ref pat)) => {
format!("pat {}{}", pprust::pat_to_string(&**pat), id_str)
format!("pat {}{}", pprust::pat_to_string(&pat), id_str)
}
Some(NodeBlock(ref block)) => {
format!("block {}{}", pprust::block_to_string(&**block), id_str)
format!("block {}{}", pprust::block_to_string(&block), id_str)
}
Some(NodeStructCtor(_)) => {
format!("struct_ctor {}{}", map.path_to_string(id), id_str)
}
Some(NodeLifetime(ref l)) => {
format!("lifetime {}{}",
pprust::lifetime_to_string(&**l), id_str)
pprust::lifetime_to_string(&l), id_str)
}
Some(NodeTyParam(ref ty_param)) => {
format!("typaram {:?}{}", ty_param, id_str)
Expand Down
48 changes: 24 additions & 24 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
fn stmt(&mut self, stmt: &hir::Stmt, pred: CFGIndex) -> CFGIndex {
match stmt.node {
hir::StmtDecl(ref decl, id) => {
let exit = self.decl(&**decl, pred);
let exit = self.decl(&decl, pred);
self.add_ast_node(id, &[exit])
}

hir::StmtExpr(ref expr, id) | hir::StmtSemi(ref expr, id) => {
let exit = self.expr(&**expr, pred);
let exit = self.expr(&expr, pred);
self.add_ast_node(id, &[exit])
}
}
Expand All @@ -88,7 +88,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
match decl.node {
hir::DeclLocal(ref local) => {
let init_exit = self.opt_expr(&local.init, pred);
self.pat(&*local.pat, init_exit)
self.pat(&local.pat, init_exit)
}

hir::DeclItem(_) => {
Expand All @@ -111,7 +111,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
hir::PatBox(ref subpat) |
hir::PatRegion(ref subpat, _) |
hir::PatIdent(_, _, Some(ref subpat)) => {
let subpat_exit = self.pat(&**subpat, pred);
let subpat_exit = self.pat(&subpat, pred);
self.add_ast_node(pat.id, &[subpat_exit])
}

Expand Down Expand Up @@ -140,13 +140,13 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
pats: I,
pred: CFGIndex) -> CFGIndex {
//! Handles case where all of the patterns must match.
pats.fold(pred, |pred, pat| self.pat(&**pat, pred))
pats.fold(pred, |pred, pat| self.pat(&pat, pred))
}

fn expr(&mut self, expr: &hir::Expr, pred: CFGIndex) -> CFGIndex {
match expr.node {
hir::ExprBlock(ref blk) => {
let blk_exit = self.block(&**blk, pred);
let blk_exit = self.block(&blk, pred);
self.add_ast_node(expr.id, &[blk_exit])
}

Expand All @@ -165,8 +165,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
// v 3 v 4
// [..expr..]
//
let cond_exit = self.expr(&**cond, pred); // 1
let then_exit = self.block(&**then, cond_exit); // 2
let cond_exit = self.expr(&cond, pred); // 1
let then_exit = self.block(&then, cond_exit); // 2
self.add_ast_node(expr.id, &[cond_exit, then_exit]) // 3,4
}

Expand All @@ -185,9 +185,9 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
// v 4 v 5
// [..expr..]
//
let cond_exit = self.expr(&**cond, pred); // 1
let then_exit = self.block(&**then, cond_exit); // 2
let else_exit = self.expr(&**otherwise, cond_exit); // 3
let cond_exit = self.expr(&cond, pred); // 1
let then_exit = self.block(&then, cond_exit); // 2
let else_exit = self.expr(&otherwise, cond_exit); // 3
self.add_ast_node(expr.id, &[then_exit, else_exit]) // 4, 5
}

Expand All @@ -211,14 +211,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {

// Is the condition considered part of the loop?
let loopback = self.add_dummy_node(&[pred]); // 1
let cond_exit = self.expr(&**cond, loopback); // 2
let cond_exit = self.expr(&cond, loopback); // 2
let expr_exit = self.add_ast_node(expr.id, &[cond_exit]); // 3
self.loop_scopes.push(LoopScope {
loop_id: expr.id,
continue_index: loopback,
break_index: expr_exit
});
let body_exit = self.block(&**body, cond_exit); // 4
let body_exit = self.block(&body, cond_exit); // 4
self.add_contained_edge(body_exit, loopback); // 5
self.loop_scopes.pop();
expr_exit
Expand Down Expand Up @@ -246,7 +246,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
continue_index: loopback,
break_index: expr_exit,
});
let body_exit = self.block(&**body, loopback); // 3
let body_exit = self.block(&body, loopback); // 3
self.add_contained_edge(body_exit, loopback); // 4
self.loop_scopes.pop();
expr_exit
Expand All @@ -271,8 +271,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
// v 3 v 4
// [..exit..]
//
let l_exit = self.expr(&**l, pred); // 1
let r_exit = self.expr(&**r, l_exit); // 2
let l_exit = self.expr(&l, pred); // 1
let r_exit = self.expr(&r, l_exit); // 2
self.add_ast_node(expr.id, &[l_exit, r_exit]) // 3,4
}

Expand Down Expand Up @@ -304,16 +304,16 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

hir::ExprCall(ref func, ref args) => {
self.call(expr, pred, &**func, args.iter().map(|e| &**e))
self.call(expr, pred, &func, args.iter().map(|e| &**e))
}

hir::ExprMethodCall(_, _, ref args) => {
self.call(expr, pred, &*args[0], args[1..].iter().map(|e| &**e))
self.call(expr, pred, &args[0], args[1..].iter().map(|e| &**e))
}

hir::ExprIndex(ref l, ref r) |
hir::ExprBinary(_, ref l, ref r) if self.tcx.is_method_call(expr.id) => {
self.call(expr, pred, &**l, Some(&**r).into_iter())
self.call(expr, pred, &l, Some(&**r).into_iter())
}

hir::ExprRange(ref start, ref end) => {
Expand All @@ -323,7 +323,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

hir::ExprUnary(_, ref e) if self.tcx.is_method_call(expr.id) => {
self.call(expr, pred, &**e, None::<hir::Expr>.iter())
self.call(expr, pred, &e, None::<hir::Expr>.iter())
}

hir::ExprTup(ref exprs) => {
Expand Down Expand Up @@ -413,7 +413,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
opt_expr: &Option<P<hir::Expr>>,
pred: CFGIndex) -> CFGIndex {
//! Constructs graph for `opt_expr` evaluated, if Some
opt_expr.iter().fold(pred, |p, e| self.expr(&**e, p))
opt_expr.iter().fold(pred, |p, e| self.expr(&e, p))
}

fn straightline<'b, I: Iterator<Item=&'b hir::Expr>>(&mut self,
Expand Down Expand Up @@ -461,18 +461,18 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {

for pat in &arm.pats {
// Visit the pattern, coming from the discriminant exit
let mut pat_exit = self.pat(&**pat, discr_exit);
let mut pat_exit = self.pat(&pat, discr_exit);

// If there is a guard expression, handle it here
if let Some(ref guard) = arm.guard {
// Add a dummy node for the previous guard
// expression to target
let guard_start = self.add_dummy_node(&[pat_exit]);
// Visit the guard expression
let guard_exit = self.expr(&**guard, guard_start);
let guard_exit = self.expr(&guard, guard_start);

let this_has_bindings = pat_util::pat_contains_bindings_or_wild(
&self.tcx.def_map.borrow(), &**pat);
&self.tcx.def_map.borrow(), &pat);

// If both this pattern and the previous pattern
// were free of bindings, they must consist only
Expand Down
Loading