Skip to content

Commit 26994e2

Browse files
committed
Reduce default 'large array' threshold
1 parent 4b7c190 commit 26994e2

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
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: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,38 @@ pub static DOESNOTLINT2: [u8; 512_001] = {
2424

2525
fn issue_10741() {
2626
#[derive(Copy, Clone)]
27-
struct Large([u32; 100_000]);
27+
struct Large([u32; 2048]);
2828

2929
fn build() -> Large {
30-
Large([0; 100_000])
30+
Large([0; 2048])
3131
}
3232

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

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

4040
fn main() {
4141
let bad = (
4242
[0u32; 20_000_000],
43-
//~^ ERROR: allocating a local array larger than 512000 bytes
43+
//~^ ERROR: allocating a local array larger than 16384 bytes
4444
[S { data: [0; 32] }; 5000],
45-
//~^ ERROR: allocating a local array larger than 512000 bytes
45+
//~^ ERROR: allocating a local array larger than 16384 bytes
4646
[Some(""); 20_000_000],
47-
//~^ ERROR: allocating a local array larger than 512000 bytes
47+
//~^ ERROR: allocating a local array larger than 16384 bytes
4848
[E::T(0); 5000],
49-
//~^ ERROR: allocating a local array larger than 512000 bytes
49+
//~^ ERROR: allocating a local array larger than 16384 bytes
5050
[0u8; usize::MAX],
51-
//~^ ERROR: allocating a local array larger than 512000 bytes
51+
//~^ ERROR: allocating a local array larger than 16384 bytes
5252
);
5353

5454
let good = (
55-
[0u32; 1000],
56-
[S { data: [0; 32] }; 1000],
57-
[Some(""); 1000],
58-
[E::T(0); 1000],
55+
[0u32; 50],
56+
[S { data: [0; 32] }; 4],
57+
[Some(""); 50],
58+
[E::T(0); 2],
5959
[(); 20_000_000],
6060
);
6161
}
@@ -69,7 +69,7 @@ fn issue_12586() {
6969
// Weird rule to test help messages.
7070
($a:expr => $b:expr) => {
7171
[$a, $b, $a, $b]
72-
//~^ ERROR: allocating a local array larger than 512000 bytes
72+
//~^ ERROR: allocating a local array larger than 16384 bytes
7373
};
7474
($id:ident; $n:literal) => {
7575
dummy!(::std::vec![$id;$n])
@@ -81,26 +81,26 @@ fn issue_12586() {
8181
macro_rules! create_then_move {
8282
($id:ident; $n:literal) => {{
8383
let _x_ = [$id; $n];
84-
//~^ ERROR: allocating a local array larger than 512000 bytes
84+
//~^ ERROR: allocating a local array larger than 16384 bytes
8585
_x_
8686
}};
8787
}
8888

89-
let x = [0u32; 50_000];
89+
let x = [0u32; 4096];
9090
let y = vec![x, x, x, x, x];
9191
let y = vec![dummy![x, x, x, x, x]];
9292
let y = vec![dummy![[x, x, x, x, x]]];
9393
let y = dummy![x, x, x, x, x];
9494
let y = [x, x, dummy!(x), x, x];
95-
//~^ ERROR: allocating a local array larger than 512000 bytes
95+
//~^ ERROR: allocating a local array larger than 16384 bytes
9696
let y = dummy![x => x];
9797
let y = dummy![x;5];
9898
let y = dummy!(vec![dummy![x, x, x, x, x]]);
9999
let y = dummy![[x, x, x, x, x]];
100-
//~^ ERROR: allocating a local array larger than 512000 bytes
100+
//~^ ERROR: allocating a local array larger than 16384 bytes
101101

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

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:33: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:36: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:42: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:44: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:46: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:48: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:50: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:94: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:71: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:99: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:102: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:83:23
9494
|
9595
LL | let _x_ = [$id; $n];

0 commit comments

Comments
 (0)