Skip to content

Commit

Permalink
add test case for rust-lang#10741
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed May 21, 2023
1 parent 191a901 commit e9a98d9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
13 changes: 13 additions & 0 deletions tests/ui/large_stack_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ pub static DOESNOTLINT2: [u8; 512_001] = {
[x; 512_001]
};

fn issue_10741() {
#[derive(Copy, Clone)]
struct Large([u32; 100_000]);

fn build() -> Large {
Large([0; 100_000])
}

let _x = [build(); 3];

let _y = [build(), build(), build()];
}

fn main() {
let bad = (
[0u32; 20_000_000],
Expand Down
30 changes: 23 additions & 7 deletions tests/ui/large_stack_arrays.stderr
Original file line number Diff line number Diff line change
@@ -1,43 +1,59 @@
error: allocating a local array larger than 512000 bytes
--> $DIR/large_stack_arrays.rs:23:9
--> $DIR/large_stack_arrays.rs:29:14
|
LL | let _x = [build(); 3];
| ^^^^^^^^^^^^
|
= help: consider allocating on the heap with `vec![build(); 3].into_boxed_slice()`
= note: `-D clippy::large-stack-arrays` implied by `-D warnings`

error: allocating a local array larger than 512000 bytes
--> $DIR/large_stack_arrays.rs:31:14
|
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
--> $DIR/large_stack_arrays.rs:36:9
|
LL | [0u32; 20_000_000],
| ^^^^^^^^^^^^^^^^^^
|
= help: consider allocating on the heap with `vec![0u32; 20_000_000].into_boxed_slice()`
= note: `-D clippy::large-stack-arrays` implied by `-D warnings`

error: allocating a local array larger than 512000 bytes
--> $DIR/large_stack_arrays.rs:24:9
--> $DIR/large_stack_arrays.rs:37:9
|
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
--> $DIR/large_stack_arrays.rs:25:9
--> $DIR/large_stack_arrays.rs:38:9
|
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
--> $DIR/large_stack_arrays.rs:26:9
--> $DIR/large_stack_arrays.rs:39:9
|
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
--> $DIR/large_stack_arrays.rs:27:9
--> $DIR/large_stack_arrays.rs:40:9
|
LL | [0u8; usize::MAX],
| ^^^^^^^^^^^^^^^^^
|
= help: consider allocating on the heap with `vec![0u8; usize::MAX].into_boxed_slice()`

error: aborting due to 5 previous errors
error: aborting due to 7 previous errors

0 comments on commit e9a98d9

Please sign in to comment.