about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs4
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/utils.rs5
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs14
3 files changed, 23 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs b/src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs
index f4564c94bb5..7b649496c48 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs
@@ -628,6 +628,10 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
         rustc_safe_intrinsic, Normal, template!(Word), WarnFollowing,
         "the `#[rustc_safe_intrinsic]` attribute is used internally to mark intrinsics as safe"
     ),
+    rustc_attr!(
+        rustc_deprecated_safe_2024, Normal, template!(Word), WarnFollowing,
+        "the `#[rustc_safe_intrinsic]` marks functions as unsafe in Rust 2024",
+    ),
 
     // ==========================================================================
     // Internal attributes, Testing:
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs b/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs
index 42c7a840328..cff8e6b0368 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs
@@ -534,6 +534,11 @@ fn parent_generic_def(db: &dyn DefDatabase, def: GenericDefId) -> Option<Generic
 pub fn is_fn_unsafe_to_call(db: &dyn HirDatabase, func: FunctionId) -> bool {
     let data = db.function_data(func);
     if data.has_unsafe_kw() {
+        // Functions that are `#[rustc_deprecated_safe_2024]` are safe to call before 2024.
+        if db.attrs(func.into()).by_key("rustc_deprecated_safe_2024").exists() {
+            // FIXME: Properly check the caller span and mark it as unsafe after 2024.
+            return false;
+        }
         return true;
     }
 
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs
index 1b29e0a3746..30dd26a118d 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/missing_unsafe.rs
@@ -183,6 +183,20 @@ fn main() {
     }
 
     #[test]
+    fn no_missing_unsafe_diagnostic_with_deprecated_safe_2024() {
+        check_diagnostics(
+            r#"
+#[rustc_deprecated_safe_2024]
+fn set_var() {}
+
+fn main() {
+    set_var();
+}
+"#,
+        );
+    }
+
+    #[test]
     fn add_unsafe_block_when_dereferencing_a_raw_pointer() {
         check_fix(
             r#"