Skip to content

unnecessary_box_returns is sometimes confused about generics #17202

@nazar-pc

Description

@nazar-pc

Summary

While #10641 was resolved, current implementation still produces false-positives in presence of generics.

Lint Name

unnecessary_box_returns

Reproducer

I don't have a reduced example yet, but it is triggered in 3 places in this file (note alloc feature if you try to reproduce it): https://github.com/nazar-pc/abundance/blob/9148aeec063525ccea2eddd0086582efd02381a5/crates/shared/ab-proof-of-space/src/chiapos/table.rs#L103

warning: boxed return of the sized type `[T; N]`
   --> crates/shared/ab-proof-of-space/src/chiapos/table.rs:103:85
    |
103 | fn strip_sync_unsafe_cell<const N: usize, T>(value: Box<[SyncUnsafeCell<T>; N]>) -> Box<[T; N]> {
    |                                                                                     ^^^^^^^^^^^ help: try: `[T; N]`
    |
    = help: changing this also requires a change to the return expressions in this function
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns
    = note: `-W clippy::unnecessary-box-returns` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::unnecessary_box_returns)]`

warning: boxed return of the sized type `[[(chiapos::table::types::Position, chiapos::table::types::Y); REDUCED_BUCKET_SIZE]; num_buckets(K)]`
   --> crates/shared/ab-proof-of-space/src/chiapos/table.rs:175:6
    |
175 | ) -> Box<[[(Position, Y); REDUCED_BUCKET_SIZE]; num_buckets(K)]>
    |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[[(chiapos::table::types::Position, chiapos::table::types::Y); REDUCED_BUCKET_SIZE]; num_buckets(K)]`
    |
    = help: changing this also requires a change to the return expressions in this function
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns

warning: boxed return of the sized type `[[(chiapos::table::types::Position, chiapos::table::types::Y); REDUCED_BUCKET_SIZE]; num_buckets(K)]`
   --> crates/shared/ab-proof-of-space/src/chiapos/table.rs:216:6
    |
216 | ) -> Box<[[(Position, Y); REDUCED_BUCKET_SIZE]; num_buckets(K)]>
    |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `[[(chiapos::table::types::Position, chiapos::table::types::Y); REDUCED_BUCKET_SIZE]; num_buckets(K)]`
    |
    = help: changing this also requires a change to the return expressions in this function
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns

For example, [(Position, Y); REDUCED_BUCKET_SIZE] is equivalent to [(u32, u32); 272], which is certainly large enough to justify putting it into a Box.

I tried extracting just strip_sync_unsafe_cell, but it didn't trigger the lint in isolation, so something more complex is going on here.

Version

rustc 1.97.0-nightly (20de910db 2026-05-02)
binary: rustc
commit-hash: 20de910db49d3476ccf49ea79a4b22e2b5dface0
commit-date: 2026-05-02
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions