Clippy lints / Pedantic
Clippy lint · Pedantic · checked with Clippy 0.1.99
clippy::large_stack_arrays: allocating a local array larger than 16384 bytes
What it meansChecks for local arrays that may be too large. It is in the pedantic group and off by default.
What you see
warning: allocating a local array larger than 16384 bytes --> main.rs:3:9 | 3 | let a = [0u32; 1_000_000]; | ^^^^^^^^^^^^^^^^^ | = help: consider allocating on the heap with `vec![0u32; 1_000_000].into_boxed_slice()` = help: for further information visit https://rust-lang.github.io/rust-clippy/stable/index.html#large_stack_arrays = note: `-W clippy::large-stack-arrays` implied by `-W clippy::pedantic`
Real output of Clippy 0.1.99 (Rust 1.99) on the example below. Names and line numbers in yours will differ.
Does it matter?
Large local arrays may cause stack overflow.
Stricter lints with some false positives. Off by default; opt in with clippy::pedantic.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
let a = [0u32; 1_000_000];
Turn it off, or on
It is off by default. To use it, set it to warn or deny:
Whole crate (Cargo.toml)
[lints.clippy]
large_stack_arrays = "warn"In code
#![warn(clippy::large_stack_arrays)]One run
cargo clippy -- -W clippy::large-stack-arraysThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Settings in clippy.toml
array-size-threshold: The maximum allowed size for arrays on the stack
Clippy's own documentation
What it does
Checks for local arrays that may be too large.
Why is this bad?
Large local arrays may cause stack overflow.
Example
let a = [0u32; 1_000_000];
Configuration
-
array-size-threshold: The maximum allowed size for arrays on the stack(default:
16384)
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- too_many_linesChecks for functions with a large amount of lines
- missing_errors_docChecks the doc comments of publicly visible functions that return a Result type and warns if there is no # Errors section
- must_use_candidateChecks for public functions that have no #[must_use] attribute, but return something not already marked must-use, have no mutable arg and mutate no statics
- iter_without_into_iterLooks for iter and iter_mut methods without an associated IntoIterator for (&|&mut) Type implementation
- large_digit_groupsdigit groups should be smaller
- large_futureslarge future with a size of 16385 bytes
- large_types_passed_by_valuethis argument (2048 byte) is passed by value, but might be more efficient if passed by reference (limit: 256 byte)
- linkedlistChecks for usage of any LinkedList, suggesting to use a Vec or a VecDeque (formerly called RingBuf)
- macro_use_importsChecks for #[macro_use] use
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::too_many_linesChecks for functions with a large amount of linesRead it next →Did this answer your question?