Rollup merge of #128008 - weiznich:fix/121521, r=lcnr

Start using `#[diagnostic::do_not_recommend]` in the standard library

This commit starts using `#[diagnostic::do_not_recommend]` in the standard library to improve some error messages. In this case we just hide a certain nightly only impl as suggested in #121521

The result in not perfect yet, but at least the `Yeet` suggestion is not shown anymore. I would consider that as a minor improvement.
This commit is contained in:
Trevor Gross 2024-07-22 11:40:21 -05:00 committed by GitHub
commit 8ee5e271ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 10 additions and 22 deletions

View File

@ -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)]

View File

@ -2507,6 +2507,7 @@ fn from_residual(residual: Option<convert::Infallible>) -> Self {
}
}
#[diagnostic::do_not_recommend]
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
impl<T> ops::FromResidual<ops::Yeet<()>> for Option<T> {
#[inline]

View File

@ -1990,7 +1990,7 @@ fn from_residual(residual: Result<convert::Infallible, E>) -> Self {
}
}
}
#[diagnostic::do_not_recommend]
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
impl<T, E, F: From<E>> ops::FromResidual<ops::Yeet<E>> for Result<T, F> {
#[inline]

View File

@ -23,9 +23,7 @@ LL | Some(3)?;
| ^ use `.ok_or(...)?` to provide an error compatible with `Result<u64, String>`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u64, String>`
= help: the following other types implement trait `FromResidual<R>`:
`Result<T, F>` implements `FromResidual<Result<Infallible, E>>`
`Result<T, F>` implements `FromResidual<Yeet<E>>`
= help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
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<u64, String>`
|
= help: the trait `FromResidual<ControlFlow<{integer}, Infallible>>` is not implemented for `Result<u64, String>`
= help: the following other types implement trait `FromResidual<R>`:
`Result<T, F>` implements `FromResidual<Result<Infallible, E>>`
`Result<T, F>` implements `FromResidual<Yeet<E>>`
= help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
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<Infallible, &str>` error information
|
= help: the trait `FromResidual<Result<Infallible, &str>>` is not implemented for `Option<u16>`
= help: the following other types implement trait `FromResidual<R>`:
`Option<T>` implements `FromResidual<Yeet<()>>`
`Option<T>` implements `FromResidual`
= help: the trait `FromResidual` 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
@ -62,9 +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 following other types implement trait `FromResidual<R>`:
`Option<T>` implements `FromResidual<Yeet<()>>`
`Option<T>` implements `FromResidual`
= help: the trait `FromResidual` 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

View File

@ -8,9 +8,7 @@ LL | a?;
| ^ use `.ok_or(...)?` to provide an error compatible with `Result<(), ()>`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<(), ()>`
= help: the following other types implement trait `FromResidual<R>`:
`Result<T, F>` implements `FromResidual<Result<Infallible, E>>`
`Result<T, F>` implements `FromResidual<Yeet<E>>`
= help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
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<Infallible, i32>` error information
|
= help: the trait `FromResidual<Result<Infallible, i32>>` is not implemented for `Option<i32>`
= help: the following other types implement trait `FromResidual<R>`:
`Option<T>` implements `FromResidual<Yeet<()>>`
`Option<T>` implements `FromResidual`
= help: the trait `FromResidual` is implemented for `Option<T>`
error: aborting due to 2 previous errors

View File

@ -8,9 +8,7 @@ LL | x?;
| ^ use `.ok_or(...)?` to provide an error compatible with `Result<u32, ()>`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `Result<u32, ()>`
= help: the following other types implement trait `FromResidual<R>`:
`Result<T, F>` implements `FromResidual<Result<Infallible, E>>`
`Result<T, F>` implements `FromResidual<Yeet<E>>`
= help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
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