about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-05-18 20:50:01 +0000
committerbors <bors@rust-lang.org>2021-05-18 20:50:01 +0000
commit4e3e6db011c5b482d2bef8ba02274657f93b5e0d (patch)
tree18c4d91304ab931792236935417dfe51ad998a7a /src/test/codegen
parent491cf5561efb1f5ff33c3234ccd0bc5cacbebe3e (diff)
parente2edee4da07032de72ac930df1453780dbe73f3b (diff)
downloadrust-4e3e6db011c5b482d2bef8ba02274657f93b5e0d.tar.gz
rust-4e3e6db011c5b482d2bef8ba02274657f93b5e0d.zip
Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnr
Implement the new desugaring from `try_trait_v2`

~~Currently blocked on https://github.com/rust-lang/rust/issues/84782, which has a PR in https://github.com/rust-lang/rust/pull/84811~~ Rebased atop that fix.

`try_trait_v2` tracking issue: https://github.com/rust-lang/rust/issues/84277

Unfortunately this is already touching a ton of things, so if you have suggestions for good ways to split it up, I'd be happy to hear them.  (The combination between the use in the library, the compiler changes, the corresponding diagnostic differences, even MIR tests mean that I don't really have a great plan for it other than trying to have decently-readable commits.

r? `@ghost`

~~(This probably shouldn't go in during the last week before the fork anyway.)~~ Fork happened.
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/try_identity.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/test/codegen/try_identity.rs b/src/test/codegen/try_identity.rs
index 81e2435e5b8..3ff77163b9f 100644
--- a/src/test/codegen/try_identity.rs
+++ b/src/test/codegen/try_identity.rs
@@ -7,11 +7,28 @@
 
 type R = Result<u64, i32>;
 
+// 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.
+// 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.
 #[no_mangle]
-fn try_identity(x: R) -> R {
+pub fn try_identity(x: R) -> R {
 // CHECK: start:
 // CHECK-NOT: br {{.*}}
 // CHECK ret void
-    let y = x?;
+    let y = match into_result(x) {
+        Err(e) => return from_error(From::from(e)),
+        Ok(v) => v,
+    };
     Ok(y)
 }
+
+#[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)
+}