Skip to content

Ignore zero-sized types in wasm future-compat warning #139498

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 18, 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
5 changes: 5 additions & 0 deletions compiler/rustc_monomorphize/src/mono_checks/abi_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment on lines +114 to +117
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not actually a stable guarantee, nobody should rely on this...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this at least respects the status quo where the purpose of the wasm_c_abi warning is "this will change" and for ZSTs behavior isn't changing.

Otherwise though for relying on ZSTs, I know wasm-bindgen definitely does rely on ZSTs getting dropped at the ABI level, and AFAIK it's quite difficult to remove the reliance. I can't speak for other projects though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for ZSTs behavior isn't changing.

Yeah, that's a fair point, we don't have to warn about them.

But it seems quite concerning that wasm-bindgen would rely on unstable undocumented ABI guarantees without (apparently) any effort to make those things into stable guarantees. We don't guarantee that ZST are skipped in any form for any ABI, and I'm not even aware of an issue someone opened asking for this as a guarantee.


false
}

Expand Down
6 changes: 6 additions & 0 deletions tests/ui/lint/wasm_c_abi_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Loading