Skip to content

Commit

Permalink
Remove type parameter default from FromResidual.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachs18 committed Aug 12, 2024
1 parent 730d5d4 commit 7e72781
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ impl<B, C> ops::Try for ControlFlow<B, C> {
}

#[unstable(feature = "try_trait_v2", issue = "84277")]
impl<B, C> ops::FromResidual for ControlFlow<B, C> {
// Note: manually specifying the residual type instead of using the default to work around
// https://github.com/rust-lang/rust/issues/99940
impl<B, C> ops::FromResidual<ControlFlow<B, convert::Infallible>> for ControlFlow<B, C> {
#[inline]
fn from_residual(residual: ControlFlow<B, convert::Infallible>) -> Self {
match residual {
Expand Down
4 changes: 3 additions & 1 deletion library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2495,7 +2495,9 @@ impl<T> ops::Try for Option<T> {
}

#[unstable(feature = "try_trait_v2", issue = "84277")]
impl<T> ops::FromResidual for Option<T> {
// Note: manually specifying the residual type instead of using the default to work around
// https://github.com/rust-lang/rust/issues/99940
impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> {
#[inline]
fn from_residual(residual: Option<convert::Infallible>) -> Self {
match residual {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/try-trait/bad-interconversion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ LL | Some(Err("hello")?)
| ^ use `.ok()?` if you want to discard the `Result<Infallible, &str>` error information
|
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `Option<u16>`
= help: the trait `FromResidual` is implemented for `Option<T>`
= help: the trait `FromResidual<Option<Infallible>>` is implemented for `Option<T>`

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

error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
--> $DIR/bad-interconversion.rs:32:39
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/try-trait/option-to-result.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LL | a?;
| ^ use `.ok()?` if you want to discard the `Result<Infallible, i32>` error information
|
= help: the trait `FromResidual<Result<Infallible, i32>>` is not implemented for `Option<i32>`
= help: the trait `FromResidual` is implemented for `Option<T>`
= help: the trait `FromResidual<Option<Infallible>>` is implemented for `Option<T>`

error: aborting due to 2 previous errors

Expand Down

0 comments on commit 7e72781

Please sign in to comment.