Skip to content
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

bevy_asset: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] #17113

Conversation

LikeLakers2
Copy link
Contributor

@LikeLakers2 LikeLakers2 commented Jan 3, 2025

Objective

Solution

Set the clippy::allow_attributes and clippy::allow_attributes_without_reason lints to deny, and bring bevy_asset in line with the new restrictions.

No code changes have been made - except if a lint that was previously allow(...)'d could be removed via small code changes. For example, unused_variables can be handled by adding a _ to the beginning of a field's name.

Testing

cargo clippy and cargo test --package bevy_asset --features multi_threaded were run, and no errors were encountered.

#[expect(
dead_code,
reason = "This exists to ensure that `#[derive(Asset)]` works on enums. The inner variants are known not to be used."
)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea why this only lints on the enum test case, despite the struct test cases also being unused.

#[derive(Asset, TypePath, Debug)]
struct A(usize);
struct A;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case you're wondering: I checked and double-checked to make sure that removing these usize fields wouldn't affect tests.

If they affect tests, I didn't see it during my testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the tests are meant to test specifically unit struct assets. Unit struct assets don't sound very useful anyway.

Copy link
Contributor Author

@LikeLakers2 LikeLakers2 Jan 3, 2025

Choose a reason for hiding this comment

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

Sure, but... The tests compile and finish successfully either way.

Really, the (usize) only confuses people into thinking that we're somehow constructing instances of the structs. Except, we're not - the structs are only used as type parameters.

If we start needing a value, they can be added back.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's true that as far as I can see there seems to be no behavior in the tests hinging on the structs having any fields. However, idk if they're relevant for TypeId calculations.
It would be best to ask someone who wrote this or knows about reflection.

Copy link
Contributor Author

@LikeLakers2 LikeLakers2 Jan 4, 2025

Choose a reason for hiding this comment

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

@IQuick143 I don't believe they're relevant for TypeId calculations: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=99bbd15c51d685da51caa2a4beecf51b

I mean, it appears that changing one to include (usize) does change its TypeId - but two unit structs still have two different TypeIds.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, I think this fix is good :)

crates/bevy_asset/src/server/loaders.rs Outdated Show resolved Hide resolved
#[derive(Asset, TypePath, Debug)]
struct A(usize);
struct A;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the tests are meant to test specifically unit struct assets. Unit struct assets don't sound very useful anyway.

@BenjaminBrienen
Copy link
Contributor

In benches, we silence dead code warnings due to similar dead_code unit tests in this PR.

@BenjaminBrienen
Copy link
Contributor

It's fine to me if we fix the dead code warning by removing the fields, but I wonder if it might make sense to instead use those fields in the unit tests. If not, nevermind me.

@LikeLakers2
Copy link
Contributor Author

LikeLakers2 commented Jan 3, 2025

@BenjaminBrienen Adding a new test that uses those fields would probably make more sense - but the addition of tests is out-of-scope for this PR.

@LikeLakers2 LikeLakers2 changed the title bevy_asset: Apply #[deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] bevy_asset: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] Jan 4, 2025
@TimJentzsch TimJentzsch added C-Code-Quality A section of code that is hard to understand or change S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 5, 2025
@LikeLakers2 LikeLakers2 force-pushed the lint/deny_allow_and_without_reason/bevy_asset branch from a1bf6e0 to 53bc757 Compare January 6, 2025 18:15
@IQuick143 IQuick143 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 6, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 6, 2025
Merged via the queue into bevyengine:main with commit b386d08 Jan 6, 2025
29 checks passed
@LikeLakers2 LikeLakers2 deleted the lint/deny_allow_and_without_reason/bevy_asset branch January 6, 2025 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants