Skip to content

Migrate to Rust 2024 edition#3515

Merged
stevenengler merged 12 commits intoshadow:mainfrom
stevenengler:2024-edition
Feb 27, 2025
Merged

Migrate to Rust 2024 edition#3515
stevenengler merged 12 commits intoshadow:mainfrom
stevenengler:2024-edition

Conversation

@stevenengler
Copy link
Copy Markdown
Contributor

@stevenengler stevenengler commented Feb 23, 2025

We don't technically need to upgrade the edition, but I think we might as well get this out of the way so that we use the modern capture rules, scopes, etc. I didn't use cargo fix for any of this.

There are some changes regarding capture rules, drop order, lifetime scopes, etc:
https://doc.rust-lang.org/edition-guide/rust-2024/language.html

A possible issue is that we have a lot of unsafe code and some may have relied on the old behaviour, which is now changed in rust 2025. But the updated code builds and passes all tests, so it's probably (hopefully) fine. I looked through the changes briefly, and I think it's unlikely that any broke our unsafe code.

Rustfmt now has "style editions". By upgrading rust editions, cargo automatically uses the new rustfmt style edition. This does have quite a bit of code churn. I think we could avoid this by specifying style_edition = "2021" in a rustfmt.toml file, but I decided to just do a rustfmt here using the latest (default) style edition. We can easily revert this before merging if anyone wants.

Edit: lint-cargo-lock requires actions/runner-images#11637, but maybe it would be better to use the rust version we specify in ci/rust-toolchain-stable.toml. The downside would be longer a workflow run time.

@stevenengler stevenengler self-assigned this Feb 23, 2025
@github-actions github-actions bot added Component: Libraries Support functions like LD_PRELOAD and logging Component: Testing Unit and integration tests and frameworks Component: Main Composing the core Shadow executable Component: Build Build/install tools and dependencies labels Feb 23, 2025
@stevenengler stevenengler requested a review from a team February 23, 2025 06:09
Copy link
Copy Markdown
Contributor

@sporksmith sporksmith left a comment

Choose a reason for hiding this comment

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

LGTM. I think the auto-formatting changes are an improvement and worth the churn.

This does not include uses of "gen" by other libraries (for example
`rand::Rng::gen`).
This won't yet build. We'll fix the build issues in follow-up commits.
The default binding mode was changed to "ref" in rust 2021, and now in
rust 2024 it's an error to use the `ref` binding modifier when the
binding mode is already "ref".

For example:

```text
error: binding modifiers may only be written when the default binding mode is `move`
   --> lib/tcp/src/buffer.rs:347:27
    |
347 |             Segment::Data(ref data) => data.len().try_into().unwrap(),
    |                           ^^^ binding modifier not allowed under `ref` default binding mode
    |
    = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>
```
```text
error[E0716]: temporary value dropped while borrowed
   --> lib/shim/src/signals.rs:119:13
    |
118 |           let action = tls_process_shmem::with(|process| *unsafe {
    |  ________________________________________________________-
119 | |             process.protected.borrow(&host_lock.root).signal_action(sig)
    | |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                  - temporary value is freed at the end of this statement
    | |             |
    | |             creates a temporary value which is freed while still in use
120 | |         });
    | |_________- borrow later used here
```
This is unrelated to the rust 2024 migration, but I noticed this so
decided to change it.
Lots of code churn here ¯\_(ツ)_/¯
@stevenengler stevenengler merged commit 8d2cad4 into shadow:main Feb 27, 2025
25 checks passed
@stevenengler stevenengler deleted the 2024-edition branch February 27, 2025 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Build Build/install tools and dependencies Component: Libraries Support functions like LD_PRELOAD and logging Component: Main Composing the core Shadow executable Component: Testing Unit and integration tests and frameworks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants