Skip to content

Commit 0e716aa

Browse files
committed
Revert changes in for loop desugaring
1 parent dd884e0 commit 0e716aa

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

src/librustc/hir/lowering.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4902,11 +4902,12 @@ impl<'a> LoweringContext<'a> {
49024902

49034903
let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false));
49044904
let body_expr = P(self.expr_block(body_block, ThinVec::new()));
4905+
let body_stmt = self.stmt(body.span, hir::StmtKind::Expr(body_expr));
49054906

49064907
let loop_block = P(self.block_all(
49074908
e.span,
4908-
hir_vec![next_let, match_stmt, pat_let],
4909-
Some(body_expr),
4909+
hir_vec![next_let, match_stmt, pat_let, body_stmt],
4910+
None,
49104911
));
49114912

49124913
// `[opt_ident]: loop { ... }`

src/test/run-pass/for-loop-while/for-loop-has-unit-body.rs renamed to src/test/ui/for/for-loop-has-unit-body.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// run-pass
21
fn main() {
32
// Check that the tail statement in the body unifies with something
43
for _ in 0..3 {
5-
unsafe { std::mem::uninitialized() }
4+
unsafe { std::mem::uninitialized() } //~ ERROR type annotations needed
65
}
76

87
// Check that the tail statement in the body can be unit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/for-loop-has-unit-body.rs:4:18
3+
|
4+
LL | unsafe { std::mem::uninitialized() }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `T`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// compile-pass
2+
13
fn main() {
24
for x in 0..3 {
3-
x //~ ERROR mismatched types
5+
x
46
}
57
}

src/test/ui/mismatched_types/for-loop-has-unit-body.stderr

-12
This file was deleted.

0 commit comments

Comments
 (0)