Skip to content

Commit 1f1a316

Browse files
committed
Auto merge of #142390 - cjgillot:mir-liveness, r=davidtwco
Perform unused assignment and unused variables lints on MIR. Rebase of rust-lang/rust#101500 Fixes rust-lang/rust#51003. The first commit moves detection of uninhabited types from the current liveness pass to MIR building. In order to keep the same level of diagnostics, I had to instrument MIR a little more: - keep for which original local a guard local is created; - store in the `VarBindingForm` the list of introducer places and whether this was a shorthand pattern. I am not very proud of the handling of self-assignments. The proposed scheme is in two parts: first detect probable self-assignments, by pattern matching on MIR, and second treat them specially during dataflow analysis. I welcome ideas. Please review carefully the changes in tests. There are many small changes to behaviour, and I'm not sure all of them are desirable.
2 parents 5e882cb + f7f9afa commit 1f1a316

File tree

4 files changed

+6
-0
lines changed

4 files changed

+6
-0
lines changed

tests/fail/function_calls/arg_inplace_locals_alias.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
//@[tree]compile-flags: -Zmiri-tree-borrows
55
// Validation forces more things into memory, which we can't have here.
66
//@compile-flags: -Zmiri-disable-validation
7+
78
#![feature(custom_mir, core_intrinsics)]
9+
#![allow(unused)]
10+
811
use std::intrinsics::mir::*;
912

1013
pub struct S(i32);

tests/fail/function_calls/arg_inplace_observe_after.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn main() {
2222
}
2323
}
2424

25+
#[expect(unused_variables, unused_assignments)]
2526
pub fn change_arg(mut x: S) {
2627
x.0 = 0;
2728
}

tests/fail/function_calls/arg_inplace_observe_during.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn main() {
2323
}
2424
}
2525

26+
#[expect(unused_variables, unused_assignments)]
2627
pub fn change_arg(mut x: S, ptr: *mut S) {
2728
x.0 = 0;
2829
// If `x` got passed in-place, we'd see the write through `ptr`!

tests/pass/align_repeat_into_well_aligned_array.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use std::mem::size_of;
44

5+
#[expect(unused_variables, unused_assignments)]
56
fn main() {
67
let mut a = Params::new();
78
// The array itself here happens to be quite well-aligned, but not all its elements have that

0 commit comments

Comments
 (0)