Skip to content

Commit bc29123

Browse files
committed
Revert "remove rust-analyser support for extern "rust-intrinsic" blocks"
This reverts commit 51b51b5.
1 parent e643f59 commit bc29123

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ pub enum FnAbi {
400400
Rust,
401401
RustCall,
402402
RustCold,
403+
RustIntrinsic,
403404
Stdcall,
404405
StdcallUnwind,
405406
System,
@@ -456,6 +457,7 @@ impl FnAbi {
456457
s if *s == sym::riscv_dash_interrupt_dash_s => FnAbi::RiscvInterruptS,
457458
s if *s == sym::rust_dash_call => FnAbi::RustCall,
458459
s if *s == sym::rust_dash_cold => FnAbi::RustCold,
460+
s if *s == sym::rust_dash_intrinsic => FnAbi::RustIntrinsic,
459461
s if *s == sym::Rust => FnAbi::Rust,
460462
s if *s == sym::stdcall_dash_unwind => FnAbi::StdcallUnwind,
461463
s if *s == sym::stdcall => FnAbi::Stdcall,
@@ -498,6 +500,7 @@ impl FnAbi {
498500
FnAbi::Rust => "Rust",
499501
FnAbi::RustCall => "rust-call",
500502
FnAbi::RustCold => "rust-cold",
503+
FnAbi::RustIntrinsic => "rust-intrinsic",
501504
FnAbi::Stdcall => "stdcall",
502505
FnAbi::StdcallUnwind => "stdcall-unwind",
503506
FnAbi::System => "system",

src/tools/rust-analyzer/crates/hir-ty/src/mir/eval/shim.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,19 @@ impl Evaluator<'_> {
5959

6060
let function_data = self.db.function_data(def);
6161
let attrs = self.db.attrs(def.into());
62-
let is_intrinsic = attrs.by_key(&sym::rustc_intrinsic).exists();
62+
let is_intrinsic = attrs.by_key(&sym::rustc_intrinsic).exists()
63+
// Keep this around for a bit until extern "rustc-intrinsic" abis are no longer used
64+
|| (match &function_data.abi {
65+
Some(abi) => *abi == sym::rust_dash_intrinsic,
66+
None => match def.lookup(self.db.upcast()).container {
67+
hir_def::ItemContainerId::ExternBlockId(block) => {
68+
let id = block.lookup(self.db.upcast()).id;
69+
id.item_tree(self.db.upcast())[id.value].abi.as_ref()
70+
== Some(&sym::rust_dash_intrinsic)
71+
}
72+
_ => false,
73+
},
74+
});
6375

6476
if is_intrinsic {
6577
return self.exec_intrinsic(

src/tools/rust-analyzer/crates/hir-ty/src/utils.rs

+20-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use hir_def::{
1818
TypeOrConstParamId,
1919
};
2020
use hir_expand::name::Name;
21+
use intern::sym;
2122
use rustc_abi::TargetDataLayout;
2223
use rustc_hash::FxHashSet;
2324
use smallvec::{smallvec, SmallVec};
@@ -302,13 +303,26 @@ pub fn is_fn_unsafe_to_call(
302303

303304
let loc = func.lookup(db.upcast());
304305
match loc.container {
305-
hir_def::ItemContainerId::ExternBlockId(_block) => {
306-
// Function in an `extern` block are always unsafe to call, except when
307-
// it is marked as `safe`.
308-
if data.is_safe() {
309-
Unsafety::Safe
306+
hir_def::ItemContainerId::ExternBlockId(block) => {
307+
let id = block.lookup(db.upcast()).id;
308+
let is_intrinsic_block =
309+
id.item_tree(db.upcast())[id.value].abi.as_ref() == Some(&sym::rust_dash_intrinsic);
310+
if is_intrinsic_block {
311+
// legacy intrinsics
312+
// extern "rust-intrinsic" intrinsics are unsafe unless they have the rustc_safe_intrinsic attribute
313+
if db.attrs(func.into()).by_key(&sym::rustc_safe_intrinsic).exists() {
314+
Unsafety::Safe
315+
} else {
316+
Unsafety::Unsafe
317+
}
310318
} else {
311-
Unsafety::Unsafe
319+
// Function in an `extern` block are always unsafe to call, except when
320+
// it is marked as `safe`.
321+
if data.is_safe() {
322+
Unsafety::Safe
323+
} else {
324+
Unsafety::Unsafe
325+
}
312326
}
313327
}
314328
_ => Unsafety::Safe,

src/tools/rust-analyzer/crates/ide-completion/src/completions/extern_abi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const SUPPORTED_CALLING_CONVENTIONS: &[&str] = &[
3636
"wasm",
3737
"system",
3838
"system-unwind",
39+
"rust-intrinsic",
3940
"rust-call",
4041
"unadjusted",
4142
];

src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ define_symbols! {
125125
riscv_dash_interrupt_dash_s = "riscv-interrupt-s",
126126
rust_dash_call = "rust-call",
127127
rust_dash_cold = "rust-cold",
128+
rust_dash_intrinsic = "rust-intrinsic",
128129
stdcall_dash_unwind = "stdcall-unwind",
129130
system_dash_unwind = "system-unwind",
130131
sysv64_dash_unwind = "sysv64-unwind",

0 commit comments

Comments
 (0)