From 508ed8d21e6cbfd8e94f7e92e6c6a6a107f9b19f Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 20 Feb 2021 02:37:17 -0800 Subject: [PATCH] Remove the option-to-result back-compat hack --- library/core/src/result.rs | 25 ------------------- src/test/ui/option-to-result.rs | 2 +- src/test/ui/option-to-result.stderr | 17 +++++++------ src/test/ui/try-block/try-block-bad-type.rs | 4 +-- .../ui/try-block/try-block-bad-type.stderr | 12 ++++----- .../try-on-option-in-result-method.rs | 20 --------------- src/test/ui/try-trait/try-on-option.rs | 2 +- src/test/ui/try-trait/try-on-option.stderr | 17 +++++++------ 8 files changed, 28 insertions(+), 71 deletions(-) delete mode 100644 src/test/ui/try-trait/try-on-option-in-result-method.rs diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 6ee5c25e6649b..380cf7e6b2024 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1650,28 +1650,3 @@ impl> ops::FromResidual> for Result { } } } - -mod sadness { - use super::*; - - /// This is a remnant of the old `NoneError` which is never going to be stabilized. - /// It's here as a snapshot of an oversight that allowed this to work in the past, - /// so we're stuck supporting it even though we'd really rather not. - #[unstable(feature = "legacy_try_trait", issue = "none")] - #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] - pub struct PleaseCallTheOkOrMethodToUseQuestionMarkOnOptionsInAMethodThatReturnsResult; - - #[unstable(feature = "try_trait_v2", issue = "42327")] - impl ops::FromResidual> for Result - where - E: From, - { - fn from_residual(x: Option) -> Self { - match x { - None => Err(From::from( - PleaseCallTheOkOrMethodToUseQuestionMarkOnOptionsInAMethodThatReturnsResult, - )), - } - } - } -} diff --git a/src/test/ui/option-to-result.rs b/src/test/ui/option-to-result.rs index 935a96b7df958..598bab495bda5 100644 --- a/src/test/ui/option-to-result.rs +++ b/src/test/ui/option-to-result.rs @@ -2,7 +2,7 @@ fn main(){ } fn test_result() -> Result<(),()> { let a:Option<()> = Some(()); - a?;//~ ERROR `?` couldn't convert the error to `()` + a?;//~ ERROR the `?` operator can only be used in a function that returns `Result` or `Option` Ok(()) } diff --git a/src/test/ui/option-to-result.stderr b/src/test/ui/option-to-result.stderr index e616ab1dca302..1c5537c358280 100644 --- a/src/test/ui/option-to-result.stderr +++ b/src/test/ui/option-to-result.stderr @@ -1,14 +1,15 @@ -error[E0277]: `?` couldn't convert the error to `()` +error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) --> $DIR/option-to-result.rs:5:5 | -LL | fn test_result() -> Result<(),()> { - | ------------- expected `()` because of this -LL | let a:Option<()> = Some(()); -LL | a?; - | ^^ the trait `From` is not implemented for `()` +LL | / fn test_result() -> Result<(),()> { +LL | | let a:Option<()> = Some(()); +LL | | a?; + | | ^^ cannot use the `?` operator in a function that returns `Result<(), ()>` +LL | | Ok(()) +LL | | } + | |_- this function should return `Result` or `Option` to accept `?` | - = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait - = note: required because of the requirements on the impl of `FromResidual>` for `Result<(), ()>` + = help: the trait `FromResidual>` is not implemented for `Result<(), ()>` = note: required by `from_residual` error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) diff --git a/src/test/ui/try-block/try-block-bad-type.rs b/src/test/ui/try-block/try-block-bad-type.rs index 97680eaf2e36e..eeaf16b7f9b81 100644 --- a/src/test/ui/try-block/try-block-bad-type.rs +++ b/src/test/ui/try-block/try-block-bad-type.rs @@ -15,7 +15,7 @@ pub fn main() { let res: Result = try { }; //~ ERROR type mismatch let res: () = try { }; - //~^ ERROR the trait bound `(): Try` is not satisfied + //~^ ERROR the trait bound `(): Try2021` is not satisfied - let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: Try` is not satisfied + let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: Try2021` is not satisfied } diff --git a/src/test/ui/try-block/try-block-bad-type.stderr b/src/test/ui/try-block/try-block-bad-type.stderr index f5e99a80039f3..9ae108e6fcab6 100644 --- a/src/test/ui/try-block/try-block-bad-type.stderr +++ b/src/test/ui/try-block/try-block-bad-type.stderr @@ -10,31 +10,31 @@ LL | Err("")?; = note: required because of the requirements on the impl of `FromResidual>` for `Result` = note: required by `from_residual` -error[E0271]: type mismatch resolving ` as Try>::Ok == &str` +error[E0271]: type mismatch resolving ` as Try2021>::Ok == &str` --> $DIR/try-block-bad-type.rs:12:9 | LL | "" | ^^ expected `i32`, found `&str` -error[E0271]: type mismatch resolving ` as Try>::Ok == ()` +error[E0271]: type mismatch resolving ` as Try2021>::Ok == ()` --> $DIR/try-block-bad-type.rs:15:39 | LL | let res: Result = try { }; | ^ expected `i32`, found `()` -error[E0277]: the trait bound `(): Try` is not satisfied +error[E0277]: the trait bound `(): Try2021` is not satisfied --> $DIR/try-block-bad-type.rs:17:25 | LL | let res: () = try { }; - | ^ the trait `Try` is not implemented for `()` + | ^ the trait `Try2021` is not implemented for `()` | = note: required by `from_output` -error[E0277]: the trait bound `i32: Try` is not satisfied +error[E0277]: the trait bound `i32: Try2021` is not satisfied --> $DIR/try-block-bad-type.rs:20:26 | LL | let res: i32 = try { 5 }; - | ^ the trait `Try` is not implemented for `i32` + | ^ the trait `Try2021` is not implemented for `i32` | = note: required by `from_output` diff --git a/src/test/ui/try-trait/try-on-option-in-result-method.rs b/src/test/ui/try-trait/try-on-option-in-result-method.rs deleted file mode 100644 index fe50d9bccb4f5..0000000000000 --- a/src/test/ui/try-trait/try-on-option-in-result-method.rs +++ /dev/null @@ -1,20 +0,0 @@ -// check-pass - -#![allow(dead_code, unused)] - -///! This isn't supposed to work, but it accidentally did, so unfortunately we need to support this. - -struct Tricky; - -impl From for Tricky { - fn from(_: T) -> Tricky { Tricky } -} - -fn foo() -> Result<(), Tricky> { - None?; - Ok(()) -} - -fn main() { - assert!(matches!(foo(), Err(Tricky))); -} diff --git a/src/test/ui/try-trait/try-on-option.rs b/src/test/ui/try-trait/try-on-option.rs index a662bbd35fbce..f2012936a1174 100644 --- a/src/test/ui/try-trait/try-on-option.rs +++ b/src/test/ui/try-trait/try-on-option.rs @@ -4,7 +4,7 @@ fn main() {} fn foo() -> Result { let x: Option = None; - x?; //~ ERROR `?` couldn't convert the error to `()` + x?; //~ ERROR the `?` operator Ok(22) } diff --git a/src/test/ui/try-trait/try-on-option.stderr b/src/test/ui/try-trait/try-on-option.stderr index d90eb3bdb0b62..d3a538e18a752 100644 --- a/src/test/ui/try-trait/try-on-option.stderr +++ b/src/test/ui/try-trait/try-on-option.stderr @@ -1,14 +1,15 @@ -error[E0277]: `?` couldn't convert the error to `()` +error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) --> $DIR/try-on-option.rs:7:5 | -LL | fn foo() -> Result { - | --------------- expected `()` because of this -LL | let x: Option = None; -LL | x?; - | ^^ the trait `From` is not implemented for `()` +LL | / fn foo() -> Result { +LL | | let x: Option = None; +LL | | x?; + | | ^^ cannot use the `?` operator in a function that returns `Result` +LL | | Ok(22) +LL | | } + | |_- this function should return `Result` or `Option` to accept `?` | - = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait - = note: required because of the requirements on the impl of `FromResidual>` for `Result` + = help: the trait `FromResidual>` is not implemented for `Result` = note: required by `from_residual` error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)