about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-06-01 00:09:20 -0400
committerGitHub <noreply@github.com>2017-06-01 00:09:20 -0400
commitdbc9d71b179bfe7e25704c17a574b8f579d3f776 (patch)
tree53da0dbc76d8f47915489c77401a362174ea5cbd /src/test
parent422faf7a6fbedd75653f1568e69858f62b5c0fe7 (diff)
parent3119e634e178d8acaed4a2d4a9d52e3b76ae79cf (diff)
downloadrust-dbc9d71b179bfe7e25704c17a574b8f579d3f776.tar.gz
rust-dbc9d71b179bfe7e25704c17a574b8f579d3f776.zip
Rollup merge of #42275 - scottmcm:try-trait, r=nikomatsakis
Lower `?` to `Try` instead of `Carrier`

The easy parts of https://github.com/rust-lang/rfcs/pull/1859, whose FCP completed without further comments.

Just the trait and the lowering -- neither the error message improvements nor the insta-stable impl for Option nor exhaustive docs.

Based on a [github search](https://github.com/search?l=rust&p=1&q=question_mark_carrier&type=Code&utf8=%E2%9C%93), this will break the following:

- https://github.com/pfpacket/rust-9p/blob/00206e34c680198a0ac7c2f066cc2954187d4fac/src/serialize.rs#L38
- https://github.com/peterdelevoryas/bufparse/blob/b1325898f4fc2c67658049196c12da82548af350/src/result.rs#L50

The other results appear to be files from libcore or its tests.  I could also leave Carrier around after stage0 and `impl<T:Carrier> Try for T` if that would be better.

r? @nikomatsakis

Edit: Oh, and it might accidentally improve perf, based on https://github.com/rust-lang/rust/issues/37939#issuecomment-265803670, since `Try::into_result` for `Result` is an obvious no-op, unlike `Carrier::translate`.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/try-operator-custom.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/test/run-pass/try-operator-custom.rs b/src/test/run-pass/try-operator-custom.rs
index 577d19a5896..82ba70c9459 100644
--- a/src/test/run-pass/try-operator-custom.rs
+++ b/src/test/run-pass/try-operator-custom.rs
@@ -8,20 +8,20 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(question_mark, question_mark_carrier)]
+#![feature(try_trait)]
 
-use std::ops::Carrier;
+use std::ops::Try;
 
 enum MyResult<T, U> {
     Awesome(T),
     Terrible(U)
 }
 
-impl<U, V> Carrier for MyResult<U, V> {
-    type Success = U;
+impl<U, V> Try for MyResult<U, V> {
+    type Ok = U;
     type Error = V;
 
-    fn from_success(u: U) -> MyResult<U, V> {
+    fn from_ok(u: U) -> MyResult<U, V> {
         MyResult::Awesome(u)
     }
 
@@ -29,12 +29,10 @@ impl<U, V> Carrier for MyResult<U, V> {
         MyResult::Terrible(e)
     }
 
-    fn translate<T>(self) -> T
-        where T: Carrier<Success=U, Error=V>
-    {
+    fn into_result(self) -> Result<U, V> {
         match self {
-            MyResult::Awesome(u) => T::from_success(u),
-            MyResult::Terrible(e) => T::from_error(e),
+            MyResult::Awesome(u) => Ok(u),
+            MyResult::Terrible(e) => Err(e),
         }
     }
 }