Skip to content

Commit 47c9ad2

Browse files
committed
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
1 parent 1afc5fd commit 47c9ad2

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
#![feature(const_unsafecell_get_mut)]
166166
#![feature(const_waker)]
167167
#![feature(coverage_attribute)]
168+
#![feature(do_not_recommend)]
168169
#![feature(duration_consts_float)]
169170
#![feature(internal_impls_macro)]
170171
#![feature(ip)]

library/core/src/option.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,7 @@ impl<T> ops::FromResidual for Option<T> {
25072507
}
25082508
}
25092509

2510+
#[diagnostic::do_not_recommend]
25102511
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
25112512
impl<T> ops::FromResidual<ops::Yeet<()>> for Option<T> {
25122513
#[inline]

library/core/src/result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@ impl<T, E, F: From<E>> ops::FromResidual<Result<convert::Infallible, E>> for Res
19901990
}
19911991
}
19921992
}
1993-
1993+
#[diagnostic::do_not_recommend]
19941994
#[unstable(feature = "try_trait_v2_yeet", issue = "96374")]
19951995
impl<T, E, F: From<E>> ops::FromResidual<ops::Yeet<E>> for Result<T, F> {
19961996
#[inline]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
struct BarError;
2+
3+
fn bar() -> Result<(), BarError> {
4+
Ok(())
5+
}
6+
7+
struct FooError;
8+
9+
fn foo() -> Result<(), FooError> {
10+
bar()?;
11+
//~^ ERROR `?` couldn't convert the error to `FooError`
12+
Ok(())
13+
}
14+
15+
fn main() {
16+
foo();
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: `?` couldn't convert the error to `FooError`
2+
--> $DIR/do_not_recommend_nightly_types.rs:10:10
3+
|
4+
LL | fn foo() -> Result<(), FooError> {
5+
| -------------------- expected `FooError` because of this
6+
LL | bar()?;
7+
| -----^ the trait `From<BarError>` is not implemented for `FooError`, which is required by `Result<(), FooError>: FromResidual<Result<Infallible, BarError>>`
8+
| |
9+
| this can't be annotated with `?` because it has type `Result<_, BarError>`
10+
|
11+
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
12+
= help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
13+
= note: required for `Result<(), FooError>` to implement `FromResidual<Result<Infallible, BarError>>`
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)