Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| box utils::internal_lints::OuterExpnDataPass);
store.register_late_pass(|| box utils::inspector::DeepCodeInspector);
store.register_late_pass(|| box utils::author::Author);
store.register_late_pass(|| box types::Types);
let vec_box_size_threshold = conf.vec_box_size_threshold;
store.register_late_pass(move || box types::Types::new(vec_box_size_threshold));
store.register_late_pass(|| box booleans::NonminimalBool);
store.register_late_pass(|| box eq_op::EqOp);
store.register_late_pass(|| box enum_glob_use::EnumGlobUse);
Expand Down
380 changes: 199 additions & 181 deletions clippy_lints/src/types.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ define_Conf! {
(too_many_lines_threshold, "too_many_lines_threshold", 100 => u64),
/// Lint: LARGE_STACK_ARRAYS. The maximum allowed size for arrays on the stack
(array_size_threshold, "array_size_threshold", 512_000 => u64),
/// Lint: VEC_BOX. The size of the boxed type in bytes, where boxing in a `Vec` is allowed
(vec_box_size_threshold, "vec_box_size_threshold", 4096 => u64),
}

impl Default for Conf {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `third-party` at line 5 column 1
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `third-party` at line 5 column 1

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/vec_box_sized/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vec-box-size-threshold = 4
15 changes: 15 additions & 0 deletions tests/ui-toml/vec_box_sized/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
struct S {
x: u64,
}

struct C {
y: u16,
}

struct Foo(Vec<Box<u8>>);
struct Bar(Vec<Box<u32>>);
struct Baz(Vec<Box<(u32, u32)>>);
struct BarBaz(Vec<Box<S>>);
struct FooBarBaz(Vec<Box<C>>);

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui-toml/vec_box_sized/test.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: `Vec<T>` is already on the heap, the boxing is unnecessary.
--> $DIR/test.rs:9:12
|
LL | struct Foo(Vec<Box<u8>>);
| ^^^^^^^^^^^^ help: try: `Vec<u8>`
|
= note: `-D clippy::vec-box` implied by `-D warnings`

error: `Vec<T>` is already on the heap, the boxing is unnecessary.
--> $DIR/test.rs:10:12
|
LL | struct Bar(Vec<Box<u32>>);
| ^^^^^^^^^^^^^ help: try: `Vec<u32>`

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

error: aborting due to 3 previous errors

4 changes: 3 additions & 1 deletion tests/ui/vec_box_sized.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

struct SizedStruct(i32);
struct UnsizedStruct([i32]);
struct BigStruct([i32; 10000]);

/// The following should trigger the lint
mod should_trigger {
Expand All @@ -19,9 +20,10 @@ mod should_trigger {

/// The following should not trigger the lint
mod should_not_trigger {
use super::UnsizedStruct;
use super::{BigStruct, UnsizedStruct};

struct C(Vec<Box<UnsizedStruct>>);
struct D(Vec<Box<BigStruct>>);

struct StructWithVecBoxButItsUnsized {
unsized_type: Vec<Box<UnsizedStruct>>,
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/vec_box_sized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

struct SizedStruct(i32);
struct UnsizedStruct([i32]);
struct BigStruct([i32; 10000]);

/// The following should trigger the lint
mod should_trigger {
Expand All @@ -19,9 +20,10 @@ mod should_trigger {

/// The following should not trigger the lint
mod should_not_trigger {
use super::UnsizedStruct;
use super::{BigStruct, UnsizedStruct};

struct C(Vec<Box<UnsizedStruct>>);
struct D(Vec<Box<BigStruct>>);

struct StructWithVecBoxButItsUnsized {
unsized_type: Vec<Box<UnsizedStruct>>,
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/vec_box_sized.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
error: `Vec<T>` is already on the heap, the boxing is unnecessary.
--> $DIR/vec_box_sized.rs:13:21
--> $DIR/vec_box_sized.rs:14:21
|
LL | sized_type: Vec<Box<SizedStruct>>,
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
|
= note: `-D clippy::vec-box` implied by `-D warnings`

error: `Vec<T>` is already on the heap, the boxing is unnecessary.
--> $DIR/vec_box_sized.rs:16:14
--> $DIR/vec_box_sized.rs:17:14
|
LL | struct A(Vec<Box<SizedStruct>>);
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`

error: `Vec<T>` is already on the heap, the boxing is unnecessary.
--> $DIR/vec_box_sized.rs:17:18
--> $DIR/vec_box_sized.rs:18:18
|
LL | struct B(Vec<Vec<Box<(u32)>>>);
| ^^^^^^^^^^^^^^^ help: try: `Vec<u32>`
Expand Down