mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-30 16:39:26 +00:00
fix vec-box-size-threshold
off-by-one error
This commit is contained in:
parent
a5995279fb
commit
b8357ffd1f
3 changed files with 7 additions and 6 deletions
|
@ -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,
|
||||||
|
|
|
@ -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>>);
|
||||||
|
|
||||||
|
|
|
@ -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>`
|
||||||
|
|
Loading…
Reference in a new issue