Skip to content

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed
 

‎src/librustc_passes/rvalue_promotion.rs

+24-31
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use rustc_data_structures::sync::Lrc;
4040
use syntax::ast;
4141
use syntax::attr;
4242
use syntax_pos::{Span, DUMMY_SP};
43-
use rustc::hir::intravisit::{Visitor, NestedVisitorMap};
4443

4544
pub fn provide(providers: &mut Providers) {
4645
*providers = Providers {
@@ -169,12 +168,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
169168
}
170169
}
171170

172-
impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> {
173-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
174-
// note that we *do* visit nested bodies, because we override `visit_nested_body` below
175-
NestedVisitorMap::None
176-
}
177-
171+
impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
178172
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
179173
let item_id = self.tcx.hir.body_owner(body_id);
180174
let item_def_id = self.tcx.hir.local_def_id(item_id);
@@ -206,8 +200,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> {
206200
euv::ExprUseVisitor::new(self, tcx, param_env, &region_scope_tree, self.tables, None)
207201
.consume_body(body);
208202

209-
self.visit_body(body);
210-
203+
self.visit_expr(&body.value);
211204
self.in_fn = outer_in_fn;
212205
self.tables = outer_tables;
213206
self.param_env = outer_param_env;
@@ -216,27 +209,29 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> {
216209

217210
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt) {
218211
match stmt.node {
219-
hir::StmtDecl(ref decl, node_id) => {
220-
self.visit_id(node_id);
221-
self.visit_decl(decl);
212+
hir::StmtDecl(ref decl, _node_id) => {
222213
match &decl.node {
223214
hir::DeclLocal(local) => {
224215
self.promotable = false;
225-
226216
if self.remove_mut_rvalue_borrow(&local.pat) {
227217
if let Some(init) = &local.init {
228218
self.mut_rvalue_borrows.insert(init.id);
229219
}
230220
}
221+
222+
match local.init {
223+
Some(ref expr) => self.visit_expr(&expr),
224+
None => {},
225+
}
231226
}
232227
// Item statements are allowed
233228
hir::DeclItem(_) => {}
234229
}
235230
}
236-
hir::StmtExpr(ref box_expr, node_id) |
237-
hir::StmtSemi(ref box_expr, node_id) => {
231+
hir::StmtExpr(ref box_expr, _node_id) |
232+
hir::StmtSemi(ref box_expr, _node_id) => {
238233
self.visit_expr(box_expr);
239-
self.visit_id(node_id);
234+
self.promotable = false;
240235
}
241236
}
242237
}
@@ -293,12 +288,18 @@ fn check_expr<'a, 'tcx>(
293288
v.promotable = false;
294289
}
295290
hir::ExprUnary(op, ref expr) => {
296-
v.visit_expr(expr);
291+
if v.tables.is_method_call(e) {
292+
v.promotable = false;
293+
}
297294
if op == hir::UnDeref {
298295
v.promotable = false;
299296
}
297+
v.visit_expr(expr);
300298
}
301299
hir::ExprBinary(op, ref lhs, ref rhs) => {
300+
if v.tables.is_method_call(e) {
301+
v.promotable = false;
302+
}
302303
v.visit_expr(lhs);
303304
v.visit_expr(rhs);
304305
match v.tables.node_id_to_type(lhs.hir_id).sty {
@@ -324,7 +325,6 @@ fn check_expr<'a, 'tcx>(
324325
}
325326
}
326327
hir::ExprPath(ref qpath) => {
327-
v.visit_qpath(qpath, e.id, e.span);
328328
let def = v.tables.qpath_def(qpath, e.hir_id);
329329
match def {
330330
Def::VariantCtor(..) | Def::StructCtor(..) |
@@ -450,11 +450,8 @@ fn check_expr<'a, 'tcx>(
450450

451451
hir::ExprLit(_) => {}
452452

453-
hir::ExprAddrOf(ref _mutability, ref expr) => {
454-
v.visit_expr(expr);
455-
}
456-
457-
hir::ExprRepeat(ref expr, ref _anon_cast) => {
453+
hir::ExprAddrOf(_, ref expr) |
454+
hir::ExprRepeat(ref expr, _) => {
458455
v.visit_expr(expr);
459456
}
460457

@@ -520,14 +517,10 @@ fn check_expr<'a, 'tcx>(
520517

521518
v.visit_expr(expr);
522519
for index in hirvec_arm.iter() {
523-
match *index {
524-
ref arm => {
525-
v.visit_expr(&*arm.body);
526-
match arm.guard {
527-
Some(ref expr) => v.visit_expr(&expr),
528-
None => {},
529-
}
530-
}
520+
v.visit_expr(&*index.body);
521+
match index.guard {
522+
Some(ref expr) => v.visit_expr(&expr),
523+
None => {},
531524
}
532525
}
533526
v.promotable = false;

0 commit comments

Comments
 (0)
Please sign in to comment.