Skip to content

transpile: replace pref_align_of with align_of in edition 2024#1656

Open
kkysen wants to merge 3 commits intomasterfrom
kkysen/transpile-edition-2024-remove-pref_align_of
Open

transpile: replace pref_align_of with align_of in edition 2024#1656
kkysen wants to merge 3 commits intomasterfrom
kkysen/transpile-edition-2024-remove-pref_align_of

Conversation

@kkysen
Copy link
Contributor

@kkysen kkysen commented Mar 12, 2026

Since core::intrinsics::pref_align_of was removed, we can't fully support __alignof/__alignof__ anymore, but using normal core::mem::align_of should still be a valid value.

This also updates tests/unit/misc to edition 2024, as its usage of __alignof__ was the only thing holding it back.

@thedataking thedataking requested a review from ahomescu March 13, 2026 07:02
Copy link
Contributor

@thedataking thedataking left a comment

Choose a reason for hiding this comment

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

The translation proposed here seems valid.

However, the translation of GNUs __alignof__ is no longer bit-for-bit faithful (e.g. __alignof__(double) == 8 but alignof(double) == 4 on i386) and the source code might rely on a particular layout via static asserts or allocation decisions. Would it make sense to emit a warning?

Copy link
Contributor Author

@kkysen kkysen left a comment

Choose a reason for hiding this comment

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

The translation proposed here seems valid.

However, the translation of GNUs __alignof__ is no longer bit-for-bit faithful (e.g. __alignof__(double) == 8 but alignof(double) == 4 on i386) and the source code might rely on a particular layout via static asserts or allocation decisions. Would it make sense to emit a warning?

Yup, we could definitely emit a warning. I didn't want to make it a hard error, but I think a warning makes a lot of sense.

@kkysen kkysen force-pushed the kkysen/transpile-edition-2024 branch from 220a2dd to 79cae37 Compare March 13, 2026 20:37
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024-remove-pref_align_of branch from d717f6a to 20c2fed Compare March 13, 2026 20:37
@kkysen kkysen requested a review from thedataking March 13, 2026 21:23
kkysen added a commit that referenced this pull request Mar 14, 2026
This fixes the following differences with edition 2024:
* [x] `#[unsafe(no_mangle)]`
* [x] `#[unsafe(export_name = "")]`
* [x] `#[unsafe(link_section = "")]`
* [x] `unsafe extern "C" {`
* [ ] `unsafe fn`s and `safe fn`s in `unsafe extern "C" {}`s
  * not required, default to `unsafe fn`s
* [x] `#![feature(stdsimd)]` removed and split up
* [x] stabilized `#![feature(raw_ref_op)]` removed
* [x] stabilized `#![feature(label_break_value)]` removed
* [x] stabilized `#![feature(asm)]` removed
* [x] `[profile.release] strip = "debuginfo"` being the default
* [ ] (#1658) updated atomic intrinsics (`atomics.c`)
* [ ] `gen` reserved keyword (`keywords.c`)
* [ ] (#1657) updated `VaListImpl` (`varargs.c`)
* [ ] `#[warn(unsafe_op_in_unsafe_fn)]` enabled by default
* In `tests/unit/`, we add `#![allow(unsafe_op_in_unsafe_fn)]` for now.
* Proper fix of an outer `unsafe` block in `unsafe fn`s (or
finer-grained ones) we can do later.
* [ ] (#1656) `pref_align_of` removed
(rust-lang/rust#141803)
  * used to translate `__alignof`
  * no alternative, so may have to drop support

This also runs the correct `rustfmt`, as we were previously just picking
up whichever one `rustup` resolved.

* Fixes #1298.

This updates all of the transpiler snapshot tests and `tests/unit/`
tests that work on edition 2024 with the above fixes. The remaining
fixes I'll fix in separate PRs, as they might be trickier.
Base automatically changed from kkysen/transpile-edition-2024 to master March 14, 2026 06:05
kkysen added 3 commits March 13, 2026 23:06
Since `core::intrinsics::pref_align_of` was removed,
we can't fully support `__alignof`/`__alignof__` anymore,
but using normal `core::mem::align_of` should still be a valid value.

This also updates `tests/unit/misc` to edition 2024,
as its usage of `__alignof__` was the only thing holding it back.
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024-remove-pref_align_of branch from 82b1b8f to 5793dbe Compare March 14, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants