Skip to content

unit_in_bundle should look within function parameter types #660

@BD103

Description

@BD103

What problem does this solve or what need does it fill?

Code like this will not trigger unit_in_bundle:

fn bundle_in_array<B: Bundle>(array: [B; 2]) {
    // ...
}

fn main() {
    // No lint triggered here because we're not passing a bundle, but an array of bundles,
    // to the function.
    bundle_in_array([(), ()]);
}

This is because array is an array type, not a B: Bundle type, so the lint skips it. Code like this as well:

fn spawn_batch<I>(_batch: I)
where
    I: IntoIterator + Send + Sync + 'static,
    I::Item: Bundle<Effect: NoBundleEffect>,
{
}

fn main() {
    let _ = spawn_batch(std::iter::once(()));
}

What solution would you like?

unit_in_bundle should inspect the generic parameters of types within the function signature, and use that to look for bundles as well.

What alternative(s) have you considered?

The current solution catches most cases. This feels like a "nice-to-have" feature, as I'm not sure how strong the need is.

Additional context

Raised as part of the #659 review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LinterRelated to the linter and custom lintsC-FeatureMake something new possibleD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions