File tree 5 files changed +38
-7
lines changed
src/tools/rust-analyzer/crates
ide-completion/src/completions
5 files changed +38
-7
lines changed Original file line number Diff line number Diff line change @@ -400,6 +400,7 @@ pub enum FnAbi {
400
400
Rust ,
401
401
RustCall ,
402
402
RustCold ,
403
+ RustIntrinsic ,
403
404
Stdcall ,
404
405
StdcallUnwind ,
405
406
System ,
@@ -456,6 +457,7 @@ impl FnAbi {
456
457
s if * s == sym:: riscv_dash_interrupt_dash_s => FnAbi :: RiscvInterruptS ,
457
458
s if * s == sym:: rust_dash_call => FnAbi :: RustCall ,
458
459
s if * s == sym:: rust_dash_cold => FnAbi :: RustCold ,
460
+ s if * s == sym:: rust_dash_intrinsic => FnAbi :: RustIntrinsic ,
459
461
s if * s == sym:: Rust => FnAbi :: Rust ,
460
462
s if * s == sym:: stdcall_dash_unwind => FnAbi :: StdcallUnwind ,
461
463
s if * s == sym:: stdcall => FnAbi :: Stdcall ,
@@ -498,6 +500,7 @@ impl FnAbi {
498
500
FnAbi :: Rust => "Rust" ,
499
501
FnAbi :: RustCall => "rust-call" ,
500
502
FnAbi :: RustCold => "rust-cold" ,
503
+ FnAbi :: RustIntrinsic => "rust-intrinsic" ,
501
504
FnAbi :: Stdcall => "stdcall" ,
502
505
FnAbi :: StdcallUnwind => "stdcall-unwind" ,
503
506
FnAbi :: System => "system" ,
Original file line number Diff line number Diff line change @@ -59,7 +59,19 @@ impl Evaluator<'_> {
59
59
60
60
let function_data = self . db . function_data ( def) ;
61
61
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
+ } ) ;
63
75
64
76
if is_intrinsic {
65
77
return self . exec_intrinsic (
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ use hir_def::{
18
18
TypeOrConstParamId ,
19
19
} ;
20
20
use hir_expand:: name:: Name ;
21
+ use intern:: sym;
21
22
use rustc_abi:: TargetDataLayout ;
22
23
use rustc_hash:: FxHashSet ;
23
24
use smallvec:: { smallvec, SmallVec } ;
@@ -302,13 +303,26 @@ pub fn is_fn_unsafe_to_call(
302
303
303
304
let loc = func. lookup ( db. upcast ( ) ) ;
304
305
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
+ }
310
318
} 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
+ }
312
326
}
313
327
}
314
328
_ => Unsafety :: Safe ,
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ const SUPPORTED_CALLING_CONVENTIONS: &[&str] = &[
36
36
"wasm" ,
37
37
"system" ,
38
38
"system-unwind" ,
39
+ "rust-intrinsic" ,
39
40
"rust-call" ,
40
41
"unadjusted" ,
41
42
] ;
Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ define_symbols! {
125
125
riscv_dash_interrupt_dash_s = "riscv-interrupt-s" ,
126
126
rust_dash_call = "rust-call" ,
127
127
rust_dash_cold = "rust-cold" ,
128
+ rust_dash_intrinsic = "rust-intrinsic" ,
128
129
stdcall_dash_unwind = "stdcall-unwind" ,
129
130
system_dash_unwind = "system-unwind" ,
130
131
sysv64_dash_unwind = "sysv64-unwind" ,
You can’t perform that action at this time.
0 commit comments