Skip to content

Commit e39c92e

Browse files
committed
Actually fix
1 parent cc75f0e commit e39c92e

File tree

58 files changed

+895
-775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+895
-775
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6363
(if_then_scope, then_source_info),
6464
LintLevel::Inherited,
6565
|this| {
66+
let variable_scope =
67+
this.new_source_scope(then_expr.span, LintLevel::Inherited, None);
68+
this.source_scope = variable_scope;
6669
let (then_block, else_block) =
6770
this.in_if_then_scope(condition_scope, |this| {
6871
let then_blk = unpack!(this.then_else_break(
6972
block,
7073
&this.thir[cond],
7174
Some(condition_scope),
7275
condition_scope,
73-
then_expr.span
76+
SourceInfo { span: then_expr.span, scope: variable_scope }
7477
));
7578

7679
this.expr_into_dest(destination, then_blk, then_expr)

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

+19-18
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_span: Span,
44+
variable_source_info: SourceInfo,
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_span,
56+
variable_source_info,
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_span,
64+
variable_source_info,
6565
));
6666

6767
rhs_then_block.unit()
@@ -74,23 +74,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7474
&this.thir[value],
7575
temp_scope_override,
7676
break_scope,
77-
variable_span,
77+
variable_source_info,
7878
)
7979
})
8080
}
81-
ExprKind::Let { expr, ref pat } => {
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-
)
93-
}
81+
ExprKind::Let { expr, ref pat } => this.lower_let_expr(
82+
block,
83+
&this.thir[expr],
84+
pat,
85+
break_scope,
86+
Some(variable_source_info.scope),
87+
variable_source_info.span,
88+
),
9489
_ => {
9590
let temp_scope = temp_scope_override.unwrap_or_else(|| this.local_scope());
9691
let mutability = Mutability::Mut;
@@ -1988,7 +1983,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19881983
Guard::If(e) => {
19891984
let e = &this.thir[e];
19901985
guard_span = e.span;
1991-
this.then_else_break(block, e, None, match_scope, arm_span)
1986+
this.then_else_break(
1987+
block,
1988+
e,
1989+
None,
1990+
match_scope,
1991+
this.source_info(arm_span),
1992+
)
19921993
}
19931994
Guard::IfLet(ref pat, scrutinee) => {
19941995
let s = &this.thir[scrutinee];

src/test/mir-opt/bool_compare.opt1.InstCombine.diff

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
let mut _0: u32; // return place in scope 0 at $DIR/bool_compare.rs:2:21: 2:24
77
let mut _2: bool; // in scope 0 at $DIR/bool_compare.rs:3:8: 3:17
88
let mut _3: bool; // in scope 0 at $DIR/bool_compare.rs:3:8: 3:9
9+
scope 1 {
10+
}
911

1012
bb0: {
11-
StorageLive(_2); // scope 0 at $DIR/bool_compare.rs:3:8: 3:17
12-
StorageLive(_3); // scope 0 at $DIR/bool_compare.rs:3:8: 3:9
13-
_3 = _1; // scope 0 at $DIR/bool_compare.rs:3:8: 3:9
14-
- _2 = Ne(move _3, const true); // scope 0 at $DIR/bool_compare.rs:3:8: 3:17
15-
+ _2 = Not(move _3); // scope 0 at $DIR/bool_compare.rs:3:8: 3:17
16-
StorageDead(_3); // scope 0 at $DIR/bool_compare.rs:3:16: 3:17
17-
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/bool_compare.rs:3:8: 3:17
13+
StorageLive(_2); // scope 1 at $DIR/bool_compare.rs:3:8: 3:17
14+
StorageLive(_3); // scope 1 at $DIR/bool_compare.rs:3:8: 3:9
15+
_3 = _1; // scope 1 at $DIR/bool_compare.rs:3:8: 3:9
16+
- _2 = Ne(move _3, const true); // scope 1 at $DIR/bool_compare.rs:3:8: 3:17
17+
+ _2 = Not(move _3); // scope 1 at $DIR/bool_compare.rs:3:8: 3:17
18+
StorageDead(_3); // scope 1 at $DIR/bool_compare.rs:3:16: 3:17
19+
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/bool_compare.rs:3:8: 3:17
1820
}
1921

2022
bb1: {
21-
_0 = const 0_u32; // scope 0 at $DIR/bool_compare.rs:3:20: 3:21
23+
_0 = const 0_u32; // scope 1 at $DIR/bool_compare.rs:3:20: 3:21
2224
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:3:5: 3:34
2325
}
2426

src/test/mir-opt/bool_compare.opt2.InstCombine.diff

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
let mut _0: u32; // return place in scope 0 at $DIR/bool_compare.rs:7:21: 7:24
77
let mut _2: bool; // in scope 0 at $DIR/bool_compare.rs:8:8: 8:17
88
let mut _3: bool; // in scope 0 at $DIR/bool_compare.rs:8:16: 8:17
9+
scope 1 {
10+
}
911

1012
bb0: {
11-
StorageLive(_2); // scope 0 at $DIR/bool_compare.rs:8:8: 8:17
12-
StorageLive(_3); // scope 0 at $DIR/bool_compare.rs:8:16: 8:17
13-
_3 = _1; // scope 0 at $DIR/bool_compare.rs:8:16: 8:17
14-
- _2 = Ne(const true, move _3); // scope 0 at $DIR/bool_compare.rs:8:8: 8:17
15-
+ _2 = Not(move _3); // scope 0 at $DIR/bool_compare.rs:8:8: 8:17
16-
StorageDead(_3); // scope 0 at $DIR/bool_compare.rs:8:16: 8:17
17-
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/bool_compare.rs:8:8: 8:17
13+
StorageLive(_2); // scope 1 at $DIR/bool_compare.rs:8:8: 8:17
14+
StorageLive(_3); // scope 1 at $DIR/bool_compare.rs:8:16: 8:17
15+
_3 = _1; // scope 1 at $DIR/bool_compare.rs:8:16: 8:17
16+
- _2 = Ne(const true, move _3); // scope 1 at $DIR/bool_compare.rs:8:8: 8:17
17+
+ _2 = Not(move _3); // scope 1 at $DIR/bool_compare.rs:8:8: 8:17
18+
StorageDead(_3); // scope 1 at $DIR/bool_compare.rs:8:16: 8:17
19+
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/bool_compare.rs:8:8: 8:17
1820
}
1921

2022
bb1: {
21-
_0 = const 0_u32; // scope 0 at $DIR/bool_compare.rs:8:20: 8:21
23+
_0 = const 0_u32; // scope 1 at $DIR/bool_compare.rs:8:20: 8:21
2224
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:8:5: 8:34
2325
}
2426

src/test/mir-opt/bool_compare.opt3.InstCombine.diff

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
let mut _0: u32; // return place in scope 0 at $DIR/bool_compare.rs:12:21: 12:24
77
let mut _2: bool; // in scope 0 at $DIR/bool_compare.rs:13:8: 13:18
88
let mut _3: bool; // in scope 0 at $DIR/bool_compare.rs:13:8: 13:9
9+
scope 1 {
10+
}
911

1012
bb0: {
11-
StorageLive(_2); // scope 0 at $DIR/bool_compare.rs:13:8: 13:18
12-
StorageLive(_3); // scope 0 at $DIR/bool_compare.rs:13:8: 13:9
13-
_3 = _1; // scope 0 at $DIR/bool_compare.rs:13:8: 13:9
14-
- _2 = Eq(move _3, const false); // scope 0 at $DIR/bool_compare.rs:13:8: 13:18
15-
+ _2 = Not(move _3); // scope 0 at $DIR/bool_compare.rs:13:8: 13:18
16-
StorageDead(_3); // scope 0 at $DIR/bool_compare.rs:13:17: 13:18
17-
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/bool_compare.rs:13:8: 13:18
13+
StorageLive(_2); // scope 1 at $DIR/bool_compare.rs:13:8: 13:18
14+
StorageLive(_3); // scope 1 at $DIR/bool_compare.rs:13:8: 13:9
15+
_3 = _1; // scope 1 at $DIR/bool_compare.rs:13:8: 13:9
16+
- _2 = Eq(move _3, const false); // scope 1 at $DIR/bool_compare.rs:13:8: 13:18
17+
+ _2 = Not(move _3); // scope 1 at $DIR/bool_compare.rs:13:8: 13:18
18+
StorageDead(_3); // scope 1 at $DIR/bool_compare.rs:13:17: 13:18
19+
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/bool_compare.rs:13:8: 13:18
1820
}
1921

2022
bb1: {
21-
_0 = const 0_u32; // scope 0 at $DIR/bool_compare.rs:13:21: 13:22
23+
_0 = const 0_u32; // scope 1 at $DIR/bool_compare.rs:13:21: 13:22
2224
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:13:5: 13:35
2325
}
2426

src/test/mir-opt/bool_compare.opt4.InstCombine.diff

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
let mut _0: u32; // return place in scope 0 at $DIR/bool_compare.rs:17:21: 17:24
77
let mut _2: bool; // in scope 0 at $DIR/bool_compare.rs:18:8: 18:18
88
let mut _3: bool; // in scope 0 at $DIR/bool_compare.rs:18:17: 18:18
9+
scope 1 {
10+
}
911

1012
bb0: {
11-
StorageLive(_2); // scope 0 at $DIR/bool_compare.rs:18:8: 18:18
12-
StorageLive(_3); // scope 0 at $DIR/bool_compare.rs:18:17: 18:18
13-
_3 = _1; // scope 0 at $DIR/bool_compare.rs:18:17: 18:18
14-
- _2 = Eq(const false, move _3); // scope 0 at $DIR/bool_compare.rs:18:8: 18:18
15-
+ _2 = Not(move _3); // scope 0 at $DIR/bool_compare.rs:18:8: 18:18
16-
StorageDead(_3); // scope 0 at $DIR/bool_compare.rs:18:17: 18:18
17-
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/bool_compare.rs:18:8: 18:18
13+
StorageLive(_2); // scope 1 at $DIR/bool_compare.rs:18:8: 18:18
14+
StorageLive(_3); // scope 1 at $DIR/bool_compare.rs:18:17: 18:18
15+
_3 = _1; // scope 1 at $DIR/bool_compare.rs:18:17: 18:18
16+
- _2 = Eq(const false, move _3); // scope 1 at $DIR/bool_compare.rs:18:8: 18:18
17+
+ _2 = Not(move _3); // scope 1 at $DIR/bool_compare.rs:18:8: 18:18
18+
StorageDead(_3); // scope 1 at $DIR/bool_compare.rs:18:17: 18:18
19+
switchInt(move _2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/bool_compare.rs:18:8: 18:18
1820
}
1921

2022
bb1: {
21-
_0 = const 0_u32; // scope 0 at $DIR/bool_compare.rs:18:21: 18:22
23+
_0 = const 0_u32; // scope 1 at $DIR/bool_compare.rs:18:21: 18:22
2224
goto -> bb3; // scope 0 at $DIR/bool_compare.rs:18:5: 18:35
2325
}
2426

src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff

+13-11
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,35 @@
77
- let mut _2: bool; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
88
- let mut _3: isize; // in scope 0 at $DIR/const_goto.rs:12:22: 12:28
99
+ let mut _2: isize; // in scope 0 at $DIR/const_goto.rs:12:22: 12:28
10+
scope 1 {
11+
}
1012

1113
bb0: {
12-
- StorageLive(_2); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
13-
- _3 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:17: 12:20
14-
- switchInt(move _3) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
15-
+ _2 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:17: 12:20
16-
+ switchInt(move _2) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
14+
- StorageLive(_2); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
15+
- _3 = discriminant(_1); // scope 1 at $DIR/const_goto.rs:12:17: 12:20
16+
- switchInt(move _3) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
17+
+ _2 = discriminant(_1); // scope 1 at $DIR/const_goto.rs:12:17: 12:20
18+
+ switchInt(move _2) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
1719
}
1820

1921
bb1: {
20-
- _2 = const false; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
21-
- goto -> bb3; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
22+
- _2 = const false; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
23+
- goto -> bb3; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2224
+ _0 = const 42_u64; // scope 0 at $DIR/const_goto.rs:12:53: 12:55
2325
+ goto -> bb3; // scope 0 at $DIR/const_goto.rs:12:5: 12:57
2426
}
2527

2628
bb2: {
27-
- _2 = const true; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
28-
- goto -> bb3; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
29+
- _2 = const true; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
30+
- goto -> bb3; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
2931
- }
3032
-
3133
- bb3: {
32-
- switchInt(move _2) -> [false: bb5, otherwise: bb4]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
34+
- switchInt(move _2) -> [false: bb5, otherwise: bb4]; // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
3335
- }
3436
-
3537
- bb4: {
36-
_0 = const 23_u64; // scope 0 at $DIR/const_goto.rs:12:41: 12:43
38+
_0 = const 23_u64; // scope 1 at $DIR/const_goto.rs:12:41: 12:43
3739
- goto -> bb6; // scope 0 at $DIR/const_goto.rs:12:5: 12:57
3840
+ goto -> bb3; // scope 0 at $DIR/const_goto.rs:12:5: 12:57
3941
}

0 commit comments

Comments
 (0)