Skip to content

Commit aa85448

Browse files
committed
Explicitly specify type parameter on FromResidual impls in stdlib.
To work around coherence issue. Also adds regression test.
1 parent b8b61e1 commit aa85448

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

Diff for: 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 {

Diff for: 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 {

Diff for: core/tests/ops.rs

+1
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,

Diff for: core/tests/ops/from_residual.rs

+26
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+
}

0 commit comments

Comments
 (0)