Skip to content

Commit cc75f0e

Browse files
committed
Revert "More minimal changes"
This reverts commit fe0dedcb06947317d41a8570b7fff7f8690dcbff.
1 parent 53deccf commit cc75f0e

12 files changed

+103
-82
lines changed

compiler/rustc_mir_build/src/build/expr/into.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7070
&this.thir[cond],
7171
Some(condition_scope),
7272
condition_scope,
73-
then_expr.span,
73+
then_expr.span
7474
));
75+
7576
this.expr_into_dest(destination, then_blk, then_expr)
7677
});
7778
then_block.and(else_block)
@@ -97,7 +98,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9798
ExprKind::Let { expr, ref pat } => {
9899
let scope = this.local_scope();
99100
let (true_block, false_block) = this.in_if_then_scope(scope, |this| {
100-
this.lower_let_expr(block, &this.thir[expr], pat, scope, expr_span)
101+
this.lower_let_expr(block, &this.thir[expr], pat, scope, None, expr_span)
101102
});
102103

103104
this.cfg.push_assign_constant(

compiler/rustc_mir_build/src/build/matches/mod.rs

+24-12
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4141
expr: &Expr<'tcx>,
4242
temp_scope_override: Option<region::Scope>,
4343
break_scope: region::Scope,
44-
variable_scope_span: Span,
44+
variable_span: Span,
4545
) -> BlockAnd<()> {
4646
let this = self;
4747
let expr_span = expr.span;
@@ -53,15 +53,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5353
&this.thir[lhs],
5454
temp_scope_override,
5555
break_scope,
56-
variable_scope_span,
56+
variable_span,
5757
));
5858

5959
let rhs_then_block = unpack!(this.then_else_break(
6060
lhs_then_block,
6161
&this.thir[rhs],
6262
temp_scope_override,
6363
break_scope,
64-
variable_scope_span,
64+
variable_span,
6565
));
6666

6767
rhs_then_block.unit()
@@ -74,12 +74,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7474
&this.thir[value],
7575
temp_scope_override,
7676
break_scope,
77-
variable_scope_span,
77+
variable_span,
7878
)
7979
})
8080
}
8181
ExprKind::Let { expr, ref pat } => {
82-
this.lower_let_expr(block, &this.thir[expr], pat, break_scope, variable_scope_span)
82+
let variable_scope =
83+
this.new_source_scope(variable_span, LintLevel::Inherited, None);
84+
this.source_scope = variable_scope;
85+
this.lower_let_expr(
86+
block,
87+
&this.thir[expr],
88+
pat,
89+
break_scope,
90+
Some(variable_scope),
91+
variable_span,
92+
)
8393
}
8494
_ => {
8595
let temp_scope = temp_scope_override.unwrap_or_else(|| this.local_scope());
@@ -1773,6 +1783,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17731783
expr: &Expr<'tcx>,
17741784
pat: &Pat<'tcx>,
17751785
else_target: region::Scope,
1786+
source_scope: Option<SourceScope>,
17761787
span: Span,
17771788
) -> BlockAnd<()> {
17781789
let expr_span = expr.span;
@@ -1798,12 +1809,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17981809
let otherwise_post_guard_block = otherwise_candidate.pre_binding_block.unwrap();
17991810
self.break_for_else(otherwise_post_guard_block, else_target, self.source_info(expr_span));
18001811

1801-
let scope =
1802-
self.declare_bindings(None, pat.span.to(span), pat, ArmHasGuard(false), opt_expr_place);
1803-
1804-
if let Some(scope) = scope {
1805-
self.source_scope = scope;
1806-
}
1812+
self.declare_bindings(
1813+
source_scope,
1814+
pat.span.to(span),
1815+
pat,
1816+
ArmHasGuard(false),
1817+
opt_expr_place,
1818+
);
18071819

18081820
let post_guard_block = self.bind_pattern(
18091821
self.source_info(pat.span),
@@ -1981,7 +1993,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19811993
Guard::IfLet(ref pat, scrutinee) => {
19821994
let s = &this.thir[scrutinee];
19831995
guard_span = s.span;
1984-
this.lower_let_expr(block, s, pat, match_scope, arm_span)
1996+
this.lower_let_expr(block, s, pat, match_scope, None, arm_span)
19851997
}
19861998
});
19871999

src/test/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@
1010
scope 1 {
1111
debug x => _1; // in scope 1 at $DIR/discriminant.rs:11:9: 11:10
1212
}
13+
scope 2 {
14+
}
1315

1416
bb0: {
1517
StorageLive(_1); // scope 0 at $DIR/discriminant.rs:11:9: 11:10
1618
StorageLive(_2); // scope 0 at $DIR/discriminant.rs:11:13: 11:64
17-
StorageLive(_3); // scope 0 at $DIR/discriminant.rs:11:34: 11:44
18-
Deinit(_3); // scope 0 at $DIR/discriminant.rs:11:34: 11:44
19-
((_3 as Some).0: bool) = const true; // scope 0 at $DIR/discriminant.rs:11:34: 11:44
20-
discriminant(_3) = 1; // scope 0 at $DIR/discriminant.rs:11:34: 11:44
21-
- _4 = discriminant(_3); // scope 0 at $DIR/discriminant.rs:11:21: 11:31
22-
- switchInt(move _4) -> [1_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31
23-
+ _4 = const 1_isize; // scope 0 at $DIR/discriminant.rs:11:21: 11:31
24-
+ switchInt(const 1_isize) -> [1_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31
19+
StorageLive(_3); // scope 2 at $DIR/discriminant.rs:11:34: 11:44
20+
Deinit(_3); // scope 2 at $DIR/discriminant.rs:11:34: 11:44
21+
((_3 as Some).0: bool) = const true; // scope 2 at $DIR/discriminant.rs:11:34: 11:44
22+
discriminant(_3) = 1; // scope 2 at $DIR/discriminant.rs:11:34: 11:44
23+
- _4 = discriminant(_3); // scope 2 at $DIR/discriminant.rs:11:21: 11:31
24+
- switchInt(move _4) -> [1_isize: bb1, otherwise: bb3]; // scope 2 at $DIR/discriminant.rs:11:21: 11:31
25+
+ _4 = const 1_isize; // scope 2 at $DIR/discriminant.rs:11:21: 11:31
26+
+ switchInt(const 1_isize) -> [1_isize: bb1, otherwise: bb3]; // scope 2 at $DIR/discriminant.rs:11:21: 11:31
2527
}
2628

2729
bb1: {
28-
switchInt(((_3 as Some).0: bool)) -> [false: bb3, otherwise: bb2]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31
30+
switchInt(((_3 as Some).0: bool)) -> [false: bb3, otherwise: bb2]; // scope 2 at $DIR/discriminant.rs:11:21: 11:31
2931
}
3032

3133
bb2: {

src/test/mir-opt/early_otherwise_branch_soundness.no_downcast.EarlyOtherwiseBranch.diff

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
let mut _2: isize; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:13:20: 13:30
88
let mut _3: isize; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
99
let mut _4: &E; // in scope 0 at $DIR/early_otherwise_branch_soundness.rs:12:16: 12:17
10+
scope 1 {
11+
}
1012

1113
bb0: {
12-
_3 = discriminant((*_1)); // scope 0 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
13-
switchInt(move _3) -> [1_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
14+
_3 = discriminant((*_1)); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
15+
switchInt(move _3) -> [1_isize: bb1, otherwise: bb3]; // scope 1 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
1416
}
1517

1618
bb1: {
17-
StorageLive(_4); // scope 0 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
18-
_4 = move (((*_1) as Some).0: &E); // scope 0 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
19-
_2 = discriminant((*_4)); // scope 0 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
20-
StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
21-
switchInt(move _2) -> [1_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
19+
StorageLive(_4); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
20+
_4 = move (((*_1) as Some).0: &E); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
21+
_2 = discriminant((*_4)); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
22+
StorageDead(_4); // scope 1 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
23+
switchInt(move _2) -> [1_isize: bb2, otherwise: bb3]; // scope 1 at $DIR/early_otherwise_branch_soundness.rs:13:12: 13:31
2224
}
2325

2426
bb2: {

src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
let _6: core::num::flt2dec::Sign; // in scope 1 at $DIR/funky_arms.rs:19:9: 19:13
2828
scope 2 {
2929
debug sign => _6; // in scope 2 at $DIR/funky_arms.rs:19:9: 19:13
30-
let _10: usize; // in scope 2 at $DIR/funky_arms.rs:24:17: 24:26
3130
scope 3 {
3231
debug precision => _10; // in scope 3 at $DIR/funky_arms.rs:24:17: 24:26
32+
let _10: usize; // in scope 3 at $DIR/funky_arms.rs:24:17: 24:26
3333
}
3434
}
3535
}
@@ -63,19 +63,19 @@
6363
}
6464

6565
bb4: {
66-
StorageLive(_7); // scope 2 at $DIR/funky_arms.rs:24:30: 24:45
67-
StorageLive(_8); // scope 2 at $DIR/funky_arms.rs:24:30: 24:45
68-
_8 = &(*_1); // scope 2 at $DIR/funky_arms.rs:24:30: 24:45
69-
_7 = Formatter::precision(move _8) -> bb5; // scope 2 at $DIR/funky_arms.rs:24:30: 24:45
66+
StorageLive(_7); // scope 3 at $DIR/funky_arms.rs:24:30: 24:45
67+
StorageLive(_8); // scope 3 at $DIR/funky_arms.rs:24:30: 24:45
68+
_8 = &(*_1); // scope 3 at $DIR/funky_arms.rs:24:30: 24:45
69+
_7 = Formatter::precision(move _8) -> bb5; // scope 3 at $DIR/funky_arms.rs:24:30: 24:45
7070
// mir::Constant
7171
// + span: $DIR/funky_arms.rs:24:34: 24:43
7272
// + literal: Const { ty: for<'r> fn(&'r Formatter) -> Option<usize> {Formatter::precision}, val: Value(Scalar(<ZST>)) }
7373
}
7474

7575
bb5: {
76-
StorageDead(_8); // scope 2 at $DIR/funky_arms.rs:24:44: 24:45
77-
_9 = discriminant(_7); // scope 2 at $DIR/funky_arms.rs:24:12: 24:27
78-
switchInt(move _9) -> [1_isize: bb6, otherwise: bb8]; // scope 2 at $DIR/funky_arms.rs:24:12: 24:27
76+
StorageDead(_8); // scope 3 at $DIR/funky_arms.rs:24:44: 24:45
77+
_9 = discriminant(_7); // scope 3 at $DIR/funky_arms.rs:24:12: 24:27
78+
switchInt(move _9) -> [1_isize: bb6, otherwise: bb8]; // scope 3 at $DIR/funky_arms.rs:24:12: 24:27
7979
}
8080

8181
bb6: {

src/test/mir-opt/issue_41888.main.ElaborateDrops.after.mir

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ fn main() -> () {
1414
let mut _11: isize; // in scope 0 at $DIR/issue-41888.rs:15:1: 15:2
1515
scope 1 {
1616
debug e => _1; // in scope 1 at $DIR/issue-41888.rs:7:9: 7:10
17-
let _6: K; // in scope 1 at $DIR/issue-41888.rs:10:21: 10:23
1817
scope 2 {
1918
debug _k => _6; // in scope 2 at $DIR/issue-41888.rs:10:21: 10:23
19+
let _6: K; // in scope 2 at $DIR/issue-41888.rs:10:21: 10:23
2020
}
2121
}
2222

@@ -51,8 +51,8 @@ fn main() -> () {
5151

5252
bb4: {
5353
StorageDead(_3); // scope 1 at $DIR/issue-41888.rs:9:19: 9:20
54-
_5 = discriminant(_1); // scope 1 at $DIR/issue-41888.rs:10:16: 10:24
55-
switchInt(move _5) -> [0_isize: bb5, otherwise: bb6]; // scope 1 at $DIR/issue-41888.rs:10:16: 10:24
54+
_5 = discriminant(_1); // scope 2 at $DIR/issue-41888.rs:10:16: 10:24
55+
switchInt(move _5) -> [0_isize: bb5, otherwise: bb6]; // scope 2 at $DIR/issue-41888.rs:10:16: 10:24
5656
}
5757

5858
bb5: {

src/test/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
let mut _6: u32; // in scope 0 at $DIR/issue-75439.rs:10:33: 10:35
1111
scope 1 {
1212
debug dwords => _2; // in scope 1 at $DIR/issue-75439.rs:7:9: 7:15
13-
let _4: u32; // in scope 1 at $DIR/issue-75439.rs:9:27: 9:29
1413
scope 3 {
1514
debug ip => _4; // in scope 3 at $DIR/issue-75439.rs:9:27: 9:29
15+
let _4: u32; // in scope 3 at $DIR/issue-75439.rs:9:27: 9:29
1616
}
1717
scope 4 {
1818
}
@@ -32,15 +32,15 @@
3232

3333
bb1: {
3434
StorageDead(_3); // scope 2 at $DIR/issue-75439.rs:7:52: 7:53
35-
switchInt(_2[0 of 4]) -> [0_u32: bb2, otherwise: bb8]; // scope 1 at $DIR/issue-75439.rs:9:12: 9:30
35+
switchInt(_2[0 of 4]) -> [0_u32: bb2, otherwise: bb8]; // scope 3 at $DIR/issue-75439.rs:9:12: 9:30
3636
}
3737

3838
bb2: {
39-
switchInt(_2[1 of 4]) -> [0_u32: bb3, otherwise: bb8]; // scope 1 at $DIR/issue-75439.rs:9:12: 9:30
39+
switchInt(_2[1 of 4]) -> [0_u32: bb3, otherwise: bb8]; // scope 3 at $DIR/issue-75439.rs:9:12: 9:30
4040
}
4141

4242
bb3: {
43-
switchInt(_2[2 of 4]) -> [0_u32: bb5, 4294901760_u32: bb6, otherwise: bb8]; // scope 1 at $DIR/issue-75439.rs:9:12: 9:30
43+
switchInt(_2[2 of 4]) -> [0_u32: bb5, 4294901760_u32: bb6, otherwise: bb8]; // scope 3 at $DIR/issue-75439.rs:9:12: 9:30
4444
}
4545

4646
bb4: {

src/test/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals.diff

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@
88
let mut _3: std::option::Option<T>; // in scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:51: 4:68
99
let mut _4: isize; // in scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:22: 4:26
1010
let mut _5: isize; // in scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:13: 4:20
11-
let _6: u8; // in scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:18: 4:19
1211
- let mut _7: bool; // in scope 0 at $DIR/simplify-locals-fixedpoint.rs:5:12: 5:20
1312
- let mut _8: u8; // in scope 0 at $DIR/simplify-locals-fixedpoint.rs:5:12: 5:13
1413
scope 1 {
1514
debug a => _6; // in scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:18: 4:19
15+
let _6: u8; // in scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:18: 4:19
1616
}
1717

1818
bb0: {
19-
StorageLive(_1); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69
20-
StorageLive(_2); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:31: 4:49
21-
Deinit(_2); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:31: 4:49
22-
discriminant(_2) = 0; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:31: 4:49
23-
StorageLive(_3); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:51: 4:68
24-
Deinit(_3); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:51: 4:68
25-
discriminant(_3) = 0; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:51: 4:68
26-
Deinit(_1); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69
27-
(_1.0: std::option::Option<u8>) = move _2; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69
28-
(_1.1: std::option::Option<T>) = move _3; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69
29-
StorageDead(_3); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69
30-
StorageDead(_2); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69
31-
_5 = discriminant((_1.0: std::option::Option<u8>)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27
32-
switchInt(move _5) -> [1_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27
19+
StorageLive(_1); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69
20+
StorageLive(_2); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:31: 4:49
21+
Deinit(_2); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:31: 4:49
22+
discriminant(_2) = 0; // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:31: 4:49
23+
StorageLive(_3); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:51: 4:68
24+
Deinit(_3); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:51: 4:68
25+
discriminant(_3) = 0; // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:51: 4:68
26+
Deinit(_1); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69
27+
(_1.0: std::option::Option<u8>) = move _2; // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69
28+
(_1.1: std::option::Option<T>) = move _3; // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69
29+
StorageDead(_3); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69
30+
StorageDead(_2); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69
31+
_5 = discriminant((_1.0: std::option::Option<u8>)); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27
32+
switchInt(move _5) -> [1_isize: bb1, otherwise: bb3]; // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27
3333
}
3434

3535
bb1: {
36-
_4 = discriminant((_1.1: std::option::Option<T>)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27
37-
switchInt(move _4) -> [0_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27
36+
_4 = discriminant((_1.1: std::option::Option<T>)); // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27
37+
switchInt(move _4) -> [0_isize: bb2, otherwise: bb3]; // scope 1 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27
3838
}
3939

4040
bb2: {

0 commit comments

Comments
 (0)