2021-03-04 13:35:11 +00:00
|
|
|
// compile-flags: -C no-prepopulate-passes -O -Z mir-opt-level=3 -Zunsound-mir-opts
|
2019-11-10 09:26:33 +00:00
|
|
|
|
|
|
|
// Ensure that `x?` has no overhead on `Result<T, E>` due to identity `match`es in lowering.
|
|
|
|
// This requires inlining to trigger the MIR optimizations in `SimplifyArmIdentity`.
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
|
|
|
type R = Result<u64, i32>;
|
|
|
|
|
2021-05-10 05:05:02 +00:00
|
|
|
// This was written to the `?` from `try_trait`, but `try_trait_v2` uses a different structure,
|
|
|
|
// so the relevant desugar is copied inline in order to keep the test testing the same thing.
|
2021-05-18 18:48:00 +00:00
|
|
|
// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR
|
|
|
|
// optimization that picks up the `?` desugaring, as `SimplifyArmIdentity` does not.
|
2019-11-10 09:26:33 +00:00
|
|
|
#[no_mangle]
|
2021-04-26 05:02:48 +00:00
|
|
|
pub fn try_identity(x: R) -> R {
|
2019-11-10 09:26:33 +00:00
|
|
|
// CHECK: start:
|
2022-04-05 23:02:57 +00:00
|
|
|
// FIXME(JakobDegen): Broken by deaggregation change CHECK-NOT\: br {{.*}}
|
2019-11-10 09:26:33 +00:00
|
|
|
// CHECK ret void
|
2021-04-26 05:02:48 +00:00
|
|
|
let y = match into_result(x) {
|
|
|
|
Err(e) => return from_error(From::from(e)),
|
|
|
|
Ok(v) => v,
|
|
|
|
};
|
2019-11-10 09:26:33 +00:00
|
|
|
Ok(y)
|
|
|
|
}
|
2021-04-26 05:02:48 +00:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> {
|
|
|
|
r
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn from_error<T, E>(e: E) -> Result<T, E> {
|
|
|
|
Err(e)
|
|
|
|
}
|