Skip to content

Commit 3c7f74d

Browse files
committed
Auto merge of #9848 - lukas-code:vec-box, r=Jarcho
Fix `vec-box-size-threshold` off-by-one error The docs for `vec-box-size-threshold` say "The size of the boxed type in bytes, where boxing in a `Vec` is allowed", but previously a boxed type of exactly that size wasn't allowed in `Vec`. changelog: [`vec_box`]: Fix off-by-one error for `vec-box-size-threshold` configuration.
2 parents a599527 + b8357ff commit 3c7f74d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

clippy_lints/src/types/vec_box.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(super) fn check(
4242
if !ty_ty.has_escaping_bound_vars();
4343
if ty_ty.is_sized(cx.tcx.at(ty.span), cx.param_env);
4444
if let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes());
45-
if ty_ty_size <= box_size_threshold;
45+
if ty_ty_size < box_size_threshold;
4646
then {
4747
span_lint_and_sugg(
4848
cx,

tests/ui-toml/vec_box_sized/test.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ struct C {
77
}
88

99
struct Foo(Vec<Box<u8>>);
10-
struct Bar(Vec<Box<u32>>);
11-
struct Baz(Vec<Box<(u32, u32)>>);
10+
struct Bar(Vec<Box<u16>>);
11+
struct Quux(Vec<Box<u32>>);
12+
struct Baz(Vec<Box<(u16, u16)>>);
1213
struct BarBaz(Vec<Box<S>>);
1314
struct FooBarBaz(Vec<Box<C>>);
1415

tests/ui-toml/vec_box_sized/test.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ LL | struct Foo(Vec<Box<u8>>);
99
error: `Vec<T>` is already on the heap, the boxing is unnecessary
1010
--> $DIR/test.rs:10:12
1111
|
12-
LL | struct Bar(Vec<Box<u32>>);
13-
| ^^^^^^^^^^^^^ help: try: `Vec<u32>`
12+
LL | struct Bar(Vec<Box<u16>>);
13+
| ^^^^^^^^^^^^^ help: try: `Vec<u16>`
1414

1515
error: `Vec<T>` is already on the heap, the boxing is unnecessary
16-
--> $DIR/test.rs:13:18
16+
--> $DIR/test.rs:14:18
1717
|
1818
LL | struct FooBarBaz(Vec<Box<C>>);
1919
| ^^^^^^^^^^^ help: try: `Vec<C>`

0 commit comments

Comments
 (0)