rust-lang / rust-lang/rust-clippy
Flag unnecessary visiblity attributes on nested functions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
When a function is nested inside another one, the inner one can only be accessed within the scope of the outer one, but not outside. Yet, it is possible to have a visibility attribute applied to the inner. That conceptually makes little sense. It could be the sign of a bug, wrong conception of the author, or just an oversight. Regardless, it should be uncontroversal that it can be removed:
fn outer() {
pub(crate) fn inner() {
}
inner()
}
I think this could even be a rustc warning, but filing this here for discussion first.
Advantage
- Remove unnecessary (and effectively dead) attributes
Drawbacks
- none (that I am aware of)
Example
fn outer() {
pub(crate) fn inner() {
}
inner()
}
Could be written as:
fn outer() {
fn inner() {
}
inner()
}
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 from the nested-function examples in the issue and review how Clippy implements warnings for Rust visibility attributes. Determine the intended warning behavior for nested functions, including the proposed rustc-warning question. Done means unnecessary visibility attributes are reliably identified without affecting valid outer-scope visibility.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100