From e4f1179fa6b044adfd52d45ce35bfe4f5ad04c8f Mon Sep 17 00:00:00 2001
From: skippy10110 <pmlyon@hotmail.ca>
Date: Tue, 15 Mar 2022 19:28:53 -0300
Subject: [PATCH] Add deprecated_safe feature gate and attribute, cc #94978

---
 compiler/rustc_feature/src/active.rs          |  2 ++
 compiler/rustc_feature/src/builtin_attrs.rs   |  5 +++++
 compiler/rustc_span/src/symbol.rs             |  1 +
 .../feature-gate-deprecated_safe.rs           |  7 +++++++
 .../feature-gate-deprecated_safe.stderr       | 21 +++++++++++++++++++
 5 files changed, 36 insertions(+)
 create mode 100644 src/test/ui/feature-gates/feature-gate-deprecated_safe.rs
 create mode 100644 src/test/ui/feature-gates/feature-gate-deprecated_safe.stderr

diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index d9748b19e13fe..02cdaa3b95840 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -364,6 +364,8 @@ declare_features! (
     (active, default_alloc_error_handler, "1.48.0", Some(66741), None),
     /// Allows default type parameters to influence type inference.
     (active, default_type_parameter_fallback, "1.3.0", Some(27336), None),
+    /// Allows using `#[deprecated_safe]` to deprecate the safeness of a function or trait
+    (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),
     /// Allows `#[derive(Default)]` and `#[default]` on enums.
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs
index 9c7b8f8032496..e2f0b413ff379 100644
--- a/compiler/rustc_feature/src/builtin_attrs.rs
+++ b/compiler/rustc_feature/src/builtin_attrs.rs
@@ -452,6 +452,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
         "`default_method_body_is_const` is a temporary placeholder for declaring default bodies \
         as `const`, which may be removed or renamed in the future."
     ),
+    // lang-team MCP 147
+    gated!(
+        deprecated_safe, Normal, template!(List: r#"since = "version", note = "...""#), ErrorFollowing,
+        experimental!(deprecated_safe),
+    ),
 
     // ==========================================================================
     // Internal attributes: Stability, deprecation, and unsafe:
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 4dd1c3fed6b36..523a1066a1c3c 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -563,6 +563,7 @@ symbols! {
         delay_span_bug_from_inside_query,
         deny,
         deprecated,
+        deprecated_safe,
         deprecated_suggestion,
         deref,
         deref_method,
diff --git a/src/test/ui/feature-gates/feature-gate-deprecated_safe.rs b/src/test/ui/feature-gates/feature-gate-deprecated_safe.rs
new file mode 100644
index 0000000000000..d5f4a4705b972
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-deprecated_safe.rs
@@ -0,0 +1,7 @@
+#[deprecated_safe(since = "TBD", note = "...")] //~ ERROR: the `#[deprecated_safe]` attribute is an experimental feature
+unsafe fn deprecated_safe_fn() {}
+
+#[deprecated_safe(since = "TBD", note = "...")] //~ ERROR: the `#[deprecated_safe]` attribute is an experimental feature
+unsafe trait DeprecatedSafeTrait {}
+
+fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-deprecated_safe.stderr b/src/test/ui/feature-gates/feature-gate-deprecated_safe.stderr
new file mode 100644
index 0000000000000..5e98a1faaa301
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-deprecated_safe.stderr
@@ -0,0 +1,21 @@
+error[E0658]: the `#[deprecated_safe]` attribute is an experimental feature
+  --> $DIR/feature-gate-deprecated_safe.rs:1:1
+   |
+LL | #[deprecated_safe(since = "TBD", note = "...")]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #94978 <https://github.com/rust-lang/rust/issues/94978> for more information
+   = help: add `#![feature(deprecated_safe)]` to the crate attributes to enable
+
+error[E0658]: the `#[deprecated_safe]` attribute is an experimental feature
+  --> $DIR/feature-gate-deprecated_safe.rs:4:1
+   |
+LL | #[deprecated_safe(since = "TBD", note = "...")]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #94978 <https://github.com/rust-lang/rust/issues/94978> for more information
+   = help: add `#![feature(deprecated_safe)]` to the crate attributes to enable
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0658`.