Skip to content

Commit e9c687b

Browse files
committed
Evaluate hair::ExprKind::Use in into
This avoids some unnecessary moves
1 parent ff4d4b2 commit e9c687b

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

src/librustc_mir/build/expr/as_rvalue.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
150150
let source = unpack!(block = this.as_operand(block, scope, source));
151151
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
152152
}
153-
ExprKind::Use { source } => {
154-
let source = unpack!(block = this.as_operand(block, scope, source));
155-
block.and(Rvalue::Use(source))
156-
}
157153
ExprKind::Pointer { cast, source } => {
158154
let source = unpack!(block = this.as_operand(block, scope, source));
159155
block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
@@ -363,6 +359,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
363359
| ExprKind::Match { .. }
364360
| ExprKind::If { .. }
365361
| ExprKind::NeverToAny { .. }
362+
| ExprKind::Use { .. }
366363
| ExprKind::Loop { .. }
367364
| ExprKind::LogicalOp { .. }
368365
| ExprKind::Call { .. }

src/librustc_mir/build/expr/category.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl Category {
4848
| ExprKind::If { .. }
4949
| ExprKind::Match { .. }
5050
| ExprKind::NeverToAny { .. }
51+
| ExprKind::Use { .. }
5152
| ExprKind::Call { .. } => Some(Category::Rvalue(RvalueFunc::Into)),
5253

5354
ExprKind::Array { .. }
@@ -58,7 +59,6 @@ impl Category {
5859
| ExprKind::Binary { .. }
5960
| ExprKind::Box { .. }
6061
| ExprKind::Cast { .. }
61-
| ExprKind::Use { .. }
6262
| ExprKind::Pointer { .. }
6363
| ExprKind::Repeat { .. }
6464
| ExprKind::Borrow { .. }

src/librustc_mir/build/expr/into.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
327327
success.unit()
328328
}
329329
}
330+
ExprKind::Use { source } => {
331+
this.into(destination, block, source)
332+
}
330333

331334
// These cases don't actually need a destination
332335
ExprKind::Assign { .. }
@@ -379,7 +382,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
379382
| ExprKind::Binary { .. }
380383
| ExprKind::Box { .. }
381384
| ExprKind::Cast { .. }
382-
| ExprKind::Use { .. }
383385
| ExprKind::Pointer { .. }
384386
| ExprKind::Repeat { .. }
385387
| ExprKind::Borrow { .. }

src/test/mir-opt/array-index-is-temporary.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@ fn main() {
1818
// START rustc.main.EraseRegions.after.mir
1919
// bb0: {
2020
// ...
21-
// _6 = &mut _2;
22-
// _5 = &mut (*_6);
23-
// _4 = move _5 as *mut usize (Misc);
24-
// _3 = move _4;
21+
// _5 = &mut _2;
22+
// _4 = &mut (*_5);
23+
// _3 = move _4 as *mut usize (Misc);
2524
// ...
26-
// _8 = _3;
27-
// _7 = const foo(move _8) -> bb1;
25+
// _7 = _3;
26+
// _6 = const foo(move _7) -> bb1;
2827
// }
2928
//
3029
// bb1: {
3130
// ...
32-
// _9 = _2;
33-
// _10 = Len(_1);
34-
// _11 = Lt(_9, _10);
35-
// assert(move _11, "index out of bounds: the len is move _10 but the index is _9") -> bb2;
31+
// _8 = _2;
32+
// _9 = Len(_1);
33+
// _10 = Lt(_8, _9);
34+
// assert(move _10, "index out of bounds: the len is move _9 but the index is _8") -> bb2;
3635
// }
3736
//
3837
// bb2: {
39-
// _1[_9] = move _7;
38+
// _1[_8] = move _6;
4039
// ...
4140
// return;
4241
// }

src/test/mir-opt/retag.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ fn main() {
7575
// _10 = move _8;
7676
// Retag(_10);
7777
// ...
78-
// _15 = &mut (*_10);
79-
// Retag(_15);
80-
// _14 = move _15 as *mut i32 (Misc);
81-
// Retag([raw] _14);
78+
// _13 = &mut (*_10);
79+
// Retag(_13);
80+
// _12 = move _13 as *mut i32 (Misc);
81+
// Retag([raw] _12);
8282
// ...
83-
// _18 = move _19(move _20) -> bb2;
83+
// _16 = move _17(move _18) -> bb2;
8484
// }
8585
//
8686
// bb2: {
87-
// Retag(_18);
87+
// Retag(_16);
8888
// ...
89-
// _22 = const Test::foo_shr(move _23, move _25) -> bb3;
89+
// _20 = const Test::foo_shr(move _21, move _23) -> bb3;
9090
// }
9191
//
9292
// bb3: {

0 commit comments

Comments
 (0)