about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev+love@gmail.com>2023-01-11 14:18:55 +0900
committerGitHub <noreply@github.com>2023-01-11 14:18:55 +0900
commite078d8271182c0923c671a05d43d2b6e9d8d6e42 (patch)
tree51596f372c448aa25c2a939418a9e024cd5b2c76
parentf547c4b33a87fb167fe9314bd225304e00268fce (diff)
parentc43faf110de5ee6abce0899872457dc8904723ad (diff)
downloadrust-e078d8271182c0923c671a05d43d2b6e9d8d6e42.tar.gz
rust-e078d8271182c0923c671a05d43d2b6e9d8d6e42.zip
Rollup merge of #106645 - c410-f3r:rfc-2397-1, r=oli-obk
[RFC 2397] Initial implementation

cc #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.
-rw-r--r--compiler/rustc_feature/src/active.rs2
-rw-r--r--compiler/rustc_feature/src/builtin_attrs.rs3
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--src/test/ui/rfc-2397-do-not-recommend/feature-gate-do_not_recommend.rs21
-rw-r--r--src/test/ui/rfc-2397-do-not-recommend/feature-gate-do_not_recommend.stderr23
-rw-r--r--src/test/ui/rfc-2397-do-not-recommend/unstable-feature.rs7
-rw-r--r--src/test/ui/rfc-2397-do-not-recommend/unstable-feature.stderr12
7 files changed, 69 insertions, 0 deletions
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index beade4d44da..691c0955cad 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -374,6 +374,8 @@ declare_features! (
     (active, deprecated_safe, "1.61.0", Some(94978), None),
     /// Allows having using `suggestion` in the `#[deprecated]` attribute.
     (active, deprecated_suggestion, "1.61.0", Some(94785), None),
+    /// Controls errors in trait implementations.
+    (active, do_not_recommend, "1.67.0", Some(51992), None),
     /// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
     (active, doc_auto_cfg, "1.58.0", Some(43781), None),
     /// Allows `#[doc(cfg(...))]`.
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs
index ad85231860d..af56a0b2459 100644
--- a/compiler/rustc_feature/src/builtin_attrs.rs
+++ b/compiler/rustc_feature/src/builtin_attrs.rs
@@ -487,6 +487,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
         experimental!(collapse_debuginfo)
     ),
 
+    // RFC 2397
+    gated!(do_not_recommend, Normal, template!(Word), WarnFollowing, experimental!(do_not_recommend)),
+
     // ==========================================================================
     // Internal attributes: Stability, deprecation, and unsafe:
     // ==========================================================================
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 5d5f8d6d654..fbb12701d96 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -613,6 +613,7 @@ symbols! {
         dispatch_from_dyn,
         div,
         div_assign,
+        do_not_recommend,
         doc,
         doc_alias,
         doc_auto_cfg,
diff --git a/src/test/ui/rfc-2397-do-not-recommend/feature-gate-do_not_recommend.rs b/src/test/ui/rfc-2397-do-not-recommend/feature-gate-do_not_recommend.rs
new file mode 100644
index 00000000000..5053c115b45
--- /dev/null
+++ b/src/test/ui/rfc-2397-do-not-recommend/feature-gate-do_not_recommend.rs
@@ -0,0 +1,21 @@
+#![feature(do_not_recommend)]
+
+pub trait Foo {
+}
+
+impl Foo for i32 {
+}
+
+pub trait Bar {
+}
+
+#[do_not_recommend]
+impl<T: Foo> Bar for T {
+}
+
+fn stuff<T: Bar>(_: T) {}
+
+fn main() {
+    stuff(1u8);
+    //~^ the trait bound `u8: Foo` is not satisfied
+}
diff --git a/src/test/ui/rfc-2397-do-not-recommend/feature-gate-do_not_recommend.stderr b/src/test/ui/rfc-2397-do-not-recommend/feature-gate-do_not_recommend.stderr
new file mode 100644
index 00000000000..2749add82ac
--- /dev/null
+++ b/src/test/ui/rfc-2397-do-not-recommend/feature-gate-do_not_recommend.stderr
@@ -0,0 +1,23 @@
+error[E0277]: the trait bound `u8: Foo` is not satisfied
+  --> $DIR/feature-gate-do_not_recommend.rs:19:11
+   |
+LL |     stuff(1u8);
+   |     ----- ^^^ the trait `Foo` is not implemented for `u8`
+   |     |
+   |     required by a bound introduced by this call
+   |
+   = help: the trait `Foo` is implemented for `i32`
+note: required for `u8` to implement `Bar`
+  --> $DIR/feature-gate-do_not_recommend.rs:13:14
+   |
+LL | impl<T: Foo> Bar for T {
+   |              ^^^     ^
+note: required by a bound in `stuff`
+  --> $DIR/feature-gate-do_not_recommend.rs:16:13
+   |
+LL | fn stuff<T: Bar>(_: T) {}
+   |             ^^^ required by this bound in `stuff`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-2397-do-not-recommend/unstable-feature.rs b/src/test/ui/rfc-2397-do-not-recommend/unstable-feature.rs
new file mode 100644
index 00000000000..b816c4a19da
--- /dev/null
+++ b/src/test/ui/rfc-2397-do-not-recommend/unstable-feature.rs
@@ -0,0 +1,7 @@
+#[do_not_recommend]
+//~^ ERROR the `#[do_not_recommend]` attribute is an experimental feature
+trait Foo {
+}
+
+fn main() {
+}
diff --git a/src/test/ui/rfc-2397-do-not-recommend/unstable-feature.stderr b/src/test/ui/rfc-2397-do-not-recommend/unstable-feature.stderr
new file mode 100644
index 00000000000..425d7e4bca0
--- /dev/null
+++ b/src/test/ui/rfc-2397-do-not-recommend/unstable-feature.stderr
@@ -0,0 +1,12 @@
+error[E0658]: the `#[do_not_recommend]` attribute is an experimental feature
+  --> $DIR/unstable-feature.rs:1:1
+   |
+LL | #[do_not_recommend]
+   | ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #51992 <https://github.com/rust-lang/rust/issues/51992> for more information
+   = help: add `#![feature(do_not_recommend)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.