Skip to content

Commit

Permalink
Start using #[diagnostic::do_not_recommend] in the standard library
Browse files Browse the repository at this point in the history
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
  • Loading branch information
weiznich committed Jul 20, 2024
1 parent 1afc5fd commit 47c9ad2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2507,6 +2507,7 @@ impl<T> ops::FromResidual for Option<T> {
}
}

#[diagnostic::do_not_recommend]
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
impl<T> ops::FromResidual<ops::Yeet<()>> for Option<T> {
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,7 @@ impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Res
}
}
}

#[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]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
struct BarError;

fn bar() -> Result<(), BarError> {
Ok(())
}

struct FooError;

fn foo() -> Result<(), FooError> {
bar()?;
//~^ ERROR `?` couldn't convert the error to `FooError`
Ok(())
}

fn main() {
foo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0277]: `?` couldn't convert the error to `FooError`
--> $DIR/do_not_recommend_nightly_types.rs:10:10
|
LL | fn foo() -> Result<(), FooError> {
| -------------------- expected `FooError` because of this
LL | bar()?;
| -----^ the trait `From<BarError>` is not implemented for `FooError`, which is required by `Result<(), FooError>: FromResidual<Result<Infallible, BarError>>`
| |
| this can't be annotated with `?` because it has type `Result<_, BarError>`
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
= note: required for `Result<(), FooError>` to implement `FromResidual<Result<Infallible, BarError>>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 47c9ad2

Please sign in to comment.