Skip to content

Conversation

DaAlbrecht
Copy link
Collaborator

@DaAlbrecht DaAlbrecht commented Sep 10, 2025

Objective

This new lint checks if a unit structures that implement Component also implements the following traits:

  • Clone
  • Copy
  • Default

Note

With how this is set up, if a Component does not implement any of those there will be a lint output for each trait on its own, this also applies to the fix.

Example

use bevy::prelude::*;

#[derive(Component)]
pub struct ImplCopy;
[package.metadata.bevy_lint]
missing_default = "warn"
missing_copy = "warn"
missing_clone = "warn"
lint output
❯ bevy_lint
    Checking test_project v0.1.0 (/tmp/test_project)
warning: defined a unit struct without a `Copy` implementation
 --> src/main.rs:4:1
  |
4 | pub struct ImplCopy;
  | ^^^^^^^^^^^^^^^^^^^^
  |
note: `Component` implemented here
 --> src/main.rs:3:10
  |
3 | #[derive(Component)]
  |          ^^^^^^^^^
  = note: requested on the command line with `-W bevy::missing-copy`
  = note: this warning originates in the derive macro `Component` (in Nightly builds, run with -Z macro-backtrace for more info)
help: `Copy` can be automatically derived
  |
4 + #[derive(Copy)]
5 | pub struct ImplCopy;
  |

warning: defined a unit struct without a `Clone` implementation
 --> src/main.rs:4:1
  |
4 | pub struct ImplCopy;
  | ^^^^^^^^^^^^^^^^^^^^
  |
note: `Component` implemented here
 --> src/main.rs:3:10
  |
3 | #[derive(Component)]
  |          ^^^^^^^^^
  = note: requested on the command line with `-W bevy::missing-clone`
  = note: this warning originates in the derive macro `Component` (in Nightly builds, run with -Z macro-backtrace for more info)
help: `Clone` can be automatically derived
  |
4 + #[derive(Clone)]
5 | pub struct ImplCopy;
  |

warning: defined a unit struct without a `Default` implementation
 --> src/main.rs:4:1
  |
4 | pub struct ImplCopy;
  | ^^^^^^^^^^^^^^^^^^^^
  |
note: `Component` implemented here
 --> src/main.rs:3:10
  |
3 | #[derive(Component)]
  |          ^^^^^^^^^
  = note: requested on the command line with `-W bevy::missing-default`
  = note: this warning originates in the derive macro `Component` (in Nightly builds, run with -Z macro-backtrace for more info)
help: `Default` can be automatically derived
  |
4 + #[derive(Default)]
5 | pub struct ImplCopy;
  |

warning: `test_project` (bin "test_project") generated 3 warnings (run `cargo fix --bin "test_project"` to apply 3 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.30s

bevy_lint --fix will result in the following:

use bevy::prelude::*;

#[derive(Component)]
#[derive(Default)]
#[derive(Clone)]
#[derive(Copy)]
pub struct ImplCopy;

fn main() {}

and after cargo fmg:

use bevy::prelude::*;

#[derive(Component, Default, Clone, Copy)]
pub struct ImplCopy;

fn main() {}

Closes #211, #344

@DaAlbrecht DaAlbrecht added A-Linter Related to the linter and custom lints D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Sep 10, 2025
@DaAlbrecht DaAlbrecht changed the title Add Linit: Unit components are missing Default implementation Add Linit: missing_trait_impls Sep 24, 2025
@DaAlbrecht DaAlbrecht marked this pull request as ready for review September 24, 2025 20:34
@DaAlbrecht DaAlbrecht added S-Needs-Review The PR needs to be reviewed before it can be merged and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Oct 5, 2025
}

impl Trait {
const fn all() -> [Trait; 3] {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not want to create our own proc macro for this / use an extra crate but it's rather sad that there is no built-in way to do this.

@BD103 BD103 self-requested a review October 5, 2025 18:23
@BD103 BD103 linked an issue Oct 13, 2025 that may be closed by this pull request
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 D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review The PR needs to be reviewed before it can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add lint: implement Default for schedule labels Lint: Unit components should implement Default

1 participant