Skip to content

Commit 7e72781

Browse files
committed
Remove type parameter default from FromResidual.
1 parent 730d5d4 commit 7e72781

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

library/core/src/ops/control_flow.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ impl<B, C> ops::Try for ControlFlow<B, C> {
116116
}
117117

118118
#[unstable(feature = "try_trait_v2", issue = "84277")]
119-
impl<B, C> ops::FromResidual for ControlFlow<B, C> {
119+
// Note: manually specifying the residual type instead of using the default to work around
120+
// https://github.com/rust-lang/rust/issues/99940
121+
impl<B, C> ops::FromResidual<ControlFlow<B, convert::Infallible>> for ControlFlow<B, C> {
120122
#[inline]
121123
fn from_residual(residual: ControlFlow<B, convert::Infallible>) -> Self {
122124
match residual {

library/core/src/option.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,9 @@ impl<T> ops::Try for Option<T> {
24952495
}
24962496

24972497
#[unstable(feature = "try_trait_v2", issue = "84277")]
2498-
impl<T> ops::FromResidual for Option<T> {
2498+
// Note: manually specifying the residual type instead of using the default to work around
2499+
// https://github.com/rust-lang/rust/issues/99940
2500+
impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> {
24992501
#[inline]
25002502
fn from_residual(residual: Option<convert::Infallible>) -> Self {
25012503
match residual {

tests/ui/try-trait/bad-interconversion.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ LL | Some(Err("hello")?)
4545
| ^ use `.ok()?` if you want to discard the `Result<Infallible, &str>` error information
4646
|
4747
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `Option<u16>`
48-
= help: the trait `FromResidual` is implemented for `Option<T>`
48+
= help: the trait `FromResidual<Option<Infallible>>` is implemented for `Option<T>`
4949

5050
error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option`
5151
--> $DIR/bad-interconversion.rs:27:33
@@ -56,7 +56,7 @@ LL | Some(ControlFlow::Break(123)?)
5656
| ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Option<u64>`
5757
|
5858
= help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Option<u64>`
59-
= help: the trait `FromResidual` is implemented for `Option<T>`
59+
= help: the trait `FromResidual<Option<Infallible>>` is implemented for `Option<T>`
6060

6161
error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
6262
--> $DIR/bad-interconversion.rs:32:39

tests/ui/try-trait/option-to-result.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | a?;
2020
| ^ use `.ok()?` if you want to discard the `Result<Infallible, i32>` error information
2121
|
2222
= help: the trait `FromResidual<Result<Infallible, i32>>` is not implemented for `Option<i32>`
23-
= help: the trait `FromResidual` is implemented for `Option<T>`
23+
= help: the trait `FromResidual<Option<Infallible>>` is implemented for `Option<T>`
2424

2525
error: aborting due to 2 previous errors
2626

0 commit comments

Comments
 (0)