diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-17 21:53:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-17 21:53:24 +0200 |
| commit | 8b7a2897c87b875ef55d403efccac4b0cc354e16 (patch) | |
| tree | 4f74dc022d5c5b9a7be5715bfd924d92db6802f4 | |
| parent | b6e48d38503a6c25ee55658ff73d6dfe09969f87 (diff) | |
| parent | f9091e24a0af713378ee705c86689c1435d0b157 (diff) | |
| download | rust-8b7a2897c87b875ef55d403efccac4b0cc354e16.tar.gz rust-8b7a2897c87b875ef55d403efccac4b0cc354e16.zip | |
Rollup merge of #139498 - alexcrichton:wasm-zst-safe, r=wesleywiser
Ignore zero-sized types in wasm future-compat warning This commit fixes a false positive of the warning triggered for #138762 and the fix is to codify that zero-sized types are "safe" in both the old and new ABIs.
| -rw-r--r-- | compiler/rustc_monomorphize/src/mono_checks/abi_check.rs | 5 | ||||
| -rw-r--r-- | tests/ui/lint/wasm_c_abi_transition.rs | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs index 0f5bdc8d768..94ee34c8b7b 100644 --- a/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs +++ b/compiler/rustc_monomorphize/src/mono_checks/abi_check.rs @@ -111,6 +111,11 @@ fn wasm_abi_safe<'tcx>(tcx: TyCtxt<'tcx>, arg: &ArgAbi<'tcx, Ty<'tcx>>) -> bool } } + // Zero-sized types are dropped in both ABIs, so they're safe + if arg.layout.is_zst() { + return true; + } + false } diff --git a/tests/ui/lint/wasm_c_abi_transition.rs b/tests/ui/lint/wasm_c_abi_transition.rs index 1fe81679e65..6a933a0de03 100644 --- a/tests/ui/lint/wasm_c_abi_transition.rs +++ b/tests/ui/lint/wasm_c_abi_transition.rs @@ -39,3 +39,9 @@ pub fn call_other_fun(x: MyType) { unsafe { other_fun(x) } //~ERROR: wasm ABI transition //~^WARN: previously accepted } + +// Zero-sized types are safe in both ABIs +#[repr(C)] +pub struct MyZstType; +#[allow(improper_ctypes_definitions)] +pub extern "C" fn zst_safe(_x: (), _y: MyZstType) {} |
