Skip to content

Commit

Permalink
Rollup merge of rust-lang#128954 - zachs18:fromresidual-no-default, r…
Browse files Browse the repository at this point in the history
…=scottmcm

Explicitly specify type parameter on FromResidual for Option and ControlFlow.

~~Remove type parameter default `R = <Self as Try>::Residual` from `FromResidual`~~ _Specify default type parameter on `FromResidual` impls in the stdlib_ to work around rust-lang#99940 / rust-lang#87350 ~~as mentioned in rust-lang#84277 (comment).

This does not completely fix the issue, but works around it for `Option` and `ControlFlow` specifically (`Result` does not have the issue since it already did not use the default parameter of `FromResidual`).

~~(Does this need an ACP or similar?)~~ ~~This probably needs at least an FCP since it changes the API described in [the RFC](rust-lang/rfcs#3058). Not sure if T-lang, T-libs-api, T-libs, or some combination (The tracking issue is tagged T-lang, T-libs-api).~~ This probably doesn't need T-lang input, since it is not changing the API of `FromResidual` from the RFC? Maybe needs T-libs-api FCP?
  • Loading branch information
jieyouxu authored Aug 14, 2024
2 parents 4f09599 + aa85448 commit 0dbf8cf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion 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 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
1 change: 1 addition & 0 deletions core/tests/ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod control_flow;
mod from_residual;

use core::ops::{
Bound, Deref, DerefMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive,
Expand Down
26 changes: 26 additions & 0 deletions core/tests/ops/from_residual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! Regression test that Option and ControlFlow can have downstream FromResidual impls.
//! cc https://github.com/rust-lang/rust/issues/99940,
//! This does NOT test that issue in general; Option and ControlFlow's FromResidual
//! impls in core were changed to not be affected by that issue.
use core::ops::{ControlFlow, FromResidual};

struct Local;

impl<T> FromResidual<Local> for Option<T> {
fn from_residual(_: Local) -> Option<T> {
unimplemented!()
}
}

impl<B, C> FromResidual<Local> for ControlFlow<B, C> {
fn from_residual(_: Local) -> ControlFlow<B, C> {
unimplemented!()
}
}

impl<T, E> FromResidual<Local> for Result<T, E> {
fn from_residual(_: Local) -> Result<T, E> {
unimplemented!()
}
}

0 comments on commit 0dbf8cf

Please sign in to comment.