Skip to content

Commit 3344232

Browse files
committed
Run check_match and check_liveness when MIR is built instead of having an explicit phase for them
1 parent 5bb58a6 commit 3344232

18 files changed

+321
-328
lines changed

compiler/rustc_interface/src/passes.rs

-21
Original file line numberDiff line numberDiff line change
@@ -761,27 +761,6 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
761761
// passes are timed inside typeck
762762
rustc_hir_analysis::check_crate(tcx)?;
763763

764-
sess.time("misc_checking_2", || {
765-
parallel!(
766-
{
767-
sess.time("match_checking", || {
768-
tcx.hir().par_body_owners(|def_id| tcx.ensure().check_match(def_id))
769-
});
770-
},
771-
{
772-
sess.time("liveness_checking", || {
773-
tcx.hir().par_body_owners(|def_id| {
774-
// this must run before MIR dump, because
775-
// "not all control paths return a value" is reported here.
776-
//
777-
// maybe move the check to a MIR pass?
778-
tcx.ensure().check_liveness(def_id);
779-
});
780-
});
781-
}
782-
);
783-
});
784-
785764
sess.time("MIR_borrow_checking", || {
786765
tcx.hir().par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
787766
});

compiler/rustc_mir_build/src/build/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ fn mir_build(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
5151
// of `mir_build`, so now we can steal it
5252
let thir = thir.steal();
5353

54+
tcx.ensure().check_match(def);
55+
// this must run before MIR dump, because
56+
// "not all control paths return a value" is reported here.
57+
//
58+
// maybe move the check to a MIR pass?
59+
tcx.ensure().check_liveness(def);
60+
5461
match thir.body_type {
5562
thir::BodyTy::Fn(fn_sig) => construct_fn(tcx, def, &thir, expr, fn_sig),
5663
thir::BodyTy::Const(ty) => construct_const(tcx, def, &thir, expr, ty),

compiler/rustc_passes/src/liveness.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ use rustc_middle::ty::query::Providers;
9898
use rustc_middle::ty::{self, RootVariableMinCaptureList, Ty, TyCtxt};
9999
use rustc_session::lint;
100100
use rustc_span::symbol::{kw, sym, Symbol};
101+
use rustc_span::DUMMY_SP;
101102
use rustc_span::{BytePos, Span};
102103

103104
use std::collections::VecDeque;
@@ -586,8 +587,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
586587
}
587588

588589
fn assigned_on_exit(&self, ln: LiveNode, var: Variable) -> bool {
589-
let successor = self.successors[ln].unwrap();
590-
self.assigned_on_entry(successor, var)
590+
match self.successors[ln] {
591+
Some(successor) => self.assigned_on_entry(successor, var),
592+
None => {
593+
self.ir.tcx.sess.delay_span_bug(DUMMY_SP, "no successor");
594+
true
595+
}
596+
}
591597
}
592598

593599
fn write_vars<F>(&self, wr: &mut dyn Write, mut test: F) -> io::Result<()>

tests/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ promoted[0] in FOO: &[&i32; 1] = {
77
let mut _3: *const i32; // in scope 0 at $DIR/const_promotion_extern_static.rs:+0:42: +0:43
88

99
bb0: {
10-
_3 = const {alloc2: *const i32}; // scope 0 at $DIR/const_promotion_extern_static.rs:+0:42: +0:43
10+
_3 = const {alloc3: *const i32}; // scope 0 at $DIR/const_promotion_extern_static.rs:+0:42: +0:43
1111
// mir::Constant
1212
// + span: $DIR/const_promotion_extern_static.rs:13:42: 13:43
13-
// + literal: Const { ty: *const i32, val: Value(Scalar(alloc2)) }
13+
// + literal: Const { ty: *const i32, val: Value(Scalar(alloc3)) }
1414
_2 = &(*_3); // scope 0 at $DIR/const_promotion_extern_static.rs:+0:41: +0:43
1515
_1 = [move _2]; // scope 0 at $DIR/const_promotion_extern_static.rs:+0:31: +0:46
1616
_0 = &_1; // scope 0 at $DIR/const_promotion_extern_static.rs:+0:31: +0:55
1717
return; // scope 0 at $DIR/const_promotion_extern_static.rs:+0:31: +0:55
1818
}
1919
}
2020

21-
alloc2 (extern static: X)
21+
alloc3 (extern static: X)

tests/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
- StorageLive(_3); // scope 0 at $DIR/const_promotion_extern_static.rs:+0:31: +0:46
1919
- StorageLive(_4); // scope 0 at $DIR/const_promotion_extern_static.rs:+0:32: +0:45
2020
- StorageLive(_5); // scope 1 at $DIR/const_promotion_extern_static.rs:+0:42: +0:43
21-
- _5 = const {alloc2: *const i32}; // scope 1 at $DIR/const_promotion_extern_static.rs:+0:42: +0:43
21+
- _5 = const {alloc3: *const i32}; // scope 1 at $DIR/const_promotion_extern_static.rs:+0:42: +0:43
2222
+ _6 = const _; // scope 0 at $DIR/const_promotion_extern_static.rs:+0:31: +0:55
2323
// mir::Constant
2424
- // + span: $DIR/const_promotion_extern_static.rs:13:42: 13:43
25-
- // + literal: Const { ty: *const i32, val: Value(Scalar(alloc2)) }
25+
- // + literal: Const { ty: *const i32, val: Value(Scalar(alloc3)) }
2626
- _4 = &(*_5); // scope 1 at $DIR/const_promotion_extern_static.rs:+0:41: +0:43
2727
- _3 = [move _4]; // scope 0 at $DIR/const_promotion_extern_static.rs:+0:31: +0:46
2828
- _2 = &_3; // scope 0 at $DIR/const_promotion_extern_static.rs:+0:31: +0:55
@@ -50,5 +50,5 @@
5050
}
5151
}
5252
-
53-
- alloc2 (extern static: X)
53+
- alloc3 (extern static: X)
5454

tests/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
error: cannot borrow value as mutable because it is also borrowed as immutable
2-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:36:9
3-
|
4-
LL | ref foo @ [.., ref mut bar] => (),
5-
| ^^^^^^^ ----------- value is mutably borrowed by `bar` here
6-
| |
7-
| value is borrowed by `foo` here
8-
9-
error: cannot borrow value as mutable because it is also borrowed as immutable
10-
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:120:9
11-
|
12-
LL | ref foo @ Some(box ref mut s) => (),
13-
| ^^^^^^^ --------- value is mutably borrowed by `s` here
14-
| |
15-
| value is borrowed by `foo` here
16-
171
error[E0382]: borrow of moved value: `x`
182
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:18:5
193
|
@@ -43,6 +27,14 @@ LL | &x;
4327
LL | drop(r);
4428
| - mutable borrow later used here
4529

30+
error: cannot borrow value as mutable because it is also borrowed as immutable
31+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:36:9
32+
|
33+
LL | ref foo @ [.., ref mut bar] => (),
34+
| ^^^^^^^ ----------- value is mutably borrowed by `bar` here
35+
| |
36+
| value is borrowed by `foo` here
37+
4638
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
4739
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:50:5
4840
|
@@ -120,6 +112,14 @@ LL | &mut x;
120112
LL | drop(r);
121113
| - immutable borrow later used here
122114

115+
error: cannot borrow value as mutable because it is also borrowed as immutable
116+
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:120:9
117+
|
118+
LL | ref foo @ Some(box ref mut s) => (),
119+
| ^^^^^^^ --------- value is mutably borrowed by `s` here
120+
| |
121+
| value is borrowed by `foo` here
122+
123123
error[E0382]: borrow of moved value: `x`
124124
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:134:5
125125
|

tests/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
2-
--> $DIR/pattern-matching-should-fail.rs:67:23
3-
|
4-
LL | let c1 = || match x { };
5-
| ^
6-
|
7-
= note: the matched value is of type `u8`
8-
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
9-
|
10-
LL ~ let c1 = || match x {
11-
LL + _ => todo!(),
12-
LL ~ };
13-
|
14-
151
error[E0381]: used binding `x` isn't initialized
162
--> $DIR/pattern-matching-should-fail.rs:8:23
173
|
@@ -69,6 +55,20 @@ LL | let t: !;
6955
LL | match t { };
7056
| ^ `t` used here but it isn't initialized
7157

58+
error[E0004]: non-exhaustive patterns: type `u8` is non-empty
59+
--> $DIR/pattern-matching-should-fail.rs:67:23
60+
|
61+
LL | let c1 = || match x { };
62+
| ^
63+
|
64+
= note: the matched value is of type `u8`
65+
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
66+
|
67+
LL ~ let c1 = || match x {
68+
LL + _ => todo!(),
69+
LL ~ };
70+
|
71+
7272
error[E0381]: used binding `x` isn't initialized
7373
--> $DIR/pattern-matching-should-fail.rs:67:23
7474
|

tests/ui/lint/lint-uppercase-variables.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ error[E0170]: pattern binding `Foo` is named the same as one of the variants of
1212
LL | let Foo = foo::Foo::Foo;
1313
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
1414

15-
error[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
16-
--> $DIR/lint-uppercase-variables.rs:33:17
17-
|
18-
LL | fn in_param(Foo: foo::Foo) {}
19-
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
20-
2115
warning: unused variable: `Foo`
2216
--> $DIR/lint-uppercase-variables.rs:22:9
2317
|
@@ -37,6 +31,12 @@ warning: unused variable: `Foo`
3731
LL | let Foo = foo::Foo::Foo;
3832
| ^^^ help: if this is intentional, prefix it with an underscore: `_Foo`
3933

34+
error[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
35+
--> $DIR/lint-uppercase-variables.rs:33:17
36+
|
37+
LL | fn in_param(Foo: foo::Foo) {}
38+
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
39+
4040
warning: unused variable: `Foo`
4141
--> $DIR/lint-uppercase-variables.rs:33:17
4242
|

tests/ui/lint/rfc-2383-lint-reason/expect_nested_lint_levels.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
error: unused variable: `this_is_my_function`
2-
--> $DIR/expect_nested_lint_levels.rs:48:9
3-
|
4-
LL | let this_is_my_function = 3;
5-
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_this_is_my_function`
6-
|
7-
note: the lint level is defined here
8-
--> $DIR/expect_nested_lint_levels.rs:45:10
9-
|
10-
LL | #[forbid(unused_variables)]
11-
| ^^^^^^^^^^^^^^^^
12-
131
warning: variable does not need to be mutable
142
--> $DIR/expect_nested_lint_levels.rs:36:13
153
|
@@ -25,6 +13,18 @@ note: the lint level is defined here
2513
LL | unused_mut,
2614
| ^^^^^^^^^^
2715

16+
error: unused variable: `this_is_my_function`
17+
--> $DIR/expect_nested_lint_levels.rs:48:9
18+
|
19+
LL | let this_is_my_function = 3;
20+
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_this_is_my_function`
21+
|
22+
note: the lint level is defined here
23+
--> $DIR/expect_nested_lint_levels.rs:45:10
24+
|
25+
LL | #[forbid(unused_variables)]
26+
| ^^^^^^^^^^^^^^^^
27+
2828
warning: this lint expectation is unfulfilled
2929
--> $DIR/expect_nested_lint_levels.rs:7:5
3030
|

tests/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ warning: unused variable: `fox_name`
1212
LL | let fox_name = "Sir Nibbles";
1313
| ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_fox_name`
1414

15-
warning: unused variable: `this_should_fulfill_the_expectation`
16-
--> $DIR/force_warn_expected_lints_fulfilled.rs:43:9
17-
|
18-
LL | let this_should_fulfill_the_expectation = "The `#[allow]` has no power here";
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_this_should_fulfill_the_expectation`
20-
2115
warning: variable does not need to be mutable
2216
--> $DIR/force_warn_expected_lints_fulfilled.rs:32:9
2317
|
@@ -28,6 +22,12 @@ LL | let mut what_does_the_fox_say = "*ding* *deng* *dung*";
2822
|
2923
= note: requested on the command line with `--force-warn unused-mut`
3024

25+
warning: unused variable: `this_should_fulfill_the_expectation`
26+
--> $DIR/force_warn_expected_lints_fulfilled.rs:43:9
27+
|
28+
LL | let this_should_fulfill_the_expectation = "The `#[allow]` has no power here";
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_this_should_fulfill_the_expectation`
30+
3131
warning: denote infinite loops with `loop { ... }`
3232
--> $DIR/force_warn_expected_lints_fulfilled.rs:10:5
3333
|

tests/ui/lint/unused/lint-unused-variables.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ note: the lint level is defined here
1010
LL | #![deny(unused_variables)]
1111
| ^^^^^^^^^^^^^^^^
1212

13-
error: unused variable: `b`
14-
--> $DIR/lint-unused-variables.rs:14:5
15-
|
16-
LL | b: i32,
17-
| ^ help: if this is intentional, prefix it with an underscore: `_b`
18-
1913
error: unused variable: `a`
2014
--> $DIR/lint-unused-variables.rs:22:9
2115
|
2216
LL | a: i32,
2317
| ^ help: if this is intentional, prefix it with an underscore: `_a`
2418

19+
error: unused variable: `b`
20+
--> $DIR/lint-unused-variables.rs:14:5
21+
|
22+
LL | b: i32,
23+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
24+
2525
error: unused variable: `b`
2626
--> $DIR/lint-unused-variables.rs:29:9
2727
|
+27-26
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
1-
warning: variable `a` is assigned to, but never used
2-
--> $DIR/liveness-consts.rs:7:13
1+
warning: unused variable: `e`
2+
--> $DIR/liveness-consts.rs:24:13
33
|
4-
LL | let mut a = 0;
5-
| ^
4+
LL | let e = 1;
5+
| ^ help: if this is intentional, prefix it with an underscore: `_e`
66
|
7-
= note: consider using `_a` instead
87
note: the lint level is defined here
98
--> $DIR/liveness-consts.rs:2:9
109
|
1110
LL | #![warn(unused)]
1211
| ^^^^^^
1312
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
1413

15-
warning: value assigned to `b` is never read
16-
--> $DIR/liveness-consts.rs:17:5
17-
|
18-
LL | b += 1;
19-
| ^
20-
|
21-
= help: maybe it is overwritten before being read?
22-
= note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
23-
24-
warning: unused variable: `e`
25-
--> $DIR/liveness-consts.rs:24:13
26-
|
27-
LL | let e = 1;
28-
| ^ help: if this is intentional, prefix it with an underscore: `_e`
29-
3014
warning: unused variable: `s`
3115
--> $DIR/liveness-consts.rs:33:24
3216
|
@@ -39,6 +23,29 @@ warning: unused variable: `z`
3923
LL | pub fn f(x: [u8; { let s = 17; 100 }]) -> [u8; { let z = 18; 100 }] {
4024
| ^ help: if this is intentional, prefix it with an underscore: `_z`
4125

26+
warning: unused variable: `z`
27+
--> $DIR/liveness-consts.rs:60:13
28+
|
29+
LL | let z = 42;
30+
| ^ help: if this is intentional, prefix it with an underscore: `_z`
31+
32+
warning: variable `a` is assigned to, but never used
33+
--> $DIR/liveness-consts.rs:7:13
34+
|
35+
LL | let mut a = 0;
36+
| ^
37+
|
38+
= note: consider using `_a` instead
39+
40+
warning: value assigned to `b` is never read
41+
--> $DIR/liveness-consts.rs:17:5
42+
|
43+
LL | b += 1;
44+
| ^
45+
|
46+
= help: maybe it is overwritten before being read?
47+
= note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
48+
4249
warning: value assigned to `t` is never read
4350
--> $DIR/liveness-consts.rs:42:9
4451
|
@@ -53,11 +60,5 @@ warning: unused variable: `w`
5360
LL | let w = 10;
5461
| ^ help: if this is intentional, prefix it with an underscore: `_w`
5562

56-
warning: unused variable: `z`
57-
--> $DIR/liveness-consts.rs:60:13
58-
|
59-
LL | let z = 42;
60-
| ^ help: if this is intentional, prefix it with an underscore: `_z`
61-
6263
warning: 8 warnings emitted
6364

0 commit comments

Comments
 (0)