about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBennet Bleßmann <bb-github@t-online.de>2025-04-07 20:30:27 +0200
committerBennet Bleßmann <bb-github@t-online.de>2025-04-07 20:30:27 +0200
commitbc2912386f6841869a74e129a06f6dbe3fffacfc (patch)
tree203444cd70e62f39df7ebc610bc88f5d89e17823 /src
parente643f59f6da3a84f43e75dea99afaa5b041ea6bf (diff)
downloadrust-bc2912386f6841869a74e129a06f6dbe3fffacfc.tar.gz
rust-bc2912386f6841869a74e129a06f6dbe3fffacfc.zip
Revert "remove rust-analyser support for `extern "rust-intrinsic"` blocks"
This reverts commit 51b51b51d7931da85280382a81c4dd80c73ca754.
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/lib.rs3
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/mir/eval/shim.rs14
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/utils.rs26
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs1
-rw-r--r--src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs1
5 files changed, 38 insertions, 7 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs
index e4c50f2ebdb..cc02b71f05c 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/lib.rs
@@ -400,6 +400,7 @@ pub enum FnAbi {
     Rust,
     RustCall,
     RustCold,
+    RustIntrinsic,
     Stdcall,
     StdcallUnwind,
     System,
@@ -456,6 +457,7 @@ impl FnAbi {
             s if *s == sym::riscv_dash_interrupt_dash_s => FnAbi::RiscvInterruptS,
             s if *s == sym::rust_dash_call => FnAbi::RustCall,
             s if *s == sym::rust_dash_cold => FnAbi::RustCold,
+            s if *s == sym::rust_dash_intrinsic => FnAbi::RustIntrinsic,
             s if *s == sym::Rust => FnAbi::Rust,
             s if *s == sym::stdcall_dash_unwind => FnAbi::StdcallUnwind,
             s if *s == sym::stdcall => FnAbi::Stdcall,
@@ -498,6 +500,7 @@ impl FnAbi {
             FnAbi::Rust => "Rust",
             FnAbi::RustCall => "rust-call",
             FnAbi::RustCold => "rust-cold",
+            FnAbi::RustIntrinsic => "rust-intrinsic",
             FnAbi::Stdcall => "stdcall",
             FnAbi::StdcallUnwind => "stdcall-unwind",
             FnAbi::System => "system",
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval/shim.rs b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval/shim.rs
index 06ac5b1ffad..f61ecabb7e4 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval/shim.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/mir/eval/shim.rs
@@ -59,7 +59,19 @@ impl Evaluator<'_> {
 
         let function_data = self.db.function_data(def);
         let attrs = self.db.attrs(def.into());
-        let is_intrinsic = attrs.by_key(&sym::rustc_intrinsic).exists();
+        let is_intrinsic = attrs.by_key(&sym::rustc_intrinsic).exists()
+            // Keep this around for a bit until extern "rustc-intrinsic" abis are no longer used
+            || (match &function_data.abi {
+                Some(abi) => *abi == sym::rust_dash_intrinsic,
+                None => match def.lookup(self.db.upcast()).container {
+                    hir_def::ItemContainerId::ExternBlockId(block) => {
+                        let id = block.lookup(self.db.upcast()).id;
+                        id.item_tree(self.db.upcast())[id.value].abi.as_ref()
+                            == Some(&sym::rust_dash_intrinsic)
+                    }
+                    _ => false,
+                },
+            });
 
         if is_intrinsic {
             return self.exec_intrinsic(
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 0cfd36d9166..89d89fe2230 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/utils.rs
@@ -18,6 +18,7 @@ use hir_def::{
     TypeOrConstParamId,
 };
 use hir_expand::name::Name;
+use intern::sym;
 use rustc_abi::TargetDataLayout;
 use rustc_hash::FxHashSet;
 use smallvec::{smallvec, SmallVec};
@@ -302,13 +303,26 @@ pub fn is_fn_unsafe_to_call(
 
     let loc = func.lookup(db.upcast());
     match loc.container {
-        hir_def::ItemContainerId::ExternBlockId(_block) => {
-            // Function in an `extern` block are always unsafe to call, except when
-            // it is marked as `safe`.
-            if data.is_safe() {
-                Unsafety::Safe
+        hir_def::ItemContainerId::ExternBlockId(block) => {
+            let id = block.lookup(db.upcast()).id;
+            let is_intrinsic_block =
+                id.item_tree(db.upcast())[id.value].abi.as_ref() == Some(&sym::rust_dash_intrinsic);
+            if is_intrinsic_block {
+                // legacy intrinsics
+                // extern "rust-intrinsic" intrinsics are unsafe unless they have the rustc_safe_intrinsic attribute
+                if db.attrs(func.into()).by_key(&sym::rustc_safe_intrinsic).exists() {
+                    Unsafety::Safe
+                } else {
+                    Unsafety::Unsafe
+                }
             } else {
-                Unsafety::Unsafe
+                // Function in an `extern` block are always unsafe to call, except when
+                // it is marked as `safe`.
+                if data.is_safe() {
+                    Unsafety::Safe
+                } else {
+                    Unsafety::Unsafe
+                }
             }
         }
         _ => Unsafety::Safe,
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs
index a3554114f4c..7c2cc2a6c1d 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs
@@ -36,6 +36,7 @@ const SUPPORTED_CALLING_CONVENTIONS: &[&str] = &[
     "wasm",
     "system",
     "system-unwind",
+    "rust-intrinsic",
     "rust-call",
     "unadjusted",
 ];
diff --git a/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs b/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs
index d4f334289f0..6b77c72cee8 100644
--- a/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs
+++ b/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs
@@ -125,6 +125,7 @@ define_symbols! {
     riscv_dash_interrupt_dash_s = "riscv-interrupt-s",
     rust_dash_call = "rust-call",
     rust_dash_cold = "rust-cold",
+    rust_dash_intrinsic = "rust-intrinsic",
     stdcall_dash_unwind = "stdcall-unwind",
     system_dash_unwind = "system-unwind",
     sysv64_dash_unwind = "sysv64-unwind",