Skip to content

Commit e0e225a

Browse files
committed
rustfmt tests/mir-opt.
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` annotations is move 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`.
1 parent ac24299 commit e0e225a

Some content is hidden

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

66 files changed

+251
-236
lines changed

rustfmt.toml

+5-9
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ ignore = [
1010
"/build-*/",
1111
"/vendor/",
1212

13-
# Some tests are not formatted, for multiple reasons:
14-
# - some contain syntax errors that cause rustfmt to give an error
15-
# - some UI tests are broken by different formatting
16-
# - some require special comments in a particular position (e.g. `EMIT_MIR` comments)
13+
# Some tests are not formatted, for various reasons.
1714
"/tests/codegen/simd-intrinsic/", # Many types like `u8x64` are better hand-formatted.
18-
"/tests/crashes/", # Many tests contain syntax errors.
19-
"/tests/debuginfo/", # Tests are somewhat sensitive to source code layout.
20-
"/tests/incremental/", # Tests are somewhat sensitive to source code layout.
21-
"/tests/mir-opt/",
15+
"/tests/crashes/", # Many of these tests contain syntax errors.
16+
"/tests/debuginfo/", # These tests are somewhat sensitive to source code layout.
17+
"/tests/incremental/", # These tests are somewhat sensitive to source code layout.
2218
"/tests/pretty/",
23-
"/tests/run-make/translation/test.rs", # Contains syntax errors.
19+
"/tests/run-make/translation/test.rs", # This test contains syntax errors.
2420
"/tests/run-make-fulldeps/",
2521
"/tests/run-pass-valgrind/",
2622
"/tests/rustdoc/",

tests/mir-opt/address_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn address_of_reborrow() {
99
y as *const [i32; 10];
1010
y as *const dyn Send;
1111
y as *const [i32];
12-
y as *const i32; // This is a cast, not a coercion
12+
y as *const i32; // This is a cast, not a coercion
1313

1414
let p: *const _ = y;
1515
let p: *const [i32; 10] = y;

tests/mir-opt/array_index_is_temporary.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ unsafe fn foo(z: *mut usize) -> u32 {
99
99
1010
}
1111

12-
1312
// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.mir
1413
fn main() {
1514
// CHECK-LABEL: fn main(

tests/mir-opt/building/custom/debuginfo.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ fn numbered(i: (u32, i32)) {
2727
}
2828
}
2929

30-
struct S { x: f32 }
30+
struct S {
31+
x: f32,
32+
}
3133

3234
// EMIT_MIR debuginfo.structured.built.after.mir
3335
#[custom_mir(dialect = "analysis", phase = "post-cleanup")]

tests/mir-opt/building/enum_cast.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@
55
// EMIT_MIR enum_cast.far.built.after.mir
66

77
enum Foo {
8-
A
8+
A,
99
}
1010

1111
enum Bar {
12-
A, B
12+
A,
13+
B,
1314
}
1415

1516
#[repr(u8)]
1617
enum Boo {
17-
A, B
18+
A,
19+
B,
1820
}
1921

2022
#[repr(i16)]
2123
enum Far {
22-
A, B
24+
A,
25+
B,
2326
}
2427

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

4144
// EMIT_MIR enum_cast.droppy.built.after.mir
4245
enum Droppy {
43-
A, B, C
46+
A,
47+
B,
48+
C,
4449
}
4550

4651
impl Drop for Droppy {
@@ -82,12 +87,15 @@ fn unsigny(x: UnsignedAroundZero) -> u16 {
8287
x as u16
8388
}
8489

85-
enum NotStartingAtZero { A = 4, B = 6, C = 8 }
90+
enum NotStartingAtZero {
91+
A = 4,
92+
B = 6,
93+
C = 8,
94+
}
8695

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

92-
fn main() {
93-
}
101+
fn main() {}

tests/mir-opt/building/logical_or_in_conditional.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ fn test_or() {
3030

3131
// EMIT_MIR logical_or_in_conditional.test_complex.built.after.mir
3232
fn test_complex() {
33-
if let E::A(_) = E::f() && ((always_true() && Droppy(0).0 > 0) || Droppy(1).0 > 1) {}
33+
if let E::A(_) = E::f()
34+
&& ((always_true() && Droppy(0).0 > 0) || Droppy(1).0 > 1)
35+
{}
3436

35-
if !always_true() && let E::B = E::f() {}
37+
if !always_true()
38+
&& let E::B = E::f()
39+
{}
3640
}
3741

3842
fn main() {

tests/mir-opt/building/match/simple_match.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// skip-filecheck
22
// Test that we don't generate unnecessarily large MIR for very simple matches
33

4-
54
// EMIT_MIR simple_match.match_bool.built.after.mir
65
fn match_bool(x: bool) -> usize {
76
match x {

tests/mir-opt/building/shifts.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,12 @@
33

44
// EMIT_MIR shifts.shift_signed.built.after.mir
55
fn shift_signed(small: i8, big: u128, a: i8, b: i32, c: i128) -> ([i8; 3], [u128; 3]) {
6-
(
7-
[small >> a, small >> b, small >> c],
8-
[big << a, big << b, big << c],
9-
)
6+
([small >> a, small >> b, small >> c], [big << a, big << b, big << c])
107
}
118

129
// EMIT_MIR shifts.shift_unsigned.built.after.mir
1310
fn shift_unsigned(small: u8, big: i128, a: u8, b: u32, c: u128) -> ([u8; 3], [i128; 3]) {
14-
(
15-
[small >> a, small >> b, small >> c],
16-
[big << a, big << b, big << c],
17-
)
11+
([small >> a, small >> b, small >> c], [big << a, big << b, big << c])
1812
}
1913

20-
fn main() {
21-
}
14+
fn main() {}

tests/mir-opt/building/storage_live_dead_in_statics.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// generate `StorageStart` or `StorageEnd` statements.
44

55
// EMIT_MIR storage_live_dead_in_statics.XXX.built.after.mir
6+
#[rustfmt::skip]
67
static XXX: &'static Foo = &Foo {
78
tup: "hi",
89
data: &[
@@ -20,13 +21,13 @@ static XXX: &'static Foo = &Foo {
2021
(0, 1), (0, 2), (0, 3),
2122
(0, 1), (0, 2), (0, 3),
2223
(0, 1), (0, 2), (0, 3),
23-
]
24+
],
2425
};
2526

2627
#[derive(Debug)]
2728
struct Foo {
2829
tup: &'static str,
29-
data: &'static [(u32, u32)]
30+
data: &'static [(u32, u32)],
3031
}
3132

3233
fn main() {

tests/mir-opt/const_prop/control_flow_simplification.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl<This> NeedsDrop for This {}
1111

1212
// EMIT_MIR control_flow_simplification.hello.GVN.diff
1313
// EMIT_MIR control_flow_simplification.hello.PreCodegen.before.mir
14-
fn hello<T>(){
14+
fn hello<T>() {
1515
if <bool>::NEEDS {
1616
panic!()
1717
}

tests/mir-opt/const_prop/invalid_constant.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
#[derive(Copy, Clone)]
1010
#[repr(u32)]
11-
enum E { A, B, C }
11+
enum E {
12+
A,
13+
B,
14+
C,
15+
}
1216

1317
#[derive(Copy, Clone)]
1418
enum Empty {}
@@ -39,7 +43,5 @@ fn main() {
3943

4044
// A non-UTF-8 string slice. Regression test for #75763 and #78520.
4145
struct Str<const S: &'static str>;
42-
let _non_utf8_str: Str::<{
43-
unsafe { std::mem::transmute::<&[u8], &str>(&[0xC0, 0xC1, 0xF5]) }
44-
}>;
46+
let _non_utf8_str: Str<{ unsafe { std::mem::transmute::<&[u8], &str>(&[0xC0, 0xC1, 0xF5]) } }>;
4547
}

tests/mir-opt/const_prop/offset_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct Delta<T> {
3131
enum Epsilon {
3232
A(u8, u16),
3333
B,
34-
C { c: u32 }
34+
C { c: u32 },
3535
}
3636

3737
enum Zeta<T> {

tests/mir-opt/const_prop/pointer_expose_provenance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ test-mir-pass: GVN
33

44
#[inline(never)]
5-
fn read(_: usize) { }
5+
fn read(_: usize) {}
66

77
// EMIT_MIR pointer_expose_provenance.main.GVN.diff
88
fn main() {

tests/mir-opt/const_prop/scalar_literal_propagation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ fn main() {
1010
}
1111

1212
#[inline(never)]
13-
fn consume(_: u32) { }
13+
fn consume(_: u32) {}

tests/mir-opt/const_prop/switch_int.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
44

55
#[inline(never)]
6-
fn foo(_: i32) { }
6+
fn foo(_: i32) {}
77

88
// EMIT_MIR switch_int.main.GVN.diff
99
// EMIT_MIR switch_int.main.SimplifyConstCondition-after-const-prop.diff

tests/mir-opt/const_prop/transmute.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ pub unsafe fn undef_union_as_integer() -> u32 {
4545
// CHECK-LABEL: fn undef_union_as_integer(
4646
// CHECK: _1 = Union32 {
4747
// CHECK: _0 = move _1 as u32 (Transmute);
48-
union Union32 { value: u32, unit: () }
48+
union Union32 {
49+
value: u32,
50+
unit: (),
51+
}
4952
unsafe { transmute(Union32 { unit: () }) }
5053
}
5154

tests/mir-opt/const_prop/tuple_literal_propagation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ fn main() {
1010
}
1111

1212
#[inline(never)]
13-
fn consume(_: (u32, u32)) { }
13+
fn consume(_: (u32, u32)) {}

tests/mir-opt/copy-prop/borrowed_local.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#![feature(custom_mir, core_intrinsics, freeze)]
55
#![allow(unused_assignments)]
66
extern crate core;
7-
use core::marker::Freeze;
87
use core::intrinsics::mir::*;
8+
use core::marker::Freeze;
99

10-
fn opaque(_: impl Sized) -> bool { true }
10+
fn opaque(_: impl Sized) -> bool {
11+
true
12+
}
1113

1214
fn cmp_ref(a: &u8, b: &u8) -> bool {
1315
std::ptr::eq(a as *const u8, b as *const u8)

tests/mir-opt/copy-prop/move_projection.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
extern crate core;
88
use core::intrinsics::mir::*;
99

10-
fn opaque(_: impl Sized) -> bool { true }
10+
fn opaque(_: impl Sized) -> bool {
11+
true
12+
}
1113

1214
struct Foo(u8);
1315

tests/mir-opt/dataflow-const-prop/enum.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::intrinsics::mir::*;
88
#[derive(Copy, Clone)]
99
enum E {
1010
V1(i32),
11-
V2(i32)
11+
V2(i32),
1212
}
1313

1414
// EMIT_MIR enum.simple.DataflowConstProp.diff
@@ -23,7 +23,10 @@ fn simple() {
2323
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb2, otherwise: bb1];
2424
// CHECK: [[target_bb]]: {
2525
// CHECK: [[x]] = const 0_i32;
26-
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
26+
let x = match e {
27+
E::V1(x1) => x1,
28+
E::V2(x2) => x2,
29+
};
2730
}
2831

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

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

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

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

7890
#[rustc_layout_scalar_valid_range_start(1)]
@@ -132,7 +144,10 @@ fn multiple(x: bool, i: u8) {
132144
// CHECK: [[x2]] = const 0_u8;
133145
// CHECK: [[some:_.*]] = (({{_.*}} as Some).0: u8)
134146
// CHECK: [[x2]] = [[some]];
135-
let x2 = match e { Some(i) => i, None => 0 };
147+
let x2 = match e {
148+
Some(i) => i,
149+
None => 0,
150+
};
136151

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

tests/mir-opt/dataflow-const-prop/mult_by_zero.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
// EMIT_MIR mult_by_zero.test.DataflowConstProp.diff
44
// CHECK-LABEL: fn test(
5-
fn test(x : i32) -> i32 {
6-
x * 0
7-
// CHECK: _0 = const 0_i32;
5+
fn test(x: i32) -> i32 {
6+
x * 0
7+
// CHECK: _0 = const 0_i32;
88
}
99

1010
fn main() {

tests/mir-opt/dataflow-const-prop/transmute.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ pub unsafe fn undef_union_as_integer() -> u32 {
4545
// CHECK-LABEL: fn undef_union_as_integer(
4646
// CHECK: _1 = Union32 {
4747
// CHECK: _0 = move _1 as u32 (Transmute);
48-
union Union32 { value: u32, unit: () }
48+
union Union32 {
49+
value: u32,
50+
unit: (),
51+
}
4952
unsafe { transmute(Union32 { unit: () }) }
5053
}
5154

tests/mir-opt/derefer_complex_case.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
55

66
fn main() {
7-
for &foo in &[42, 43] { drop(foo) }
7+
for &foo in &[42, 43] {
8+
drop(foo)
9+
}
810
}

0 commit comments

Comments
 (0)