Skip to content

Conversation

BD103
Copy link
Member

@BD103 BD103 commented May 23, 2025

Wow, Rust 1.88.0 just released, meaning we're two releases behind and need to update. This is the first of the upgrade PRs, which migrates us to nightly-2025-05-14 and clippy_utils v0.1.89.

Summary

  • Symbols are now pre-interned and available as constants in the sym module.
    • This means no more @default syntax in declare_bevy_lint_pass!.
    • Additionally, lint passes are now zero-sized types that do not need to be initialized. No more LintPass::default() when registering passes.
  • Path resolution is now cached through PathLookup.
  • A few other minors changes, such as function renames and path changes. Nothing too major!

How to Review

Unfortunately this PR isn't the easiest to review commit-by-commit. I'd recommend looking at the main diff and reading over my annotations, as that may help clarify the changes. Let me know if you have any questions!

@BD103 BD103 added A-Linter Related to the linter and custom lints C-Dependencies A change related to dependencies D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels May 23, 2025
@BD103

This comment was marked as off-topic.

@BD103

This comment was marked as off-topic.

@BD103

This comment was marked as off-topic.

@BD103 BD103 force-pushed the rust-2025-05-14 branch from 4953535 to 976b6fc Compare June 24, 2025 14:53
BD103 added 4 commits June 24, 2025 11:43
`find_crates()` now returns a slice, since it caches the results. This means it is espensive to call the function the first time, but not nearly so when executed again. Since we just care about the length of the slice, nothing changes for us.
`is_normalizable()` was originally used because `layout_of()` would panic if the type wasn't normalizable. `layout_of()` was later fixed, so the check isn't necessary anymore.

See rust-lang/rust-clippy#14717 for details.
It was removed in rust-lang/rust-clippy#14650. We can either call `Symbol::intern()` manually (which is what this commit does), or use the new preinterned symbol system (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html#structfield.extra_symbols).
It used to be re-exported in `rustc_middle::ty`, but no longer is.
@BD103 BD103 force-pushed the rust-2025-05-14 branch from bed3170 to 44671e2 Compare June 25, 2025 15:18
BD103 added 8 commits June 25, 2025 13:08
It's no longer used, now that we pre-intern symbols.
…prove docs

Turns out the compiler will ICE if there are multiple extra symbols with the same value. Additionally, `clippy_utils` depends on its extra symbols starting directly after `PREDEFINED_SYMBOLS_COUNT`, so we need to include it first.
The method got renamed, it took me _way_ too long to figure that out.

I ended up removing it entirely in `borrowed_reborrowable` since we already have access to the argument names through the function body. (This was before I realized `fn_arg_names()` wasn't just outright deleted.)

rust-lang/rust#139510
@BD103 BD103 moved this to This Week in BD103 Work Planning Jun 26, 2025
These were added after the PR was initially created.
@BD103 BD103 mentioned this pull request Jun 26, 2025
DaAlbrecht pushed a commit that referenced this pull request Jun 26, 2025
This is a little `cargo update` that makes sure our dependencies are
up-to-date! There are a few dependencies that have newer versions that
we cannot update to yet:

```sh
$ cargo update -v
    Updating crates.io index
     Locking 0 packages to latest Rust 1.88.0-nightly compatible versions
   Unchanged clippy_utils v0.1.88 (available: v0.1.89)
   Unchanged matchit v0.8.4 (available: v0.8.6)
   Unchanged rhai v1.21.0 (available: v1.22.2)
   Unchanged tempfile v3.19.1 (available: v3.20.0)
```

- `clippy_utils` will be updated #456
- `matchit` is stuck due to `axum`'s dependency on it, nothing we can do
there
- `rhai` and `tempfile` are stuck due to `cargo-generate`'s dependency
on them, also nothing to do there
@BD103 BD103 removed the status in BD103 Work Planning Jun 26, 2025
@BD103 BD103 moved this to In Progress in BD103 Work Planning Jun 27, 2025
Copy link
Member Author

Choose a reason for hiding this comment

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

CI will fail testing this action because it's trying to install the linter from the main branch, not rust-2025-05-14. This is a shortcoming of CI, and can be safely ignored!

Comment on lines +19 to +20
// Used to access the index of repeating macro input in `declare_bevy_symbols!`.
#![feature(macro_metavar_expr)]
Copy link
Member Author

Choose a reason for hiding this comment

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

The RFC for this feature is really interesting! It lets us do this kind of thing:

#[macro_export]
macro_rules! vec {
    ( $( $x:expr ),* ) => {
        {
            // `${count(x)}` counts the amount of times `$x` is specified, and evaluates to that number!
            // We can't do this in stable Rust without proc-macros, which can be quite slow.
            let mut temp_vec = Vec::with_capacity(${count(x)});
            $(
                temp_vec.push($x);
            )*
            temp_vec
        }
    };
}

In the linter I use ${index()} in declare_bevy_symbols!. Check out that for more details.

Comment on lines -167 to -171
$(
@default = {
$($default_field:ident: $default_ty:ty = $default_value:expr),* $(,)?
},
)?
Copy link
Member Author

Choose a reason for hiding this comment

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

We no longer need @default, as its primary purpose was to intern symbols we used. We now have the sym module for that!

Comment on lines -178 to -184
impl ::std::default::Default for $name {
fn default() -> Self {
Self {
$($($default_field: $default_value),*)?
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

We no longer implement Default for lint passes, as they are unit structs with no fields.

Copy link
Member Author

Choose a reason for hiding this comment

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

The underlying concept of pre-interning symbols is this:

We assign each unique string a unique number. The easiest way to do this is to count upward, meaning the first 50 strings use the numbers 0 through 49. Some numbers are already used by the Rust compiler, however, so Bevy's symbols cannot start at 0. Instead, they start at SYMBOL_OFFSET.

There is some added complexity because we need to intern clippy_utils's symbols as well, but I talk about it well in the comments. :)

/// assert_eq!(extract_value!(Name), "Name");
/// assert_eq!(extract_value!(Name: "value"), "value");
/// ```
macro_rules! extract_value {
Copy link
Member Author

Choose a reason for hiding this comment

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

This macro is purely meant to be used internally by declare_bevy_symbols!.

Comment on lines +118 to +120
add_systems,
app,
App,
Copy link
Member Author

Choose a reason for hiding this comment

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

This will result in the constants:

pub const add_systems: Symbol = Symbol::new(SYMBOL_OFFSET + 0);
pub const app: Symbol = Symbol::new(SYMBOL_OFFSET + 1);
pub const App: Symbol = Symbol::new(SYMBOL_OFFSET + 2);
// ...

Comment on lines -82 to -87
> **Important**
>
> `bevy_app::app` is a [private module], but we still have to refer to it by name because [`struct App`] is within `bevy_app/src/app.rs`. Do not be tricked by re-exported types, such as `bevy::prelude::App`!
>
> [private module]: https://docs.rs/bevy_app/0.16.0-rc.2/src/bevy_app/lib.rs.html#26
> [`struct App`]: https://docs.rs/bevy_app/0.16.0-rc.2/src/bevy_app/app.rs.html#78-88
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'm going to move this advice to a separate article about the paths module, but that's for a follow-up PR.

@BD103 BD103 marked this pull request as ready for review June 27, 2025 13:39
Copy link
Collaborator

@DaAlbrecht DaAlbrecht left a comment

Choose a reason for hiding this comment

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

Nice, thanks for all the comments, made it really easy to review.

The new symbol interning syntax needs a bit of getting used to. When reading, I would expect sym::add_systems to be a method and not a const.

tcx: TyCtxt<'tcx>,
trait_path: &[&str],
) -> impl Iterator<Item = Self> + use<'tcx> {
fn from_local_crate<'tcx, 'a>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is totally fine, we could remove the extra lifetime if we just return a Vec, but this would result in a way worse API imo.

@BD103
Copy link
Member Author

BD103 commented Jun 29, 2025

The new symbol interning syntax needs a bit of getting used to. When reading, I would expect sym::add_systems to be a method and not a const.

Yeah, I'm not used to it either yet, but I've been following Clippy's and rustc's lead for these kinds of things, so I don't think I would change it.

@BD103 BD103 enabled auto-merge (squash) June 30, 2025 17:12
@BD103 BD103 merged commit 9a24ac4 into main Jun 30, 2025
10 of 13 checks passed
@BD103 BD103 deleted the rust-2025-05-14 branch June 30, 2025 17:29
@github-project-automation github-project-automation bot moved this from In Progress to Done! in BD103 Work Planning Jun 30, 2025
DaAlbrecht pushed a commit that referenced this pull request Jul 11, 2025
Closes #506, follow up to #456.

This is a relatively simple upgrade, only two changes affected us:

- `ItemKind::Struct` and `ItemKind::Enum`'s fields were reordered.
- `GenericArg::unpack()` was renamed to `GenericArg::kind()`.

With this, we're all caught up to Rust's language latest beta language
features!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Related to the linter and custom lints C-Dependencies A change related to dependencies D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use new PathLookup type after toolchain update Pre-intern extra symbols to avoid Symbol::intern() and sym!()
2 participants