rust-lang / rust-lang/rust-clippy

Flag unnecessary visiblity attributes on nested functions

Open
#13,262 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.