RS.CLIPPY.VEC_BOX

Usage of `Vec<Box<T>>` where T: Sized, vector elements are already on the heap

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: vec_box. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for usage of Vec<Box<T>> where T: Sized anywhere in the code. Check the Box documentation for more information.

Why is this bad?

Vec already keeps its contents in a separate area on the heap. So if you Box its contents, you just add another level of indirection.

Example

struct X {
    values: Vec<Box<i32>>,
}

Better:

struct X {
    values: Vec<i32>,
}

Configuration

  • avoid-breaking-exported-api: Suppress lints whenever the suggested change would cause breakage for other crates.

    (default: true)

  • vec-box-size-threshold: The size of the boxed type in bytes, where boxing in a Vec is allowed

    (default: 4096)