rust-lang / rust-lang/rust-clippy
suggestion: Ways to specify `stack-size-threshold` for an item (function or module)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
We already have awesome lint large_stack_frames with single cfg stack-size-threshold. But could be great to set the threshold for a function, or module, or maybe any scope if possible.
Example
I have stack limits:
- main-thread =
10240 bytes(10KiB, internally defined as256032-bitunits) - audio-thread =
4096 bytes - net-thread =
6144 bytes
It could be awesome to get some ability to set stack-limit by-hand for a function like this for example:
#[clippy::stack_size(threshold = 10240)]
fn main_task_root() {}
#[clippy::stack_size(threshold = 4096)]
fn sound_task_root() {}
Also could be great to differentiate it as "levels by threshold" like this:
#[clippy::stack_size(threshold = 10240, level = "deny")]
fn main_task_root() {}
#[clippy::stack_size(threshold = 4096, level = "deny")] // total
#[clippy::stack_size(threshold = 4096/4, level = "warn")] // average max for "one of four" channel
fn sound_task_root() {}
And same for large_stack_arrays with array-size-threshold, because "what if I have two CPUs with various cache-lines on the board in-chain". Actually that is the case from my other project.
e.g.
- My main Cortex M7 have 32-byte cache-lines.
- Second CPU have an instruction cache with 16-byte lines.
#[clippy::array_size(threshold = 32)] // Main
fn main_task_root() {}
#[clippy::array_size(threshold = 16)] // Second
#[clippy::stack_size(threshold = 6144)]
fn net_task_root() {}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing large_stack_frames and large_stack_arrays lints and determine how their global thresholds are configured. Define the supported scope and attribute syntax, including the proposed level behavior, then document and test the agreed semantics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100