fix vec-box-size-threshold off-by-one error

This commit is contained in:
Lukas Markeffsky 2022-11-14 16:06:21 +01:00
parent a5995279fb
commit b8357ffd1f
3 changed files with 7 additions and 6 deletions

View file

@ -42,7 +42,7 @@ pub(super) fn check(
if !ty_ty.has_escaping_bound_vars(); if !ty_ty.has_escaping_bound_vars();
if ty_ty.is_sized(cx.tcx.at(ty.span), cx.param_env); if ty_ty.is_sized(cx.tcx.at(ty.span), cx.param_env);
if let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes()); if let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes());
if ty_ty_size <= box_size_threshold; if ty_ty_size < box_size_threshold;
then { then {
span_lint_and_sugg( span_lint_and_sugg(
cx, cx,

View file

@ -7,8 +7,9 @@ struct C {
} }
struct Foo(Vec<Box<u8>>); struct Foo(Vec<Box<u8>>);
struct Bar(Vec<Box<u32>>); struct Bar(Vec<Box<u16>>);
struct Baz(Vec<Box<(u32, u32)>>); struct Quux(Vec<Box<u32>>);
struct Baz(Vec<Box<(u16, u16)>>);
struct BarBaz(Vec<Box<S>>); struct BarBaz(Vec<Box<S>>);
struct FooBarBaz(Vec<Box<C>>); struct FooBarBaz(Vec<Box<C>>);

View file

@ -9,11 +9,11 @@ LL | struct Foo(Vec<Box<u8>>);
error: `Vec<T>` is already on the heap, the boxing is unnecessary error: `Vec<T>` is already on the heap, the boxing is unnecessary
--> $DIR/test.rs:10:12 --> $DIR/test.rs:10:12
| |
LL | struct Bar(Vec<Box<u32>>); LL | struct Bar(Vec<Box<u16>>);
| ^^^^^^^^^^^^^ help: try: `Vec<u32>` | ^^^^^^^^^^^^^ help: try: `Vec<u16>`
error: `Vec<T>` is already on the heap, the boxing is unnecessary error: `Vec<T>` is already on the heap, the boxing is unnecessary
--> $DIR/test.rs:13:18 --> $DIR/test.rs:14:18
| |
LL | struct FooBarBaz(Vec<Box<C>>); LL | struct FooBarBaz(Vec<Box<C>>);
| ^^^^^^^^^^^ help: try: `Vec<C>` | ^^^^^^^^^^^ help: try: `Vec<C>`