rust-lang / rust-lang/rust-clippy

Misleading code example for `wrong_pub_self_convention` lint

Open
#6,438 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-documentation A-lint C-enhancement
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

The wrong_pub_self_convention example from documentation is kind of misleading to me.

The example for this lint is:

# struct X;
impl<'a> X {
    pub fn as_str(self) -> &'a str {
        "foo"
    }
}

On playground, it fires wrong_self_convention (instead wrong_pub_self_convention), so the example or the lint needs to be reworked.

The difference with wrong_self_convention example is mainly the pub keyword on the method as_str, but the lint doesn't use the function visibility as condition to choose which lint to fire (in fact it uses the visibility of the impl item).

As proposed in #6316, it would probably make sense to also look into the history of the lints, what were the reasons to split them (if that was the case)?
It seems there are no tests for the pub variant.

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 with the wrong_pub_self_convention and wrong_self_convention examples in clippy_lints/src/methods/mod.rs, then reproduce the playground behavior described in the issue. Review the history and rationale referenced in rust-clippy#6316, and check how lint tests are organized; done means the example and lint behavior agree and the pub variant is covered if its behavior remains distinct.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.