Skip to content

Revert r-a changes of rust-lang/rust#139455 #139496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/tools/rust-analyzer/crates/hir-ty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ pub enum FnAbi {
Rust,
RustCall,
RustCold,
RustIntrinsic,
Stdcall,
StdcallUnwind,
System,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion src/tools/rust-analyzer/crates/hir-ty/src/mir/eval/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 20 additions & 6 deletions src/tools/rust-analyzer/crates/hir-ty/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const SUPPORTED_CALLING_CONVENTIONS: &[&str] = &[
"wasm",
"system",
"system-unwind",
"rust-intrinsic",
"rust-call",
"unadjusted",
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading