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 11, 2024
1 parent 730d5d4 commit eff3994
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ 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> {
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
6 changes: 3 additions & 3 deletions library/core/src/ops/try_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ use crate::ops::ControlFlow;
)]
#[doc(alias = "?")]
#[lang = "Try"]
pub trait Try: FromResidual {
pub trait Try: FromResidual<Self::Residual> {
/// The type of the value produced by `?` when *not* short-circuiting.
#[unstable(feature = "try_trait_v2", issue = "84277")]
type Output;
Expand Down Expand Up @@ -304,7 +304,7 @@ pub trait Try: FromResidual {
)]
#[rustc_diagnostic_item = "FromResidual"]
#[unstable(feature = "try_trait_v2", issue = "84277")]
pub trait FromResidual<R = <Self as Try>::Residual> {
pub trait FromResidual<R> {
/// Constructs the type from a compatible `Residual` type.
///
/// This should be implemented consistently with the `branch` method such
Expand Down Expand Up @@ -410,7 +410,7 @@ impl<T> Try for NeverShortCircuit<T> {
}
}

impl<T> FromResidual for NeverShortCircuit<T> {
impl<T> FromResidual<NeverShortCircuitResidual> for NeverShortCircuit<T> {
#[inline]
fn from_residual(never: NeverShortCircuitResidual) -> Self {
match never {}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2495,7 +2495,7 @@ impl<T> ops::Try for Option<T> {
}

#[unstable(feature = "try_trait_v2", issue = "84277")]
impl<T> ops::FromResidual for Option<T> {
impl<T> ops::FromResidual<Option<convert::Infallible>> for Option<T> {
#[inline]
fn from_residual(residual: Option<convert::Infallible>) -> Self {
match residual {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::ops::FromResidual;

impl<T> const FromResidual for T {
impl<T> const FromResidual<T> for T {
//~^ ERROR const `impl` for trait `FromResidual` which is not marked with `#[const_trait]`
//~| type parameter `T` must be used as the type parameter for some local type
fn from_residual(t: T) -> _ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ error: using `#![feature(effects)]` without enabling next trait solver globally
error: const `impl` for trait `FromResidual` which is not marked with `#[const_trait]`
--> $DIR/ice-119717-constant-lifetime.rs:6:15
|
LL | impl<T> const FromResidual for T {
| ^^^^^^^^^^^^
LL | impl<T> const FromResidual<T> for T {
| ^^^^^^^^^^^^^^^
|
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
= note: adding a non-const method body in the future would be a breaking change

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/ice-119717-constant-lifetime.rs:6:6
|
LL | impl<T> const FromResidual for T {
LL | impl<T> const FromResidual<T> for T {
| ^ type parameter `T` must be used as the type parameter for some local type
|
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl const Try for T {

#[stable(feature = "foo", since = "1.0")]
#[rustc_const_unstable(feature = "const_t_try", issue = "none")]
impl const FromResidual for T {
impl const FromResidual<T> for T {
fn from_residual(t: T) -> T {
t
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ LL | impl const Try for T {
error: const `impl` for trait `FromResidual` which is not marked with `#[const_trait]`
--> $DIR/trait-default-body-stability.rs:34:12
|
LL | impl const FromResidual for T {
| ^^^^^^^^^^^^
LL | impl const FromResidual<T> for T {
| ^^^^^^^^^^^^^^^
|
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
= note: adding a non-const method body in the future would be a breaking change
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 eff3994

Please sign in to comment.