Skip to content

Commit

Permalink
rustfmt tests/mir-opt.
Browse files Browse the repository at this point in the history
The only non-obvious changes:
- `building/storage_live_dead_in_statics.rs` has a `#[rustfmt::skip]`
  attribute to avoid reformating a table of data.
- Two `.mir` files have slight changes involving line numbers.
- In `unusual_item_types.rs` an `EMIT_MIR` annotation is moved to
  outside a function, which is the usual spot, because `tidy` complains
  if such a comment is indented.

The commit also tweaks the comments in `rustfmt.toml`.
  • Loading branch information
nnethercote committed Jun 3, 2024
1 parent ac24299 commit c9c80d2
Show file tree
Hide file tree
Showing 66 changed files with 251 additions and 236 deletions.
14 changes: 5 additions & 9 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ ignore = [
"/build-*/",
"/vendor/",

# Some tests are not formatted, for multiple reasons:
# - some contain syntax errors that cause rustfmt to give an error
# - some UI tests are broken by different formatting
# - some require special comments in a particular position (e.g. `EMIT_MIR` comments)
# Some tests are not formatted, for various reasons.
"/tests/codegen/simd-intrinsic/", # Many types like `u8x64` are better hand-formatted.
"/tests/crashes/", # Many tests contain syntax errors.
"/tests/debuginfo/", # Tests are somewhat sensitive to source code layout.
"/tests/incremental/", # Tests are somewhat sensitive to source code layout.
"/tests/mir-opt/",
"/tests/crashes/", # Many of these tests contain syntax errors.
"/tests/debuginfo/", # These tests are somewhat sensitive to source code layout.
"/tests/incremental/", # These tests are somewhat sensitive to source code layout.
"/tests/pretty/",
"/tests/run-make/translation/test.rs", # Contains syntax errors.
"/tests/run-make/translation/test.rs", # This test contains syntax errors.
"/tests/run-make-fulldeps/",
"/tests/run-pass-valgrind/",
"/tests/rustdoc/",
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/address_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn address_of_reborrow() {
y as *const [i32; 10];
y as *const dyn Send;
y as *const [i32];
y as *const i32; // This is a cast, not a coercion
y as *const i32; // This is a cast, not a coercion

let p: *const _ = y;
let p: *const [i32; 10] = y;
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/array_index_is_temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ unsafe fn foo(z: *mut usize) -> u32 {
99
}


// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.mir
fn main() {
// CHECK-LABEL: fn main(
Expand Down
4 changes: 3 additions & 1 deletion tests/mir-opt/building/custom/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ fn numbered(i: (u32, i32)) {
}
}

struct S { x: f32 }
struct S {
x: f32,
}

// EMIT_MIR debuginfo.structured.built.after.mir
#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
Expand Down
24 changes: 16 additions & 8 deletions tests/mir-opt/building/enum_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
// EMIT_MIR enum_cast.far.built.after.mir

enum Foo {
A
A,
}

enum Bar {
A, B
A,
B,
}

#[repr(u8)]
enum Boo {
A, B
A,
B,
}

#[repr(i16)]
enum Far {
A, B
A,
B,
}

fn foo(foo: Foo) -> usize {
Expand All @@ -40,7 +43,9 @@ fn far(far: Far) -> isize {

// EMIT_MIR enum_cast.droppy.built.after.mir
enum Droppy {
A, B, C
A,
B,
C,
}

impl Drop for Droppy {
Expand Down Expand Up @@ -82,12 +87,15 @@ fn unsigny(x: UnsignedAroundZero) -> u16 {
x as u16
}

enum NotStartingAtZero { A = 4, B = 6, C = 8 }
enum NotStartingAtZero {
A = 4,
B = 6,
C = 8,
}

// EMIT_MIR enum_cast.offsetty.built.after.mir
fn offsetty(x: NotStartingAtZero) -> u32 {
x as u32
}

fn main() {
}
fn main() {}
8 changes: 6 additions & 2 deletions tests/mir-opt/building/logical_or_in_conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ fn test_or() {

// EMIT_MIR logical_or_in_conditional.test_complex.built.after.mir
fn test_complex() {
if let E::A(_) = E::f() && ((always_true() && Droppy(0).0 > 0) || Droppy(1).0 > 1) {}
if let E::A(_) = E::f()
&& ((always_true() && Droppy(0).0 > 0) || Droppy(1).0 > 1)
{}

if !always_true() && let E::B = E::f() {}
if !always_true()
&& let E::B = E::f()
{}
}

fn main() {
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/building/match/simple_match.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// skip-filecheck
// Test that we don't generate unnecessarily large MIR for very simple matches


// EMIT_MIR simple_match.match_bool.built.after.mir
fn match_bool(x: bool) -> usize {
match x {
Expand Down
13 changes: 3 additions & 10 deletions tests/mir-opt/building/shifts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@

// EMIT_MIR shifts.shift_signed.built.after.mir
fn shift_signed(small: i8, big: u128, a: i8, b: i32, c: i128) -> ([i8; 3], [u128; 3]) {
(
[small >> a, small >> b, small >> c],
[big << a, big << b, big << c],
)
([small >> a, small >> b, small >> c], [big << a, big << b, big << c])
}

// EMIT_MIR shifts.shift_unsigned.built.after.mir
fn shift_unsigned(small: u8, big: i128, a: u8, b: u32, c: u128) -> ([u8; 3], [i128; 3]) {
(
[small >> a, small >> b, small >> c],
[big << a, big << b, big << c],
)
([small >> a, small >> b, small >> c], [big << a, big << b, big << c])
}

fn main() {
}
fn main() {}
5 changes: 3 additions & 2 deletions tests/mir-opt/building/storage_live_dead_in_statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// generate `StorageStart` or `StorageEnd` statements.

// EMIT_MIR storage_live_dead_in_statics.XXX.built.after.mir
#[rustfmt::skip]
static XXX: &'static Foo = &Foo {
tup: "hi",
data: &[
Expand All @@ -20,13 +21,13 @@ static XXX: &'static Foo = &Foo {
(0, 1), (0, 2), (0, 3),
(0, 1), (0, 2), (0, 3),
(0, 1), (0, 2), (0, 3),
]
],
};

#[derive(Debug)]
struct Foo {
tup: &'static str,
data: &'static [(u32, u32)]
data: &'static [(u32, u32)],
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/control_flow_simplification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl<This> NeedsDrop for This {}

// EMIT_MIR control_flow_simplification.hello.GVN.diff
// EMIT_MIR control_flow_simplification.hello.PreCodegen.before.mir
fn hello<T>(){
fn hello<T>() {
if <bool>::NEEDS {
panic!()
}
Expand Down
10 changes: 6 additions & 4 deletions tests/mir-opt/const_prop/invalid_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

#[derive(Copy, Clone)]
#[repr(u32)]
enum E { A, B, C }
enum E {
A,
B,
C,
}

#[derive(Copy, Clone)]
enum Empty {}
Expand Down Expand Up @@ -39,7 +43,5 @@ fn main() {

// A non-UTF-8 string slice. Regression test for #75763 and #78520.
struct Str<const S: &'static str>;
let _non_utf8_str: Str::<{
unsafe { std::mem::transmute::<&[u8], &str>(&[0xC0, 0xC1, 0xF5]) }
}>;
let _non_utf8_str: Str<{ unsafe { std::mem::transmute::<&[u8], &str>(&[0xC0, 0xC1, 0xF5]) } }>;
}
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/offset_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Delta<T> {
enum Epsilon {
A(u8, u16),
B,
C { c: u32 }
C { c: u32 },
}

enum Zeta<T> {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/pointer_expose_provenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ test-mir-pass: GVN

#[inline(never)]
fn read(_: usize) { }
fn read(_: usize) {}

// EMIT_MIR pointer_expose_provenance.main.GVN.diff
fn main() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/scalar_literal_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ fn main() {
}

#[inline(never)]
fn consume(_: u32) { }
fn consume(_: u32) {}
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/switch_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

#[inline(never)]
fn foo(_: i32) { }
fn foo(_: i32) {}

// EMIT_MIR switch_int.main.GVN.diff
// EMIT_MIR switch_int.main.SimplifyConstCondition-after-const-prop.diff
Expand Down
5 changes: 4 additions & 1 deletion tests/mir-opt/const_prop/transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ pub unsafe fn undef_union_as_integer() -> u32 {
// CHECK-LABEL: fn undef_union_as_integer(
// CHECK: _1 = Union32 {
// CHECK: _0 = move _1 as u32 (Transmute);
union Union32 { value: u32, unit: () }
union Union32 {
value: u32,
unit: (),
}
unsafe { transmute(Union32 { unit: () }) }
}

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/const_prop/tuple_literal_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ fn main() {
}

#[inline(never)]
fn consume(_: (u32, u32)) { }
fn consume(_: (u32, u32)) {}
6 changes: 4 additions & 2 deletions tests/mir-opt/copy-prop/borrowed_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#![feature(custom_mir, core_intrinsics, freeze)]
#![allow(unused_assignments)]
extern crate core;
use core::marker::Freeze;
use core::intrinsics::mir::*;
use core::marker::Freeze;

fn opaque(_: impl Sized) -> bool { true }
fn opaque(_: impl Sized) -> bool {
true
}

fn cmp_ref(a: &u8, b: &u8) -> bool {
std::ptr::eq(a as *const u8, b as *const u8)
Expand Down
4 changes: 3 additions & 1 deletion tests/mir-opt/copy-prop/move_projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
extern crate core;
use core::intrinsics::mir::*;

fn opaque(_: impl Sized) -> bool { true }
fn opaque(_: impl Sized) -> bool {
true
}

struct Foo(u8);

Expand Down
27 changes: 21 additions & 6 deletions tests/mir-opt/dataflow-const-prop/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::intrinsics::mir::*;
#[derive(Copy, Clone)]
enum E {
V1(i32),
V2(i32)
V2(i32),
}

// EMIT_MIR enum.simple.DataflowConstProp.diff
Expand All @@ -23,7 +23,10 @@ fn simple() {
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb2, otherwise: bb1];
// CHECK: [[target_bb]]: {
// CHECK: [[x]] = const 0_i32;
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
let x = match e {
E::V1(x1) => x1,
E::V2(x2) => x2,
};
}

// EMIT_MIR enum.constant.DataflowConstProp.diff
Expand All @@ -39,7 +42,10 @@ fn constant() {
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb2, otherwise: bb1];
// CHECK: [[target_bb]]: {
// CHECK: [[x]] = const 0_i32;
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
let x = match e {
E::V1(x1) => x1,
E::V2(x2) => x2,
};
}

// EMIT_MIR enum.statics.DataflowConstProp.diff
Expand All @@ -58,7 +64,10 @@ fn statics() {
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb2, otherwise: bb1];
// CHECK: [[target_bb]]: {
// CHECK: [[x1]] = const 0_i32;
let x1 = match e1 { E::V1(x11) => x11, E::V2(x12) => x12 };
let x1 = match e1 {
E::V1(x11) => x11,
E::V2(x12) => x12,
};

static RC: &E = &E::V2(4);

Expand All @@ -72,7 +81,10 @@ fn statics() {
// One is `_9 = &(*_12) and another is `_9 = _11`. It is different from what we can
// get by printing MIR directly. It is better to check if there are any bugs in the
// MIR passes around this stage.
let x2 = match e2 { E::V1(x21) => x21, E::V2(x22) => x22 };
let x2 = match e2 {
E::V1(x21) => x21,
E::V2(x22) => x22,
};
}

#[rustc_layout_scalar_valid_range_start(1)]
Expand Down Expand Up @@ -132,7 +144,10 @@ fn multiple(x: bool, i: u8) {
// CHECK: [[x2]] = const 0_u8;
// CHECK: [[some:_.*]] = (({{_.*}} as Some).0: u8)
// CHECK: [[x2]] = [[some]];
let x2 = match e { Some(i) => i, None => 0 };
let x2 = match e {
Some(i) => i,
None => 0,
};

// Therefore, `x2` should be `Top` here, and no replacement shall happen.

Expand Down
6 changes: 3 additions & 3 deletions tests/mir-opt/dataflow-const-prop/mult_by_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

// EMIT_MIR mult_by_zero.test.DataflowConstProp.diff
// CHECK-LABEL: fn test(
fn test(x : i32) -> i32 {
x * 0
// CHECK: _0 = const 0_i32;
fn test(x: i32) -> i32 {
x * 0
// CHECK: _0 = const 0_i32;
}

fn main() {
Expand Down
5 changes: 4 additions & 1 deletion tests/mir-opt/dataflow-const-prop/transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ pub unsafe fn undef_union_as_integer() -> u32 {
// CHECK-LABEL: fn undef_union_as_integer(
// CHECK: _1 = Union32 {
// CHECK: _0 = move _1 as u32 (Transmute);
union Union32 { value: u32, unit: () }
union Union32 {
value: u32,
unit: (),
}
unsafe { transmute(Union32 { unit: () }) }
}

Expand Down
4 changes: 3 additions & 1 deletion tests/mir-opt/derefer_complex_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

fn main() {
for &foo in &[42, 43] { drop(foo) }
for &foo in &[42, 43] {
drop(foo)
}
}
Loading

0 comments on commit c9c80d2

Please sign in to comment.