Skip to content

Commit 508ed8d

Browse files
committed
Remove the option-to-result back-compat hack
1 parent 4a07acb commit 508ed8d

8 files changed

+28
-71
lines changed

library/core/src/result.rs

-25
Original file line numberDiff line numberDiff line change
@@ -1650,28 +1650,3 @@ impl<T, E, F: From<E>> ops::FromResidual<Result<!, E>> for Result<T, F> {
16501650
}
16511651
}
16521652
}
1653-
1654-
mod sadness {
1655-
use super::*;
1656-
1657-
/// This is a remnant of the old `NoneError` which is never going to be stabilized.
1658-
/// It's here as a snapshot of an oversight that allowed this to work in the past,
1659-
/// so we're stuck supporting it even though we'd really rather not.
1660-
#[unstable(feature = "legacy_try_trait", issue = "none")]
1661-
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
1662-
pub struct PleaseCallTheOkOrMethodToUseQuestionMarkOnOptionsInAMethodThatReturnsResult;
1663-
1664-
#[unstable(feature = "try_trait_v2", issue = "42327")]
1665-
impl<T, E> ops::FromResidual<Option<!>> for Result<T, E>
1666-
where
1667-
E: From<PleaseCallTheOkOrMethodToUseQuestionMarkOnOptionsInAMethodThatReturnsResult>,
1668-
{
1669-
fn from_residual(x: Option<!>) -> Self {
1670-
match x {
1671-
None => Err(From::from(
1672-
PleaseCallTheOkOrMethodToUseQuestionMarkOnOptionsInAMethodThatReturnsResult,
1673-
)),
1674-
}
1675-
}
1676-
}
1677-
}

src/test/ui/option-to-result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fn main(){ }
22

33
fn test_result() -> Result<(),()> {
44
let a:Option<()> = Some(());
5-
a?;//~ ERROR `?` couldn't convert the error to `()`
5+
a?;//~ ERROR the `?` operator can only be used in a function that returns `Result` or `Option`
66
Ok(())
77
}
88

src/test/ui/option-to-result.stderr

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
error[E0277]: `?` couldn't convert the error to `()`
1+
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
22
--> $DIR/option-to-result.rs:5:5
33
|
4-
LL | fn test_result() -> Result<(),()> {
5-
| ------------- expected `()` because of this
6-
LL | let a:Option<()> = Some(());
7-
LL | a?;
8-
| ^^ the trait `From<result::sadness::PleaseCallTheOkOrMethodToUseQuestionMarkOnOptionsInAMethodThatReturnsResult>` is not implemented for `()`
4+
LL | / fn test_result() -> Result<(),()> {
5+
LL | | let a:Option<()> = Some(());
6+
LL | | a?;
7+
| | ^^ cannot use the `?` operator in a function that returns `Result<(), ()>`
8+
LL | | Ok(())
9+
LL | | }
10+
| |_- this function should return `Result` or `Option` to accept `?`
911
|
10-
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
11-
= note: required because of the requirements on the impl of `FromResidual<Option<!>>` for `Result<(), ()>`
12+
= help: the trait `FromResidual<Option<!>>` is not implemented for `Result<(), ()>`
1213
= note: required by `from_residual`
1314

1415
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)

src/test/ui/try-block/try-block-bad-type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn main() {
1515
let res: Result<i32, i32> = try { }; //~ ERROR type mismatch
1616

1717
let res: () = try { };
18-
//~^ ERROR the trait bound `(): Try` is not satisfied
18+
//~^ ERROR the trait bound `(): Try2021` is not satisfied
1919

20-
let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: Try` is not satisfied
20+
let res: i32 = try { 5 }; //~ ERROR the trait bound `i32: Try2021` is not satisfied
2121
}

src/test/ui/try-block/try-block-bad-type.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ LL | Err("")?;
1010
= note: required because of the requirements on the impl of `FromResidual<Result<!, &str>>` for `Result<u32, TryFromSliceError>`
1111
= note: required by `from_residual`
1212

13-
error[E0271]: type mismatch resolving `<Result<i32, i32> as Try>::Ok == &str`
13+
error[E0271]: type mismatch resolving `<Result<i32, i32> as Try2021>::Ok == &str`
1414
--> $DIR/try-block-bad-type.rs:12:9
1515
|
1616
LL | ""
1717
| ^^ expected `i32`, found `&str`
1818

19-
error[E0271]: type mismatch resolving `<Result<i32, i32> as Try>::Ok == ()`
19+
error[E0271]: type mismatch resolving `<Result<i32, i32> as Try2021>::Ok == ()`
2020
--> $DIR/try-block-bad-type.rs:15:39
2121
|
2222
LL | let res: Result<i32, i32> = try { };
2323
| ^ expected `i32`, found `()`
2424

25-
error[E0277]: the trait bound `(): Try` is not satisfied
25+
error[E0277]: the trait bound `(): Try2021` is not satisfied
2626
--> $DIR/try-block-bad-type.rs:17:25
2727
|
2828
LL | let res: () = try { };
29-
| ^ the trait `Try` is not implemented for `()`
29+
| ^ the trait `Try2021` is not implemented for `()`
3030
|
3131
= note: required by `from_output`
3232

33-
error[E0277]: the trait bound `i32: Try` is not satisfied
33+
error[E0277]: the trait bound `i32: Try2021` is not satisfied
3434
--> $DIR/try-block-bad-type.rs:20:26
3535
|
3636
LL | let res: i32 = try { 5 };
37-
| ^ the trait `Try` is not implemented for `i32`
37+
| ^ the trait `Try2021` is not implemented for `i32`
3838
|
3939
= note: required by `from_output`
4040

src/test/ui/try-trait/try-on-option-in-result-method.rs

-20
This file was deleted.

src/test/ui/try-trait/try-on-option.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn main() {}
44

55
fn foo() -> Result<u32, ()> {
66
let x: Option<u32> = None;
7-
x?; //~ ERROR `?` couldn't convert the error to `()`
7+
x?; //~ ERROR the `?` operator
88
Ok(22)
99
}
1010

src/test/ui/try-trait/try-on-option.stderr

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
error[E0277]: `?` couldn't convert the error to `()`
1+
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
22
--> $DIR/try-on-option.rs:7:5
33
|
4-
LL | fn foo() -> Result<u32, ()> {
5-
| --------------- expected `()` because of this
6-
LL | let x: Option<u32> = None;
7-
LL | x?;
8-
| ^^ the trait `From<result::sadness::PleaseCallTheOkOrMethodToUseQuestionMarkOnOptionsInAMethodThatReturnsResult>` is not implemented for `()`
4+
LL | / fn foo() -> Result<u32, ()> {
5+
LL | | let x: Option<u32> = None;
6+
LL | | x?;
7+
| | ^^ cannot use the `?` operator in a function that returns `Result<u32, ()>`
8+
LL | | Ok(22)
9+
LL | | }
10+
| |_- this function should return `Result` or `Option` to accept `?`
911
|
10-
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
11-
= note: required because of the requirements on the impl of `FromResidual<Option<!>>` for `Result<u32, ()>`
12+
= help: the trait `FromResidual<Option<!>>` is not implemented for `Result<u32, ()>`
1213
= note: required by `from_residual`
1314

1415
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)

0 commit comments

Comments
 (0)