Explicitly specify type parameter on FromResidual impls in stdlib. · patricklam/verify-rust-std@aa85448

4 files changed

lines changed

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 {

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 {

Original file line numberDiff line numberDiff line change

@@ -1,4 +1,5 @@

11

mod control_flow;

2+

mod from_residual;

23
34

use core::ops::{

45

Bound, Deref, DerefMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive,

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,26 @@

1+

//! Regression test that Option and ControlFlow can have downstream FromResidual impls.

2+

//! cc https://github.com/rust-lang/rust/issues/99940,

3+

//! This does NOT test that issue in general; Option and ControlFlow's FromResidual

4+

//! impls in core were changed to not be affected by that issue.

5+
6+

use core::ops::{ControlFlow, FromResidual};

7+
8+

struct Local;

9+
10+

impl<T> FromResidual<Local> for Option<T> {

11+

fn from_residual(_: Local) -> Option<T> {

12+

unimplemented!()

13+

}

14+

}

15+
16+

impl<B, C> FromResidual<Local> for ControlFlow<B, C> {

17+

fn from_residual(_: Local) -> ControlFlow<B, C> {

18+

unimplemented!()

19+

}

20+

}

21+
22+

impl<T, E> FromResidual<Local> for Result<T, E> {

23+

fn from_residual(_: Local) -> Result<T, E> {

24+

unimplemented!()

25+

}

26+

}