Skip to content

Commit 920ff52

Browse files
committed
Reduce default 'large array' threshold
1 parent 5ca7f4a commit 920ff52

File tree

6 files changed

+52
-52
lines changed

6 files changed

+52
-52
lines changed

book/src/lint_configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"]
329329
## `array-size-threshold`
330330
The maximum allowed size for arrays on the stack
331331

332-
**Default Value:** `512000`
332+
**Default Value:** `16384`
333333

334334
---
335335
**Affected lints:**

clippy_config/src/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ define_Conf! {
366366
arithmetic_side_effects_allowed_unary: Vec<String> = <_>::default(),
367367
/// The maximum allowed size for arrays on the stack
368368
#[lints(large_const_arrays, large_stack_arrays)]
369-
array_size_threshold: u64 = 512_000,
369+
array_size_threshold: u64 = 16 * 1024,
370370
/// Suppress lints whenever the suggested change would cause breakage for other crates.
371371
#[lints(
372372
box_collection,

tests/ui/large_const_arrays.fixed

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ pub static FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000];
1212
static FOO: [u32; 1_000_000] = [0u32; 1_000_000];
1313

1414
// Good
15-
pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000];
16-
pub const G_FOO_PUB: [u32; 1_000] = [0u32; 1_000];
17-
const G_FOO: [u32; 1_000] = [0u32; 1_000];
15+
pub(crate) const G_FOO_PUB_CRATE: [u32; 250] = [0u32; 250];
16+
pub const G_FOO_PUB: [u32; 250] = [0u32; 250];
17+
const G_FOO: [u32; 250] = [0u32; 250];
1818

1919
fn main() {
2020
// Should lint
@@ -26,10 +26,10 @@ fn main() {
2626
static BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000];
2727

2828
// Good
29-
pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000];
30-
const G_BAR: [u32; 1_000] = [0u32; 1_000];
31-
pub const G_BAR_STRUCT_PUB: [S; 500] = [S { data: [0; 32] }; 500];
32-
const G_BAR_STRUCT: [S; 500] = [S { data: [0; 32] }; 500];
33-
pub const G_BAR_S_PUB: [Option<&str>; 200] = [Some("str"); 200];
34-
const G_BAR_S: [Option<&str>; 200] = [Some("str"); 200];
29+
pub const G_BAR_PUB: [u32; 250] = [0u32; 250];
30+
const G_BAR: [u32; 250] = [0u32; 250];
31+
pub const G_BAR_STRUCT_PUB: [S; 4] = [S { data: [0; 32] }; 4];
32+
const G_BAR_STRUCT: [S; 4] = [S { data: [0; 32] }; 4];
33+
pub const G_BAR_S_PUB: [Option<&str>; 50] = [Some("str"); 50];
34+
const G_BAR_S: [Option<&str>; 50] = [Some("str"); 50];
3535
}

tests/ui/large_const_arrays.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ pub const FOO_PUB: [u32; 1_000_000] = [0u32; 1_000_000];
1212
const FOO: [u32; 1_000_000] = [0u32; 1_000_000];
1313

1414
// Good
15-
pub(crate) const G_FOO_PUB_CRATE: [u32; 1_000] = [0u32; 1_000];
16-
pub const G_FOO_PUB: [u32; 1_000] = [0u32; 1_000];
17-
const G_FOO: [u32; 1_000] = [0u32; 1_000];
15+
pub(crate) const G_FOO_PUB_CRATE: [u32; 250] = [0u32; 250];
16+
pub const G_FOO_PUB: [u32; 250] = [0u32; 250];
17+
const G_FOO: [u32; 250] = [0u32; 250];
1818

1919
fn main() {
2020
// Should lint
@@ -26,10 +26,10 @@ fn main() {
2626
const BAR_S: [Option<&str>; 200_000] = [Some("str"); 200_000];
2727

2828
// Good
29-
pub const G_BAR_PUB: [u32; 1_000] = [0u32; 1_000];
30-
const G_BAR: [u32; 1_000] = [0u32; 1_000];
31-
pub const G_BAR_STRUCT_PUB: [S; 500] = [S { data: [0; 32] }; 500];
32-
const G_BAR_STRUCT: [S; 500] = [S { data: [0; 32] }; 500];
33-
pub const G_BAR_S_PUB: [Option<&str>; 200] = [Some("str"); 200];
34-
const G_BAR_S: [Option<&str>; 200] = [Some("str"); 200];
29+
pub const G_BAR_PUB: [u32; 250] = [0u32; 250];
30+
const G_BAR: [u32; 250] = [0u32; 250];
31+
pub const G_BAR_STRUCT_PUB: [S; 4] = [S { data: [0; 32] }; 4];
32+
const G_BAR_STRUCT: [S; 4] = [S { data: [0; 32] }; 4];
33+
pub const G_BAR_S_PUB: [Option<&str>; 50] = [Some("str"); 50];
34+
const G_BAR_S: [Option<&str>; 50] = [Some("str"); 50];
3535
}

tests/ui/large_stack_arrays.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,38 @@ pub static DOESNOTLINT2: [u8; 512_001] = {
2323

2424
fn issue_10741() {
2525
#[derive(Copy, Clone)]
26-
struct Large([u32; 100_000]);
26+
struct Large([u32; 2048]);
2727

2828
fn build() -> Large {
29-
Large([0; 100_000])
29+
Large([0; 2048])
3030
}
3131

3232
let _x = [build(); 3];
33-
//~^ ERROR: allocating a local array larger than 512000 bytes
33+
//~^ ERROR: allocating a local array larger than 16384 bytes
3434

3535
let _y = [build(), build(), build()];
36-
//~^ ERROR: allocating a local array larger than 512000 bytes
36+
//~^ ERROR: allocating a local array larger than 16384 bytes
3737
}
3838

3939
fn main() {
4040
let bad = (
4141
[0u32; 20_000_000],
42-
//~^ ERROR: allocating a local array larger than 512000 bytes
42+
//~^ ERROR: allocating a local array larger than 16384 bytes
4343
[S { data: [0; 32] }; 5000],
44-
//~^ ERROR: allocating a local array larger than 512000 bytes
44+
//~^ ERROR: allocating a local array larger than 16384 bytes
4545
[Some(""); 20_000_000],
46-
//~^ ERROR: allocating a local array larger than 512000 bytes
46+
//~^ ERROR: allocating a local array larger than 16384 bytes
4747
[E::T(0); 5000],
48-
//~^ ERROR: allocating a local array larger than 512000 bytes
48+
//~^ ERROR: allocating a local array larger than 16384 bytes
4949
[0u8; usize::MAX],
50-
//~^ ERROR: allocating a local array larger than 512000 bytes
50+
//~^ ERROR: allocating a local array larger than 16384 bytes
5151
);
5252

5353
let good = (
54-
[0u32; 1000],
55-
[S { data: [0; 32] }; 1000],
56-
[Some(""); 1000],
57-
[E::T(0); 1000],
54+
[0u32; 50],
55+
[S { data: [0; 32] }; 4],
56+
[Some(""); 50],
57+
[E::T(0); 2],
5858
[(); 20_000_000],
5959
);
6060
}
@@ -68,7 +68,7 @@ fn issue_12586() {
6868
// Weird rule to test help messages.
6969
($a:expr => $b:expr) => {
7070
[$a, $b, $a, $b]
71-
//~^ ERROR: allocating a local array larger than 512000 bytes
71+
//~^ ERROR: allocating a local array larger than 16384 bytes
7272
};
7373
($id:ident; $n:literal) => {
7474
dummy!(::std::vec![$id;$n])
@@ -80,28 +80,28 @@ fn issue_12586() {
8080
macro_rules! create_then_move {
8181
($id:ident; $n:literal) => {{
8282
let _x_ = [$id; $n];
83-
//~^ ERROR: allocating a local array larger than 512000 bytes
83+
//~^ ERROR: allocating a local array larger than 16384 bytes
8484
_x_
8585
}};
8686
}
8787

88-
let x = [0u32; 50_000];
88+
let x = [0u32; 4096];
8989
let y = vec![x, x, x, x, x];
9090
let y = vec![dummy![x, x, x, x, x]];
9191
let y = vec![dummy![[x, x, x, x, x]]];
9292
let y = dummy![x, x, x, x, x];
9393
let y = [x, x, dummy!(x), x, x];
94-
//~^ ERROR: allocating a local array larger than 512000 bytes
94+
//~^ ERROR: allocating a local array larger than 16384 bytes
9595
let y = dummy![x => x];
9696
let y = dummy![x;5];
9797
let y = dummy!(vec![dummy![x, x, x, x, x]]);
9898
let y = dummy![[x, x, x, x, x]];
99-
//~^ ERROR: allocating a local array larger than 512000 bytes
99+
//~^ ERROR: allocating a local array larger than 16384 bytes
100100

101101
let y = proc_macros::make_it_big!([x; 1]);
102-
//~^ ERROR: allocating a local array larger than 512000 bytes
102+
//~^ ERROR: allocating a local array larger than 16384 bytes
103103
let y = vec![proc_macros::make_it_big!([x; 10])];
104104
let y = vec![create_then_move![x; 5]; 5];
105105
}
106106

107-
const STATIC_PROMOTED_LARGE_ARRAY: &[u8; 512001] = &[0; 512001];
107+
const STATIC_PROMOTED_LARGE_ARRAY: &[u8; 1025] = &[0; 1025];

tests/ui/large_stack_arrays.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: allocating a local array larger than 512000 bytes
1+
error: allocating a local array larger than 16384 bytes
22
--> tests/ui/large_stack_arrays.rs:32:14
33
|
44
LL | let _x = [build(); 3];
@@ -8,63 +8,63 @@ LL | let _x = [build(); 3];
88
= note: `-D clippy::large-stack-arrays` implied by `-D warnings`
99
= help: to override `-D warnings` add `#[allow(clippy::large_stack_arrays)]`
1010

11-
error: allocating a local array larger than 512000 bytes
11+
error: allocating a local array larger than 16384 bytes
1212
--> tests/ui/large_stack_arrays.rs:35:14
1313
|
1414
LL | let _y = [build(), build(), build()];
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616
|
1717
= help: consider allocating on the heap with `vec![build(), build(), build()].into_boxed_slice()`
1818

19-
error: allocating a local array larger than 512000 bytes
19+
error: allocating a local array larger than 16384 bytes
2020
--> tests/ui/large_stack_arrays.rs:41:9
2121
|
2222
LL | [0u32; 20_000_000],
2323
| ^^^^^^^^^^^^^^^^^^
2424
|
2525
= help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()`
2626

27-
error: allocating a local array larger than 512000 bytes
27+
error: allocating a local array larger than 16384 bytes
2828
--> tests/ui/large_stack_arrays.rs:43:9
2929
|
3030
LL | [S { data: [0; 32] }; 5000],
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232
|
3333
= help: consider allocating on the heap with `vec![S { data: [0; 32] }; 5000].into_boxed_slice()`
3434

35-
error: allocating a local array larger than 512000 bytes
35+
error: allocating a local array larger than 16384 bytes
3636
--> tests/ui/large_stack_arrays.rs:45:9
3737
|
3838
LL | [Some(""); 20_000_000],
3939
| ^^^^^^^^^^^^^^^^^^^^^^
4040
|
4141
= help: consider allocating on the heap with `vec![Some(""); 20_000_000].into_boxed_slice()`
4242

43-
error: allocating a local array larger than 512000 bytes
43+
error: allocating a local array larger than 16384 bytes
4444
--> tests/ui/large_stack_arrays.rs:47:9
4545
|
4646
LL | [E::T(0); 5000],
4747
| ^^^^^^^^^^^^^^^
4848
|
4949
= help: consider allocating on the heap with `vec![E::T(0); 5000].into_boxed_slice()`
5050

51-
error: allocating a local array larger than 512000 bytes
51+
error: allocating a local array larger than 16384 bytes
5252
--> tests/ui/large_stack_arrays.rs:49:9
5353
|
5454
LL | [0u8; usize::MAX],
5555
| ^^^^^^^^^^^^^^^^^
5656
|
5757
= help: consider allocating on the heap with `vec![0u8; usize::MAX].into_boxed_slice()`
5858

59-
error: allocating a local array larger than 512000 bytes
59+
error: allocating a local array larger than 16384 bytes
6060
--> tests/ui/large_stack_arrays.rs:93:13
6161
|
6262
LL | let y = [x, x, dummy!(x), x, x];
6363
| ^^^^^^^^^^^^^^^^^^^^^^^
6464
|
6565
= help: consider allocating on the heap with `vec![x, x, dummy!(x), x, x].into_boxed_slice()`
6666

67-
error: allocating a local array larger than 512000 bytes
67+
error: allocating a local array larger than 16384 bytes
6868
--> tests/ui/large_stack_arrays.rs:70:13
6969
|
7070
LL | [$a, $b, $a, $b]
@@ -75,21 +75,21 @@ LL | let y = dummy![x => x];
7575
|
7676
= note: this error originates in the macro `dummy` (in Nightly builds, run with -Z macro-backtrace for more info)
7777

78-
error: allocating a local array larger than 512000 bytes
78+
error: allocating a local array larger than 16384 bytes
7979
--> tests/ui/large_stack_arrays.rs:98:20
8080
|
8181
LL | let y = dummy![[x, x, x, x, x]];
8282
| ^^^^^^^^^^^^^^^
8383
|
8484
= help: consider allocating on the heap with `vec![x, x, x, x, x].into_boxed_slice()`
8585

86-
error: allocating a local array larger than 512000 bytes
86+
error: allocating a local array larger than 16384 bytes
8787
--> tests/ui/large_stack_arrays.rs:101:39
8888
|
8989
LL | let y = proc_macros::make_it_big!([x; 1]);
9090
| ^^^^^^
9191

92-
error: allocating a local array larger than 512000 bytes
92+
error: allocating a local array larger than 16384 bytes
9393
--> tests/ui/large_stack_arrays.rs:82:23
9494
|
9595
LL | let _x_ = [$id; $n];

0 commit comments

Comments
 (0)