Skip to content

Commit 3054d6f

Browse files
committed
Add test for Box<Vec<T>> with known layout
1 parent 6667ea1 commit 3054d6f

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

tests/ui/unnecessary_box_returns.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ fn generic_element_array<T>(value: Box<[T; 10]>) -> Box<[T; 10]> {
8181
value
8282
}
8383

84+
// lint: the size of `Vec<T>` is known regardless of the generic element type
85+
#[expect(clippy::box_collection)]
86+
fn generic_vec<T>(value: Box<Vec<T>>) -> Box<Vec<T>> {
87+
//~^ unnecessary_box_returns
88+
value
89+
}
90+
8491
fn main() {
8592
// don't lint: this is a closure
8693
let a = || -> Box<usize> { Box::new(5) };

tests/ui/unnecessary_box_returns.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,13 @@ LL | fn _bxed_foo() -> Box<Foo> {
3232
|
3333
= help: changing this also requires a change to the return expressions in this function
3434

35-
error: aborting due to 4 previous errors
35+
error: boxed return of the sized type `std::vec::Vec<T>`
36+
--> tests/ui/unnecessary_box_returns.rs:86:42
37+
|
38+
LL | fn generic_vec<T>(value: Box<Vec<T>>) -> Box<Vec<T>> {
39+
| ^^^^^^^^^^^ help: try: `std::vec::Vec<T>`
40+
|
41+
= help: changing this also requires a change to the return expressions in this function
42+
43+
error: aborting due to 5 previous errors
3644

0 commit comments

Comments
 (0)