Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22183 from ChayimFriedman2/extern-block-fn-abi
fix: Define the ABI of functions inside extern blocks as the ABI of the extern block
| -rw-r--r-- | crates/hir-def/src/expr_store/tests/signatures.rs | 14 | ||||
| -rw-r--r-- | crates/hir-def/src/signatures.rs | 26 | ||||
| -rw-r--r-- | crates/hir-ty/src/tests/method_resolution.rs | 2 | ||||
| -rw-r--r-- | crates/ide/src/hover/tests.rs | 4 |
4 files changed, 31 insertions, 15 deletions
diff --git a/crates/hir-def/src/expr_store/tests/signatures.rs b/crates/hir-def/src/expr_store/tests/signatures.rs index 5e0184dfad..24bdc6ece3 100644 --- a/crates/hir-def/src/expr_store/tests/signatures.rs +++ b/crates/hir-def/src/expr_store/tests/signatures.rs @@ -210,3 +210,17 @@ fn foo(v: for<'a> Trait1 + Trait2) {} "#]], ); } + +#[test] +fn extern_block_abi() { + lower_and_print( + r#" +extern "C" { + fn extern_fn(); +} + "#, + expect![[r#" + extern "C" fn extern_fn() {...} + "#]], + ); +} diff --git a/crates/hir-def/src/signatures.rs b/crates/hir-def/src/signatures.rs index 6d704274f4..f03ad5dae8 100644 --- a/crates/hir-def/src/signatures.rs +++ b/crates/hir-def/src/signatures.rs @@ -652,9 +652,19 @@ impl FunctionSignature { } let name = as_name_opt(source.value.name()); - let abi = source.value.abi().map(|abi| { - abi.abi_string().map_or_else(|| sym::C, |it| Symbol::intern(it.text_without_quotes())) - }); + let abi = source + .value + .abi() + .map(|abi| { + abi.abi_string() + .map_or_else(|| sym::C, |it| Symbol::intern(it.text_without_quotes())) + }) + .or_else(|| match loc.container { + ItemContainerId::ExternBlockId(extern_block) => extern_block_abi(db, extern_block), + ItemContainerId::ModuleId(_) + | ItemContainerId::ImplId(_) + | ItemContainerId::TraitId(_) => None, + }); let (store, source_map, generic_params, params, ret_type, self_param, variadic) = lower_function(db, module, source, id); if self_param { @@ -738,15 +748,7 @@ impl FunctionSignature { let data = FunctionSignature::of(db, id); data.flags.contains(FnFlags::RUSTC_INTRINSIC) // Keep this around for a bit until extern "rustc-intrinsic" abis are no longer used - || match &data.abi { - Some(abi) => *abi == sym::rust_dash_intrinsic, - None => match id.lookup(db).container { - ItemContainerId::ExternBlockId(block) => { - block.abi(db) == Some(sym::rust_dash_intrinsic) - } - _ => false, - }, - } + || data.abi.as_ref().is_some_and(|abi| *abi == sym::rust_dash_intrinsic) } } diff --git a/crates/hir-ty/src/tests/method_resolution.rs b/crates/hir-ty/src/tests/method_resolution.rs index fc8c1f8164..4291c9ba18 100644 --- a/crates/hir-ty/src/tests/method_resolution.rs +++ b/crates/hir-ty/src/tests/method_resolution.rs @@ -1193,7 +1193,7 @@ fn test() { 123..167 '{ ...o(); }': () 133..134 's': &'? S 137..151 'unsafe { f() }': &'? S - 146..147 'f': fn f() -> &'static S + 146..147 'f': extern "C" fn f() -> &'static S 146..149 'f()': &'static S 157..158 's': &'? S 157..164 's.foo()': bool diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 491471428f..89d467cef8 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -3392,7 +3392,7 @@ fn main() { let foo_test = unsafe { fo$0o(1, 2, 3); } } ``` ```rust - pub unsafe fn foo(bar: i32, ...) -> i32 + pub unsafe extern "C" fn foo(bar: i32, ...) -> i32 ``` "#]], ); @@ -9197,7 +9197,7 @@ extern "C" { ``` ```rust - unsafe fn fun() + unsafe extern "C" fn fun() ``` "#]], ); |