Skip to content

Commit 47b9948

Browse files
committed
mir-opt & codegen test updates
`SimplifyArm` and such are currently in `-Zunsound-mir-opts` and thus weren't running by default, so having something like them for the new desugar shouldn't be necessary for switching.
1 parent 266a726 commit 47b9948

10 files changed

+349
-346
lines changed

src/test/codegen/try_identity.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,28 @@
77

88
type R = Result<u64, i32>;
99

10+
// This was written to the `?` from `try_trait`,
11+
// but `try_trait_v2` uses a different structure,
12+
// so the relevant desugar is copied inline
13+
// in order to keep the test testing the same thing.
1014
#[no_mangle]
11-
fn try_identity(x: R) -> R {
15+
pub fn try_identity(x: R) -> R {
1216
// CHECK: start:
1317
// CHECK-NOT: br {{.*}}
1418
// CHECK ret void
15-
let y = x?;
19+
let y = match into_result(x) {
20+
Err(e) => return from_error(From::from(e)),
21+
Ok(v) => v,
22+
};
1623
Ok(y)
1724
}
25+
26+
#[inline]
27+
fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> {
28+
r
29+
}
30+
31+
#[inline]
32+
fn from_error<T, E>(e: E) -> Result<T, E> {
33+
Err(e)
34+
}

src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ fn test() -> Option<Box<u32>> {
44
let mut _0: std::option::Option<std::boxed::Box<u32>>; // return place in scope 0 at $DIR/issue-62289.rs:8:14: 8:30
55
let mut _1: std::boxed::Box<u32>; // in scope 0 at $DIR/issue-62289.rs:9:10: 9:21
66
let mut _2: std::boxed::Box<u32>; // in scope 0 at $DIR/issue-62289.rs:9:10: 9:21
7-
let mut _3: std::result::Result<u32, std::option::NoneError>; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:20
7+
let mut _3: std::ops::ControlFlow<std::option::Option<std::convert::Infallible>, u32>; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:20
88
let mut _4: std::option::Option<u32>; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:19
99
let mut _5: isize; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
10-
let _6: std::option::NoneError; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
10+
let _6: std::option::Option<std::convert::Infallible>; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
1111
let mut _7: !; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
12-
let mut _8: std::option::NoneError; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
13-
let mut _9: std::option::NoneError; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
14-
let _10: u32; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:20
12+
let mut _8: std::option::Option<std::convert::Infallible>; // in scope 0 at $DIR/issue-62289.rs:9:19: 9:20
13+
let _9: u32; // in scope 0 at $DIR/issue-62289.rs:9:15: 9:20
1514
scope 1 {
16-
debug err => _6; // in scope 1 at $DIR/issue-62289.rs:9:19: 9:20
15+
debug residual => _6; // in scope 1 at $DIR/issue-62289.rs:9:19: 9:20
1716
scope 2 {
1817
}
1918
}
2019
scope 3 {
21-
debug val => _10; // in scope 3 at $DIR/issue-62289.rs:9:15: 9:20
20+
debug val => _9; // in scope 3 at $DIR/issue-62289.rs:9:15: 9:20
2221
scope 4 {
2322
}
2423
}
@@ -30,10 +29,10 @@ fn test() -> Option<Box<u32>> {
3029
StorageLive(_3); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
3130
StorageLive(_4); // scope 0 at $DIR/issue-62289.rs:9:15: 9:19
3231
_4 = Option::<u32>::None; // scope 0 at $DIR/issue-62289.rs:9:15: 9:19
33-
_3 = <Option<u32> as Try>::into_result(move _4) -> [return: bb1, unwind: bb12]; // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
32+
_3 = <Option<u32> as Try>::branch(move _4) -> [return: bb1, unwind: bb11]; // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
3433
// mir::Constant
3534
// + span: $DIR/issue-62289.rs:9:15: 9:20
36-
// + literal: Const { ty: fn(std::option::Option<u32>) -> std::result::Result<<std::option::Option<u32> as std::ops::Try>::Ok, <std::option::Option<u32> as std::ops::Try>::Error> {<std::option::Option<u32> as std::ops::Try>::into_result}, val: Value(Scalar(<ZST>)) }
35+
// + literal: Const { ty: fn(std::option::Option<u32>) -> std::ops::ControlFlow<<std::option::Option<u32> as std::ops::Try>::Residual, <std::option::Option<u32> as std::ops::Try>::Output> {<std::option::Option<u32> as std::ops::Try>::branch}, val: Value(Scalar(<ZST>)) }
3736
}
3837

3938
bb1: {
@@ -43,12 +42,12 @@ fn test() -> Option<Box<u32>> {
4342
}
4443

4544
bb2: {
46-
StorageLive(_10); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
47-
_10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
48-
(*_2) = _10; // scope 4 at $DIR/issue-62289.rs:9:15: 9:20
49-
StorageDead(_10); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
45+
StorageLive(_9); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
46+
_9 = ((_3 as Continue).0: u32); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20
47+
(*_2) = _9; // scope 4 at $DIR/issue-62289.rs:9:15: 9:20
48+
StorageDead(_9); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
5049
_1 = move _2; // scope 0 at $DIR/issue-62289.rs:9:10: 9:21
51-
drop(_2) -> [return: bb7, unwind: bb11]; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
50+
drop(_2) -> [return: bb6, unwind: bb10]; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
5251
}
5352

5453
bb3: {
@@ -57,62 +56,53 @@ fn test() -> Option<Box<u32>> {
5756

5857
bb4: {
5958
StorageLive(_6); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
60-
_6 = ((_3 as Err).0: std::option::NoneError); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
59+
_6 = ((_3 as Break).0: std::option::Option<std::convert::Infallible>); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
6160
StorageLive(_8); // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
62-
StorageLive(_9); // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
63-
_9 = _6; // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
64-
_8 = <NoneError as From<NoneError>>::from(move _9) -> [return: bb5, unwind: bb12]; // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
61+
_8 = _6; // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
62+
_0 = <Option<Box<u32>> as FromResidual<Option<Infallible>>>::from_residual(move _8) -> [return: bb5, unwind: bb11]; // scope 2 at $DIR/issue-62289.rs:9:15: 9:20
6563
// mir::Constant
6664
// + span: $DIR/issue-62289.rs:9:19: 9:20
67-
// + literal: Const { ty: fn(std::option::NoneError) -> std::option::NoneError {<std::option::NoneError as std::convert::From<std::option::NoneError>>::from}, val: Value(Scalar(<ZST>)) }
65+
// + literal: Const { ty: fn(std::option::Option<std::convert::Infallible>) -> std::option::Option<std::boxed::Box<u32>> {<std::option::Option<std::boxed::Box<u32>> as std::ops::FromResidual<std::option::Option<std::convert::Infallible>>>::from_residual}, val: Value(Scalar(<ZST>)) }
6866
}
6967

7068
bb5: {
71-
StorageDead(_9); // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
72-
_0 = <Option<Box<u32>> as Try>::from_error(move _8) -> [return: bb6, unwind: bb12]; // scope 2 at $DIR/issue-62289.rs:9:15: 9:20
73-
// mir::Constant
74-
// + span: $DIR/issue-62289.rs:9:15: 9:20
75-
// + literal: Const { ty: fn(<std::option::Option<std::boxed::Box<u32>> as std::ops::Try>::Error) -> std::option::Option<std::boxed::Box<u32>> {<std::option::Option<std::boxed::Box<u32>> as std::ops::Try>::from_error}, val: Value(Scalar(<ZST>)) }
76-
}
77-
78-
bb6: {
7969
StorageDead(_8); // scope 2 at $DIR/issue-62289.rs:9:19: 9:20
8070
StorageDead(_6); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20
81-
drop(_2) -> bb9; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
71+
drop(_2) -> bb8; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
8272
}
8373

84-
bb7: {
74+
bb6: {
8575
StorageDead(_2); // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
8676
_0 = Option::<Box<u32>>::Some(move _1); // scope 0 at $DIR/issue-62289.rs:9:5: 9:22
87-
drop(_1) -> bb8; // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
77+
drop(_1) -> bb7; // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
8878
}
8979

90-
bb8: {
80+
bb7: {
9181
StorageDead(_1); // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
9282
StorageDead(_3); // scope 0 at $DIR/issue-62289.rs:10:1: 10:2
93-
goto -> bb10; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
83+
goto -> bb9; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
9484
}
9585

96-
bb9: {
86+
bb8: {
9787
StorageDead(_2); // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
9888
StorageDead(_1); // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
9989
StorageDead(_3); // scope 0 at $DIR/issue-62289.rs:10:1: 10:2
100-
goto -> bb10; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
90+
goto -> bb9; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
10191
}
10292

103-
bb10: {
93+
bb9: {
10494
return; // scope 0 at $DIR/issue-62289.rs:10:2: 10:2
10595
}
10696

107-
bb11 (cleanup): {
108-
drop(_1) -> bb13; // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
97+
bb10 (cleanup): {
98+
drop(_1) -> bb12; // scope 0 at $DIR/issue-62289.rs:9:21: 9:22
10999
}
110100

111-
bb12 (cleanup): {
112-
drop(_2) -> bb13; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
101+
bb11 (cleanup): {
102+
drop(_2) -> bb12; // scope 0 at $DIR/issue-62289.rs:9:20: 9:21
113103
}
114104

115-
bb13 (cleanup): {
105+
bb12 (cleanup): {
116106
resume; // scope 0 at $DIR/issue-62289.rs:8:1: 10:2
117107
}
118108
}

src/test/mir-opt/simplify-arm.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,23 @@ fn id_result(r: Result<u8, i32>) -> Result<u8, i32> {
2020
}
2121
}
2222

23+
fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> {
24+
r
25+
}
26+
27+
fn from_error<T, E>(e: E) -> Result<T, E> {
28+
Err(e)
29+
}
30+
31+
// This was written to the `?` from `try_trait`,
32+
// but `try_trait_v2` uses a different structure,
33+
// so the relevant desugar is copied inline
34+
// in order to keep the test testing the same thing.
2335
fn id_try(r: Result<u8, i32>) -> Result<u8, i32> {
24-
let x = r?;
36+
let x = match into_result(r) {
37+
Err(e) => return from_error(From::from(e)),
38+
Ok(v) => v,
39+
};
2540
Ok(x)
2641
}
2742

0 commit comments

Comments
 (0)