Commit 7c34d8d
committed
Auto merge of rust-lang#69756 - wesleywiser:simplify_try, r=oli-obk
Modify SimplifyArmIdentity so it can trigger on mir-opt-level=1
I also added test cases to make sure the optimization can fire on all of
these cases:
```rust
fn case_1(o: Option<u8>) -> Option<u8> {
match o {
Some(u) => Some(u),
None => None,
}
}
fn case2(r: Result<u8, i32>) -> Result<u8, i32> {
match r {
Ok(u) => Ok(u),
Err(i) => Err(i),
}
}
fn case3(r: Result<u8, i32>) -> Result<u8, i32> {
let u = r?;
Ok(u)
}
```
Without MIR inlining, this still does not completely optimize away the
`?` operator because the `Try::into_result()`, `From::from()` and
`Try::from_error()` calls still exist. This does move us a bit closer to
that goal though because:
- We can now run the pass on mir-opt-level=1
- We no longer depend on the copy propagation pass running which is
unlikely to stabilize anytime soon.
Fixes rust-lang#66855File tree
16 files changed
+1032
-73
lines changed- src
- librustc_mir/transform
- test/mir-opt
- simplify-arm-identity
- 32bit
- 64bit
- simplify-arm
- simplify_try_if_let
- simplify_try
16 files changed
+1032
-73
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| 320 | + | |
| 321 | + | |
320 | 322 | | |
321 | 323 | | |
322 | 324 | | |
323 | 325 | | |
324 | | - | |
325 | | - | |
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
| |||
0 commit comments