Skip to content

Commit

Permalink
bevy_asset: Apply `#![deny(clippy::allow_attributes, clippy::allow_at…
Browse files Browse the repository at this point in the history
…tributes_without_reason)]` (#17113)

# Objective
- #17111

## 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.
  • Loading branch information
LikeLakers2 authored Jan 6, 2025
1 parent f64f3ac commit b386d08
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/asset_changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub struct AssetChangedState<A: AsAssetId> {
_asset: PhantomData<fn(A)>,
}

#[allow(unsafe_code)]
#[expect(unsafe_code, reason = "WorldQuery is an unsafe trait.")]
/// SAFETY: `ROQueryFetch<Self>` is the same as `QueryFetch<Self>`
unsafe impl<A: AsAssetId> WorldQuery for AssetChanged<A> {
type Item<'w> = ();
Expand Down Expand Up @@ -264,7 +264,7 @@ unsafe impl<A: AsAssetId> WorldQuery for AssetChanged<A> {
}
}

#[allow(unsafe_code)]
#[expect(unsafe_code, reason = "QueryFilter is an unsafe trait.")]
/// SAFETY: read-only access
unsafe impl<A: AsAssetId> QueryFilter for AssetChanged<A> {
const IS_ARCHETYPAL: bool = false;
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,11 @@ mod tests {
}

/// Typed and Untyped `Handles` should be orderable amongst each other and themselves
#[allow(clippy::cmp_owned)]
#[test]
#[expect(
clippy::cmp_owned,
reason = "This lints on the assertion that a typed handle converted to an untyped handle maintains its ordering compared to an untyped handle. While the conversion would normally be useless, we need to ensure that converted handles maintain their ordering, making the conversion necessary here."
)]
fn ordering() {
assert!(UUID_1 < UUID_2);

Expand Down
12 changes: 9 additions & 3 deletions crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@
//! This trait mirrors [`AssetLoader`] in structure, and works in tandem with [`AssetWriter`](io::AssetWriter), which mirrors [`AssetReader`](io::AssetReader).
#![expect(missing_docs, reason = "Not all docs are written yet, see #3492.")]
#![deny(
clippy::allow_attributes,
clippy::allow_attributes_without_reason,
reason = "See #17111; To be removed once all crates are in-line with these attributes"
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc(
html_logo_url = "https://bevyengine.org/assets/icon.png",
Expand Down Expand Up @@ -1767,8 +1772,11 @@ mod tests {
#[derive(Asset, TypePath)]
pub struct TestAsset;

#[allow(dead_code)]
#[derive(Asset, TypePath)]
#[expect(
dead_code,
reason = "This exists to ensure that `#[derive(Asset)]` works on enums. The inner variants are known not to be used."
)]
pub enum EnumTestAsset {
Unnamed(#[dependency] Handle<TestAsset>),
Named {
Expand All @@ -1783,7 +1791,6 @@ mod tests {
Empty,
}

#[allow(dead_code)]
#[derive(Asset, TypePath)]
pub struct StructTestAsset {
#[dependency]
Expand All @@ -1792,7 +1799,6 @@ mod tests {
embedded: TestAsset,
}

#[allow(dead_code)]
#[derive(Asset, TypePath)]
pub struct TupleTestAsset(#[dependency] Handle<TestAsset>);
}
1 change: 0 additions & 1 deletion crates/bevy_asset/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ impl AssetProcessor {
self.set_state(ProcessorState::Finished).await;
}

#[allow(unused)]
#[cfg(all(not(target_arch = "wasm32"), feature = "multi_threaded"))]
async fn process_assets_internal<'scope>(
&'scope self,
Expand Down
10 changes: 3 additions & 7 deletions crates/bevy_asset/src/server/loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,14 @@ mod tests {

use super::*;

// The compiler notices these fields are never read and raises a dead_code lint which kill CI.
#[allow(dead_code)]
#[derive(Asset, TypePath, Debug)]
struct A(usize);
struct A;

#[allow(dead_code)]
#[derive(Asset, TypePath, Debug)]
struct B(usize);
struct B;

#[allow(dead_code)]
#[derive(Asset, TypePath, Debug)]
struct C(usize);
struct C;

struct Loader<A: Asset, const N: usize, const E: usize> {
sender: Sender<()>,
Expand Down

0 comments on commit b386d08

Please sign in to comment.