Skip to content

Commit e078d82

Browse files
author
Yuki Okushi
authored
Rollup merge of rust-lang#106645 - c410-f3r:rfc-2397-1, r=oli-obk
[RFC 2397] Initial implementation cc rust-lang#51992 Because of previous experiences where ppl didn't have the time to review large PRs (or any at all), the implementation of this feature will be delivered in small chunks to hopefully make things faster. In this initial PR, only the attribute is being declared and gated with ordinary tests.
2 parents f547c4b + c43faf1 commit e078d82

File tree

7 files changed

+69
-0
lines changed

7 files changed

+69
-0
lines changed

Diff for: compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ declare_features! (
374374
(active, deprecated_safe, "1.61.0", Some(94978), None),
375375
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
376376
(active, deprecated_suggestion, "1.61.0", Some(94785), None),
377+
/// Controls errors in trait implementations.
378+
(active, do_not_recommend, "1.67.0", Some(51992), None),
377379
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
378380
(active, doc_auto_cfg, "1.58.0", Some(43781), None),
379381
/// Allows `#[doc(cfg(...))]`.

Diff for: compiler/rustc_feature/src/builtin_attrs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
487487
experimental!(collapse_debuginfo)
488488
),
489489

490+
// RFC 2397
491+
gated!(do_not_recommend, Normal, template!(Word), WarnFollowing, experimental!(do_not_recommend)),
492+
490493
// ==========================================================================
491494
// Internal attributes: Stability, deprecation, and unsafe:
492495
// ==========================================================================

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ symbols! {
613613
dispatch_from_dyn,
614614
div,
615615
div_assign,
616+
do_not_recommend,
616617
doc,
617618
doc_alias,
618619
doc_auto_cfg,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(do_not_recommend)]
2+
3+
pub trait Foo {
4+
}
5+
6+
impl Foo for i32 {
7+
}
8+
9+
pub trait Bar {
10+
}
11+
12+
#[do_not_recommend]
13+
impl<T: Foo> Bar for T {
14+
}
15+
16+
fn stuff<T: Bar>(_: T) {}
17+
18+
fn main() {
19+
stuff(1u8);
20+
//~^ the trait bound `u8: Foo` is not satisfied
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0277]: the trait bound `u8: Foo` is not satisfied
2+
--> $DIR/feature-gate-do_not_recommend.rs:19:11
3+
|
4+
LL | stuff(1u8);
5+
| ----- ^^^ the trait `Foo` is not implemented for `u8`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the trait `Foo` is implemented for `i32`
10+
note: required for `u8` to implement `Bar`
11+
--> $DIR/feature-gate-do_not_recommend.rs:13:14
12+
|
13+
LL | impl<T: Foo> Bar for T {
14+
| ^^^ ^
15+
note: required by a bound in `stuff`
16+
--> $DIR/feature-gate-do_not_recommend.rs:16:13
17+
|
18+
LL | fn stuff<T: Bar>(_: T) {}
19+
| ^^^ required by this bound in `stuff`
20+
21+
error: aborting due to previous error
22+
23+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[do_not_recommend]
2+
//~^ ERROR the `#[do_not_recommend]` attribute is an experimental feature
3+
trait Foo {
4+
}
5+
6+
fn main() {
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: the `#[do_not_recommend]` attribute is an experimental feature
2+
--> $DIR/unstable-feature.rs:1:1
3+
|
4+
LL | #[do_not_recommend]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #51992 <https://github.com/rust-lang/rust/issues/51992> for more information
8+
= help: add `#![feature(do_not_recommend)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)