Reduce default 'large array' threshold
This commit is contained in:
parent
4b7c19018d
commit
26994e2519
@ -329,7 +329,7 @@ arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"]
|
||||
## `array-size-threshold`
|
||||
The maximum allowed size for arrays on the stack
|
||||
|
||||
**Default Value:** `512000`
|
||||
**Default Value:** `16384`
|
||||
|
||||
---
|
||||
**Affected lints:**
|
||||
|
@ -366,7 +366,7 @@ pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
|
||||
arithmetic_side_effects_allowed_unary: Vec<String> = <_>::default(),
|
||||
/// The maximum allowed size for arrays on the stack
|
||||
#[lints(large_const_arrays, large_stack_arrays)]
|
||||
array_size_threshold: u64 = 512_000,
|
||||
array_size_threshold: u64 = 16 * 1024,
|
||||
/// Suppress lints whenever the suggested change would cause breakage for other crates.
|
||||
#[lints(
|
||||
box_collection,
|
||||
|
@ -12,9 +12,9 @@ pub static FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000];
|
||||
static FOO: [u32; 1_000_000] = [0u32; 1_000_000];
|
||||
|
||||
// Good
|
||||
pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000];
|
||||
pub const G_FOO_PUB: [u32; 1_000] = [0u32; 1_000];
|
||||
const G_FOO: [u32; 1_000] = [0u32; 1_000];
|
||||
pub(crate) const G_FOO_PUB_CRATE: [u32; 250] = [0u32; 250];
|
||||
pub const G_FOO_PUB: [u32; 250] = [0u32; 250];
|
||||
const G_FOO: [u32; 250] = [0u32; 250];
|
||||
|
||||
fn main() {
|
||||
// Should lint
|
||||
@ -26,10 +26,10 @@ fn main() {
|
||||
static BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000];
|
||||
|
||||
// Good
|
||||
pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000];
|
||||
const G_BAR: [u32; 1_000] = [0u32; 1_000];
|
||||
pub const G_BAR_STRUCT_PUB: [S; 500] = [S { data: [0; 32] }; 500];
|
||||
const G_BAR_STRUCT: [S; 500] = [S { data: [0; 32] }; 500];
|
||||
pub const G_BAR_S_PUB: [Option<&str>; 200] = [Some("str"); 200];
|
||||
const G_BAR_S: [Option<&str>; 200] = [Some("str"); 200];
|
||||
pub const G_BAR_PUB: [u32; 250] = [0u32; 250];
|
||||
const G_BAR: [u32; 250] = [0u32; 250];
|
||||
pub const G_BAR_STRUCT_PUB: [S; 4] = [S { data: [0; 32] }; 4];
|
||||
const G_BAR_STRUCT: [S; 4] = [S { data: [0; 32] }; 4];
|
||||
pub const G_BAR_S_PUB: [Option<&str>; 50] = [Some("str"); 50];
|
||||
const G_BAR_S: [Option<&str>; 50] = [Some("str"); 50];
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ pub struct S {
|
||||
const FOO: [u32; 1_000_000] = [0u32; 1_000_000];
|
||||
|
||||
// Good
|
||||
pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000];
|
||||
pub const G_FOO_PUB: [u32; 1_000] = [0u32; 1_000];
|
||||
const G_FOO: [u32; 1_000] = [0u32; 1_000];
|
||||
pub(crate) const G_FOO_PUB_CRATE: [u32; 250] = [0u32; 250];
|
||||
pub const G_FOO_PUB: [u32; 250] = [0u32; 250];
|
||||
const G_FOO: [u32; 250] = [0u32; 250];
|
||||
|
||||
fn main() {
|
||||
// Should lint
|
||||
@ -26,10 +26,10 @@ fn main() {
|
||||
const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000];
|
||||
|
||||
// Good
|
||||
pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000];
|
||||
const G_BAR: [u32; 1_000] = [0u32; 1_000];
|
||||
pub const G_BAR_STRUCT_PUB: [S; 500] = [S { data: [0; 32] }; 500];
|
||||
const G_BAR_STRUCT: [S; 500] = [S { data: [0; 32] }; 500];
|
||||
pub const G_BAR_S_PUB: [Option<&str>; 200] = [Some("str"); 200];
|
||||
const G_BAR_S: [Option<&str>; 200] = [Some("str"); 200];
|
||||
pub const G_BAR_PUB: [u32; 250] = [0u32; 250];
|
||||
const G_BAR: [u32; 250] = [0u32; 250];
|
||||
pub const G_BAR_STRUCT_PUB: [S; 4] = [S { data: [0; 32] }; 4];
|
||||
const G_BAR_STRUCT: [S; 4] = [S { data: [0; 32] }; 4];
|
||||
pub const G_BAR_S_PUB: [Option<&str>; 50] = [Some("str"); 50];
|
||||
const G_BAR_S: [Option<&str>; 50] = [Some("str"); 50];
|
||||
}
|
||||
|
@ -24,38 +24,38 @@ enum E {
|
||||
|
||||
fn issue_10741() {
|
||||
#[derive(Copy, Clone)]
|
||||
struct Large([u32; 100_000]);
|
||||
struct Large([u32; 2048]);
|
||||
|
||||
fn build() -> Large {
|
||||
Large([0; 100_000])
|
||||
Large([0; 2048])
|
||||
}
|
||||
|
||||
let _x = [build(); 3];
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
|
||||
let _y = [build(), build(), build()];
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let bad = (
|
||||
[0u32; 20_000_000],
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
[S { data: [0; 32] }; 5000],
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
[Some(""); 20_000_000],
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
[E::T(0); 5000],
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
[0u8; usize::MAX],
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
);
|
||||
|
||||
let good = (
|
||||
[0u32; 1000],
|
||||
[S { data: [0; 32] }; 1000],
|
||||
[Some(""); 1000],
|
||||
[E::T(0); 1000],
|
||||
[0u32; 50],
|
||||
[S { data: [0; 32] }; 4],
|
||||
[Some(""); 50],
|
||||
[E::T(0); 2],
|
||||
[(); 20_000_000],
|
||||
);
|
||||
}
|
||||
@ -69,7 +69,7 @@ macro_rules! dummy {
|
||||
// Weird rule to test help messages.
|
||||
($a:expr => $b:expr) => {
|
||||
[$a, $b, $a, $b]
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
};
|
||||
($id:ident; $n:literal) => {
|
||||
dummy!(::std::vec![$id;$n])
|
||||
@ -81,26 +81,26 @@ macro_rules! dummy {
|
||||
macro_rules! create_then_move {
|
||||
($id:ident; $n:literal) => {{
|
||||
let _x_ = [$id; $n];
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
_x_
|
||||
}};
|
||||
}
|
||||
|
||||
let x = [0u32; 50_000];
|
||||
let x = [0u32; 4096];
|
||||
let y = vec![x, x, x, x, x];
|
||||
let y = vec![dummy![x, x, x, x, x]];
|
||||
let y = vec![dummy![[x, x, x, x, x]]];
|
||||
let y = dummy![x, x, x, x, x];
|
||||
let y = [x, x, dummy!(x), x, x];
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
let y = dummy![x => x];
|
||||
let y = dummy![x;5];
|
||||
let y = dummy!(vec![dummy![x, x, x, x, x]]);
|
||||
let y = dummy![[x, x, x, x, x]];
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
|
||||
let y = proc_macros::make_it_big!([x; 1]);
|
||||
//~^ ERROR: allocating a local array larger than 512000 bytes
|
||||
//~^ ERROR: allocating a local array larger than 16384 bytes
|
||||
let y = vec![proc_macros::make_it_big!([x; 10])];
|
||||
let y = vec![create_then_move![x; 5]; 5];
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:33:14
|
||||
|
|
||||
LL | let _x = [build(); 3];
|
||||
@ -8,7 +8,7 @@ LL | let _x = [build(); 3];
|
||||
= note: `-D clippy::large-stack-arrays` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]`
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:36:14
|
||||
|
|
||||
LL | let _y = [build(), build(), build()];
|
||||
@ -16,7 +16,7 @@ LL | let _y = [build(), build(), build()];
|
||||
|
|
||||
= help: consider allocating on the heap with `vec![build(), build(), build()].into_boxed_slice()`
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:42:9
|
||||
|
|
||||
LL | [0u32; 20_000_000],
|
||||
@ -24,7 +24,7 @@ LL | [0u32; 20_000_000],
|
||||
|
|
||||
= help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()`
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:44:9
|
||||
|
|
||||
LL | [S { data: [0; 32] }; 5000],
|
||||
@ -32,7 +32,7 @@ LL | [S { data: [0; 32] }; 5000],
|
||||
|
|
||||
= help: consider allocating on the heap with `vec![S { data: [0; 32] }; 5000].into_boxed_slice()`
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:46:9
|
||||
|
|
||||
LL | [Some(""); 20_000_000],
|
||||
@ -40,7 +40,7 @@ LL | [Some(""); 20_000_000],
|
||||
|
|
||||
= help: consider allocating on the heap with `vec![Some(""); 20_000_000].into_boxed_slice()`
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:48:9
|
||||
|
|
||||
LL | [E::T(0); 5000],
|
||||
@ -48,7 +48,7 @@ LL | [E::T(0); 5000],
|
||||
|
|
||||
= help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()`
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:50:9
|
||||
|
|
||||
LL | [0u8; usize::MAX],
|
||||
@ -56,7 +56,7 @@ LL | [0u8; usize::MAX],
|
||||
|
|
||||
= help: consider allocating on the heap with `vec![0u8; usize::MAX].into_boxed_slice()`
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:94:13
|
||||
|
|
||||
LL | let y = [x, x, dummy!(x), x, x];
|
||||
@ -64,7 +64,7 @@ LL | let y = [x, x, dummy!(x), x, x];
|
||||
|
|
||||
= help: consider allocating on the heap with `vec![x, x, dummy!(x), x, x].into_boxed_slice()`
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:71:13
|
||||
|
|
||||
LL | [$a, $b, $a, $b]
|
||||
@ -75,7 +75,7 @@ LL | let y = dummy![x => x];
|
||||
|
|
||||
= note: this error originates in the macro `dummy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:99:20
|
||||
|
|
||||
LL | let y = dummy![[x, x, x, x, x]];
|
||||
@ -83,13 +83,13 @@ LL | let y = dummy![[x, x, x, x, x]];
|
||||
|
|
||||
= help: consider allocating on the heap with `vec![x, x, x, x, x].into_boxed_slice()`
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:102:39
|
||||
|
|
||||
LL | let y = proc_macros::make_it_big!([x; 1]);
|
||||
| ^^^^^^
|
||||
|
||||
error: allocating a local array larger than 512000 bytes
|
||||
error: allocating a local array larger than 16384 bytes
|
||||
--> tests/ui/large_stack_arrays.rs:83:23
|
||||
|
|
||||
LL | let _x_ = [$id; $n];
|
||||
|
Loading…
Reference in New Issue
Block a user