diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index d0622182ea9..0ec46412e95 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -165,6 +165,7 @@ #![feature(const_unsafecell_get_mut)] #![feature(const_waker)] #![feature(coverage_attribute)] +#![feature(do_not_recommend)] #![feature(duration_consts_float)] #![feature(internal_impls_macro)] #![feature(ip)] diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 1a8fe1e6051..d93cb8d10e6 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -2507,6 +2507,7 @@ fn from_residual(residual: Option) -> Self { } } +#[diagnostic::do_not_recommend] #[unstable(feature = "try_trait_v2_yeet", issue = "96374")] impl ops::FromResidual> for Option { #[inline] diff --git a/library/core/src/result.rs b/library/core/src/result.rs index f8cdcc000c5..7f278296b7b 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1990,7 +1990,7 @@ fn from_residual(residual: Result) -> Self { } } } - +#[diagnostic::do_not_recommend] #[unstable(feature = "try_trait_v2_yeet", issue = "96374")] impl> ops::FromResidual> for Result { #[inline] diff --git a/tests/ui/try-trait/bad-interconversion.stderr b/tests/ui/try-trait/bad-interconversion.stderr index c30b6334fed..642a93d64e2 100644 --- a/tests/ui/try-trait/bad-interconversion.stderr +++ b/tests/ui/try-trait/bad-interconversion.stderr @@ -23,9 +23,7 @@ LL | Some(3)?; | ^ use `.ok_or(...)?` to provide an error compatible with `Result` | = help: the trait `FromResidual>` is not implemented for `Result` - = help: the following other types implement trait `FromResidual`: - `Result` implements `FromResidual>` - `Result` implements `FromResidual>` + = help: the trait `FromResidual>` is implemented for `Result` error[E0277]: the `?` operator can only be used on `Result`s in a function that returns `Result` --> $DIR/bad-interconversion.rs:17:31 @@ -36,9 +34,7 @@ LL | Ok(ControlFlow::Break(123)?) | ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Result` | = help: the trait `FromResidual>` is not implemented for `Result` - = help: the following other types implement trait `FromResidual`: - `Result` implements `FromResidual>` - `Result` implements `FromResidual>` + = help: the trait `FromResidual>` is implemented for `Result` error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option` --> $DIR/bad-interconversion.rs:22:22 @@ -49,9 +45,7 @@ LL | Some(Err("hello")?) | ^ use `.ok()?` if you want to discard the `Result` error information | = help: the trait `FromResidual>` is not implemented for `Option` - = help: the following other types implement trait `FromResidual`: - `Option` implements `FromResidual>` - `Option` implements `FromResidual` + = help: the trait `FromResidual` is implemented for `Option` error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option` --> $DIR/bad-interconversion.rs:27:33 @@ -62,9 +56,7 @@ LL | Some(ControlFlow::Break(123)?) | ^ this `?` produces `ControlFlow<{integer}, Infallible>`, which is incompatible with `Option` | = help: the trait `FromResidual>` is not implemented for `Option` - = help: the following other types implement trait `FromResidual`: - `Option` implements `FromResidual>` - `Option` implements `FromResidual` + = help: the trait `FromResidual` is implemented for `Option` error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow` --> $DIR/bad-interconversion.rs:32:39 diff --git a/tests/ui/try-trait/option-to-result.stderr b/tests/ui/try-trait/option-to-result.stderr index 2d97226275d..8055b2a0b04 100644 --- a/tests/ui/try-trait/option-to-result.stderr +++ b/tests/ui/try-trait/option-to-result.stderr @@ -8,9 +8,7 @@ LL | a?; | ^ use `.ok_or(...)?` to provide an error compatible with `Result<(), ()>` | = help: the trait `FromResidual>` is not implemented for `Result<(), ()>` - = help: the following other types implement trait `FromResidual`: - `Result` implements `FromResidual>` - `Result` implements `FromResidual>` + = help: the trait `FromResidual>` is implemented for `Result` error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option` --> $DIR/option-to-result.rs:11:6 @@ -22,9 +20,7 @@ LL | a?; | ^ use `.ok()?` if you want to discard the `Result` error information | = help: the trait `FromResidual>` is not implemented for `Option` - = help: the following other types implement trait `FromResidual`: - `Option` implements `FromResidual>` - `Option` implements `FromResidual` + = help: the trait `FromResidual` is implemented for `Option` error: aborting due to 2 previous errors diff --git a/tests/ui/try-trait/try-on-option.stderr b/tests/ui/try-trait/try-on-option.stderr index 84a51a078af..15d0b28ddc1 100644 --- a/tests/ui/try-trait/try-on-option.stderr +++ b/tests/ui/try-trait/try-on-option.stderr @@ -8,9 +8,7 @@ LL | x?; | ^ use `.ok_or(...)?` to provide an error compatible with `Result` | = help: the trait `FromResidual>` is not implemented for `Result` - = help: the following other types implement trait `FromResidual`: - `Result` implements `FromResidual>` - `Result` implements `FromResidual>` + = help: the trait `FromResidual>` is implemented for `Result` error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) --> $DIR/try-on-option.rs:11:6