Skip to content

transpile: upgrade most things for edition 2024#1643

Open
kkysen wants to merge 39 commits intomasterfrom
kkysen/transpile-edition-2024
Open

transpile: upgrade most things for edition 2024#1643
kkysen wants to merge 39 commits intomasterfrom
kkysen/transpile-edition-2024

Conversation

@kkysen
Copy link
Contributor

@kkysen kkysen commented Mar 6, 2026

This fixes the following differences with edition 2024:

  • #[unsafe(no_mangle)]
  • #[unsafe(export_name = "")]
  • #[unsafe(link_section = "")]
  • unsafe extern "C" {
  • unsafe fns and safe fns in unsafe extern "C" {}s
    • not required, default to unsafe fns
  • #![feature(stdsimd)] removed and split up
  • stabilized #![feature(raw_ref_op)] removed
  • stabilized #![feature(label_break_value)] removed
  • stabilized #![feature(asm)] removed
  • [profile.release] strip = "debuginfo" being the default
  • updated atomic intrinsics (atomics.c)
  • gen reserved keyword (keywords.c)
  • 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 fns (or finer-grained ones) we can do later.
  • pref_align_of removed (Remove rustc's notion of "preferred" alignment AKA __alignof 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.

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.

@kkysen kkysen force-pushed the kkysen/transpile-tests-separate-snapshot-tests branch from f86aec4 to d1ae9eb Compare March 6, 2026 08:32
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024 branch from 19c6138 to db5a90e Compare March 6, 2026 08:34
@kkysen kkysen force-pushed the kkysen/transpile-tests-separate-snapshot-tests branch from d1ae9eb to 02b9ca2 Compare March 6, 2026 08:36
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024 branch 5 times, most recently from 73c45e4 to 1a4774e Compare March 6, 2026 13:18
@Rua
Copy link
Contributor

Rua commented Mar 6, 2026

In the 2024 edition, the unsafe-op-in-unsafe-fn lint now also warns by default. A simple fix could be to just add an extra unsafe { } block to each function, but ultimately marking only the actual unsafe operations as unsafe could be preferred.

@kkysen kkysen force-pushed the kkysen/transpile-edition-2024 branch 3 times, most recently from 9af29df to 43f7566 Compare March 6, 2026 22:54
@kkysen kkysen force-pushed the kkysen/transpile-tests-separate-snapshot-tests branch from 02b9ca2 to b3ab33d Compare March 6, 2026 22:56
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024 branch 2 times, most recently from 5ecf3f2 to 6d4cba2 Compare March 6, 2026 23:20
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.

In the 2024 edition, the unsafe-op-in-unsafe-fn lint now also warns by default. A simple fix could be to just add an extra unsafe { } block to each function, but ultimately marking only the actual unsafe operations as unsafe could be preferred.

It's still just a warning, and we have plenty of warnings already, so I don't think I'll fix it as part of this PR, but you're right, we should fix it. We can do an outer unsafe {} block first, and if possible, narrow it.

@kkysen kkysen force-pushed the kkysen/transpile-edition-2024 branch 2 times, most recently from 2273281 to a70695c Compare March 6, 2026 23:51
Base automatically changed from kkysen/transpile-tests-separate-snapshot-tests to master March 6, 2026 23:52
kkysen added 10 commits March 7, 2026 16:43
This will help as I'm upgrading to edition 2024 and fix errors one by one.
…rustc`

`nightly-2023-04-15` doesn't know about edition 2024 yet.

Previously, `rustfmt` wasn't using a specific toolchain,
so it would just default to whatever `rust-toolchain.toml` was there.
Now it properly is overridden like `rustc` was being.
…m scratch with the right toolchain

`generated-rust-toolchain.toml` is very simple, so embedding it should be fine.
We previously didn't since `test_translator.py` just copied it,
since it doesn't use `--emit-build-files`, for *reasons*.
But now that the toolchain depends on the edition, we can't do that.
So we just duplicate the simple logic in `fn emit_rust_toolchain`.
These are `incomplete_arrays.c` and `main_fn.c`.
kkysen added 20 commits March 7, 2026 16:43
…ion = "")]` in edition 2024

This reworks the previous basic support for `#[unsafe(no_mangle)]` to make it more robust.
`fn Builder::meta` is added, which checks `self.unsafety`,
and if it's `unsafe`, adds a wrapper `unsafe()` around the meta.
This is then used in all of the `mk().meta_*` functions to ensure they use the `unsafe` wrapping.
It has to be done at this level because sometimes these `unsafe`s aren't at the top-level,
like `#[cfg_attr(target_os = "linux", unsafe(link_section = ".init_array"))]`.
* Fixes #1298.

Luckily, I left comments saying how to do this in more recent Rust versions.
We still haven't fixed the missing `cfg_attr` in
`#![cfg_attr(target_arch = "arm", stdarch_arm_neon_intrinsics)]`
when using `self.use_feature`, but we're
not testing `target_arch = "arm"` at the moment.
…e suffixes so that related files are next to each
This easy to do, gives better test coverage,
and allows us to see the failing snapshots on edition 2024
for tests that haven't been converted yet.
…`test_*.rs` files

This allows us to move individual test directories to edition 2024.
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024 branch from b4012b2 to 2810fc6 Compare March 8, 2026 00:43
@kkysen kkysen force-pushed the kkysen/transpile-edition-2024 branch from 2050f67 to 9bbfccc Compare March 8, 2026 01:02
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.

#![feature(stdsimd)] was split up and removed in 1.78, so stop emitting it when we upgrade past 1.65

2 participants