about summary refs log tree commit diff
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2021-04-15 01:13:39 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2021-05-06 11:37:45 -0700
commit266a72637a5bb79eeaaa741950a6f9501bfd2f8d (patch)
tree55e401fe397d04fa072069ff719dc6588daef3db
parentca92b5a23a9bb30a0741e9969e73d838eeba1ad1 (diff)
downloadrust-266a72637a5bb79eeaaa741950a6f9501bfd2f8d.tar.gz
rust-266a72637a5bb79eeaaa741950a6f9501bfd2f8d.zip
Simple library test updates
-rw-r--r--library/core/src/ops/try_trait.rs20
-rw-r--r--library/core/tests/lib.rs1
-rw-r--r--library/core/tests/option.rs12
-rw-r--r--library/core/tests/result.rs30
4 files changed, 24 insertions, 39 deletions
diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs
index 52a76081947..80a5800bcbb 100644
--- a/library/core/src/ops/try_trait.rs
+++ b/library/core/src/ops/try_trait.rs
@@ -41,8 +41,7 @@ use crate::ops::ControlFlow;
 /// output type that we want:
 /// ```
 /// # #![feature(try_trait_v2)]
-/// # #![feature(try_trait_transition)]
-/// # use std::ops::TryV2 as Try;
+/// # use std::ops::Try;
 /// fn simple_try_fold_1<A, T, R: Try<Output = A>>(
 ///     iter: impl Iterator<Item = T>,
 ///     mut accum: A,
@@ -56,9 +55,8 @@ use crate::ops::ControlFlow;
 /// into the return type using [`Try::from_output`]:
 /// ```
 /// # #![feature(try_trait_v2)]
-/// # #![feature(try_trait_transition)]
 /// # #![feature(control_flow_enum)]
-/// # use std::ops::{ControlFlow, TryV2 as Try};
+/// # use std::ops::{ControlFlow, Try};
 /// fn simple_try_fold_2<A, T, R: Try<Output = A>>(
 ///     iter: impl Iterator<Item = T>,
 ///     mut accum: A,
@@ -81,9 +79,8 @@ use crate::ops::ControlFlow;
 /// recreated from their corresponding residual, so we'll just call it:
 /// ```
 /// # #![feature(try_trait_v2)]
-/// # #![feature(try_trait_transition)]
 /// # #![feature(control_flow_enum)]
-/// # use std::ops::{ControlFlow, TryV2 as Try};
+/// # use std::ops::{ControlFlow, Try};
 /// pub fn simple_try_fold_3<A, T, R: Try<Output = A>>(
 ///     iter: impl Iterator<Item = T>,
 ///     mut accum: A,
@@ -103,10 +100,9 @@ use crate::ops::ControlFlow;
 /// But this "call `branch`, then `match` on it, and `return` if it was a
 /// `Break`" is exactly what happens inside the `?` operator.  So rather than
 /// do all this manually, we can just use `?` instead:
-/// ```compile_fail (enable again once ? converts to the new trait)
+/// ```
 /// # #![feature(try_trait_v2)]
-/// # #![feature(try_trait_transition)]
-/// # use std::ops::TryV2 as Try;
+/// # use std::ops::Try;
 /// fn simple_try_fold<A, T, R: Try<Output = A>>(
 ///     iter: impl Iterator<Item = T>,
 ///     mut accum: A,
@@ -160,8 +156,7 @@ pub trait Try: FromResidual {
     /// ```
     /// #![feature(try_trait_v2)]
     /// #![feature(control_flow_enum)]
-    /// #![feature(try_trait_transition)]
-    /// use std::ops::TryV2 as Try;
+    /// use std::ops::Try;
     ///
     /// assert_eq!(<Result<_, String> as Try>::from_output(3), Ok(3));
     /// assert_eq!(<Option<_> as Try>::from_output(4), Some(4));
@@ -193,8 +188,7 @@ pub trait Try: FromResidual {
     /// ```
     /// #![feature(try_trait_v2)]
     /// #![feature(control_flow_enum)]
-    /// #![feature(try_trait_transition)]
-    /// use std::ops::{ControlFlow, TryV2 as Try};
+    /// use std::ops::{ControlFlow, Try};
     ///
     /// assert_eq!(Ok::<_, String>(3).branch(), ControlFlow::Continue(3));
     /// assert_eq!(Err::<String, _>(3).branch(), ControlFlow::Break(Err(3)));
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 35e4d213dde..db12d79c00c 100644
--- a/library/core/tests/lib.rs
+++ b/library/core/tests/lib.rs
@@ -45,6 +45,7 @@
 #![feature(test)]
 #![feature(trusted_len)]
 #![feature(try_trait)]
+#![feature(try_trait_v2)]
 #![feature(slice_internals)]
 #![feature(slice_partition_dedup)]
 #![feature(int_error_matching)]
diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs
index 9470451278c..88ea15a3b33 100644
--- a/library/core/tests/option.rs
+++ b/library/core/tests/option.rs
@@ -301,18 +301,6 @@ fn test_try() {
         Some(val)
     }
     assert_eq!(try_option_none(), None);
-
-    fn try_option_ok() -> Result<u8, NoneError> {
-        let val = Some(1)?;
-        Ok(val)
-    }
-    assert_eq!(try_option_ok(), Ok(1));
-
-    fn try_option_err() -> Result<u8, NoneError> {
-        let val = None?;
-        Ok(val)
-    }
-    assert_eq!(try_option_err(), Err(NoneError));
 }
 
 #[test]
diff --git a/library/core/tests/result.rs b/library/core/tests/result.rs
index c461ab380ad..f4e5e7751b8 100644
--- a/library/core/tests/result.rs
+++ b/library/core/tests/result.rs
@@ -249,26 +249,14 @@ pub fn test_into_err() {
 
 #[test]
 fn test_try() {
-    fn try_result_some() -> Option<u8> {
-        let val = Ok(1)?;
-        Some(val)
-    }
-    assert_eq!(try_result_some(), Some(1));
-
-    fn try_result_none() -> Option<u8> {
-        let val = Err(NoneError)?;
-        Some(val)
-    }
-    assert_eq!(try_result_none(), None);
-
-    fn try_result_ok() -> Result<u8, u8> {
+    fn try_result_ok() -> Result<u8, u32> {
         let result: Result<u8, u8> = Ok(1);
         let val = result?;
         Ok(val)
     }
     assert_eq!(try_result_ok(), Ok(1));
 
-    fn try_result_err() -> Result<u8, u8> {
+    fn try_result_err() -> Result<u8, u32> {
         let result: Result<u8, u8> = Err(1);
         let val = result?;
         Ok(val)
@@ -401,3 +389,17 @@ fn result_opt_conversions() {
 
     assert_eq!(res, Err(BadNumErr))
 }
+
+#[test]
+#[cfg(not(bootstrap))] // Needs the V2 trait
+fn result_try_trait_v2_branch() {
+    use core::num::NonZeroU32;
+    use core::ops::{ControlFlow::*, Try};
+    assert_eq!(Ok::<i32, i32>(4).branch(), Continue(4));
+    assert_eq!(Err::<i32, i32>(4).branch(), Break(Err(4)));
+    let one = NonZeroU32::new(1).unwrap();
+    assert_eq!(Ok::<(), NonZeroU32>(()).branch(), Continue(()));
+    assert_eq!(Err::<(), NonZeroU32>(one).branch(), Break(Err(one)));
+    assert_eq!(Ok::<NonZeroU32, ()>(one).branch(), Continue(one));
+    assert_eq!(Err::<NonZeroU32, ()>(()).branch(), Break(Err(())));
+}