Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Roadmap] False Positive Rate #6623

Open
1 of 5 tasks
flip1995 opened this issue Jan 22, 2021 · 10 comments
Open
1 of 5 tasks

[Roadmap] False Positive Rate #6623

flip1995 opened this issue Jan 22, 2021 · 10 comments
Assignees
Labels
C-tracking-issue Category: Tracking Issue I-false-positive Issue: The lint was triggered on code it shouldn't have P-high Priority: High

Comments

@flip1995
Copy link
Member

flip1995 commented Jan 22, 2021

In the worst case, new lints are only available in nightly for 2 weeks, before
hitting beta and ultimately stable. This and the fact that fewer people use
nightly Rust nowadays makes it more probable that a lint with many FPs hits
stable. This leads to annoyed users, that will disable these new lints in the
best case and to more annoyed users, that will stop using Clippy in the worst.
A process should be developed and implemented to prevent this from happening.

#6429

Steps to completion:

@flip1995 flip1995 added C-tracking-issue Category: Tracking Issue I-false-positive Issue: The lint was triggered on code it shouldn't have P-high Priority: High labels Jan 22, 2021
@flip1995 flip1995 added this to False positive rate in Roadmap 2021/2022 Jan 22, 2021
@flip1995 flip1995 self-assigned this Jan 26, 2021
@flip1995 flip1995 pinned this issue May 20, 2021
@xFrednet
Copy link
Member

I think it would be a good idea to add some crates to the lintcheck tool that use unicode identifiers. Looking and fixing #7869 made me realize how fast byte and character indices can be mixed up 🙃

@llogiq
Copy link
Contributor

llogiq commented Oct 24, 2021

Perhaps a str slicing lint would help us find the lints that are in need of test cases containing unicode identifiers...

bors added a commit that referenced this issue Oct 26, 2021
new lint: string-slice

This is a restriction lint to highlight code that should have tests containing non-ascii characters. See #6623.

changelog: new lint: [`string-slice`]
@EdJoPaTo
Copy link

EdJoPaTo commented Nov 4, 2021

Something I think that would be helpful to deal with false positives would be #3122. In case false positives are found they will be allowed short term.
In the long term this false positive will be fixed and the allow comment shouldn't be there anymore.

@flip1995
Copy link
Member Author

flip1995 commented Nov 4, 2021

Good news: @xFrednet is currently working on this: rust-lang/rust#87835

bors added a commit that referenced this issue Nov 11, 2021
Add Clippy version to Clippy's lint list

Hey, hey, the semester is finally over, and I wanted to get back into hacking on Clippy. It has also been some time since our metadata collection monster has been feed. So, this PR adds a new attribute `clippy::version` to document which version a lint was stabilized. I considered using `git blame` but that would be very hacky and probably not accurate.

I'm also thinking that this attribute can be used to have a `clippy::nightly` lint group which is allow-by-default that delays setting the actual lint group until the defined version is reached. Just something to consider regarding #6623 🙃

This PR only adds the version to 4 lints to keep it reviewable. I'll do a followup PR to add the version to other lints if the implementation is accepted 🙃

![image](https://user-images.githubusercontent.com/17087237/137118859-0aafdfdf-7595-4289-8ba4-33d58eb6991d.png)

Also, mobile approved xD

![image](https://user-images.githubusercontent.com/17087237/137118944-833cf7fb-a4a1-45d6-9af8-32c951822360.png)

---

r? `@flip1995`

cc: #7172

closes: #6492

changelog: [Clippy's lint list](https://rust-lang.github.io/rust-clippy/master/index.html) now displays the version a lint was added. 🎉

---

Example lint declaration after this update:

```rs
declare_clippy_lint! {
    /// [...]
    ///
    /// ### Example
    /// ```rust
    /// // Bad
    /// let x = 3.14;
    /// // Good
    /// let x = std::f32::consts::PI;
    /// ```
    #[clippy::version = "pre 1.29.0"]
    pub APPROX_CONSTANT,
    correctness,
    "the approximate of a known float constant (in `std::fXX::consts`)"
}
```
@xFrednet
Copy link
Member

xFrednet commented Jan 2, 2022

I would like to take a stab at the second point: "Implement framework so that lints can be enabled in nightly only". I have three ideas how this can be implemented, with advantages and drawbacks. I'll create an issue outlining the possibilities and to ask for feedback. 🙃

@matthiaskrgr
Copy link
Member

To add an additional datapoint, I have run clippy on all files (standalone) in the rustc repo [1]
(basically: run cargo clippy --fix -Wall::lints on a file, check if rustfix fails to apply clippys suggestion, bisect the offending lint), and these are the lints and the number of times a applied lint suggestion caused a compilation failure (aka invalid suggestion)

      1       "--force-warn clippy::assign-op-pattern",
      1       "--force-warn clippy::blocks-in-if-conditions",
      1       "--force-warn clippy::bool-comparison",
      1       "--force-warn clippy::bool-to-int-with-if",
      1       "--force-warn clippy::borrow-deref-ref",
      1       "--force-warn clippy::cloned-instead-of-copied",
      1       "--force-warn clippy::derive-partial-eq-without-eq",
      1       "--force-warn clippy::excessive-precision",
      1       "--force-warn clippy::explicit-auto-deref",
      1       "--force-warn clippy::match-single-binding",
      1       "--force-warn clippy::needless-arbitrary-self-type",
      1       "--force-warn clippy::needless-for-each",
      1       "--force-warn clippy::needless-late-init",
      1       "--force-warn clippy::range-minus-one",
      1       "--force-warn clippy::range-plus-one",
      1       "--force-warn clippy::redundant-pattern-matching",
      1       "--force-warn clippy::ref-binding-to-reference",
      1       "--force-warn clippy::short-circuit-statement",
      1       "--force-warn clippy::single-component-path-imports",
      1       "--force-warn clippy::transmutes-expressible-as-ptr-casts",
      1       "--force-warn clippy::unnecessary-sort-by",
      2       "--force-warn clippy::cast-lossless",
      2       "--force-warn clippy::equatable-if-let",
      2       "--force-warn clippy::manual-async-fn",
      2       "--force-warn clippy::needless-lifetimes",
      2       "--force-warn clippy::redundant-closure",
      2       "--force-warn clippy::redundant-closure-call",
      2       "--force-warn clippy::redundant-pub-crate",
      2       "--force-warn clippy::unused-unit",
      3       "--force-warn clippy::needless-return",
      3       "--force-warn clippy::no-mangle-with-rust-abi",
      3       "--force-warn clippy::redundant-clone",
      3       "--force-warn clippy::trait-duplication-in-bounds",
      3       "--force-warn clippy::unnecessary-fold",
      3       "--force-warn clippy::unnested-or-patterns",
      4       "--force-warn clippy::unit-arg",
      4       "--force-warn clippy::unnecessary-operation",
      4       "--force-warn clippy::wildcard-imports",
      6       "--force-warn clippy::redundant-closure-for-method-calls",
      6       "--force-warn clippy::use-self",
     13       "--force-warn clippy::ptr-as-ptr",
     23       "--force-warn clippy::let-unit-value",
     40       "--force-warn clippy::borrow-as-ptr",

Note that this is by no means a complete picture, it only shows lints that can be applied automatically in the first place, and lints that are more likely to fire on code inside short snippets of rustcs unit tests.

@llogiq
Copy link
Contributor

llogiq commented Mar 9, 2023

I wonder how many of those are in compile tests that would have failed to compile in the first place?

Do you have the raw data somewhere?

@matthiaskrgr
Copy link
Member

I think none of those failed to compile in the first place because I don't pass --broken code flag to rustfix which is required to fix code that does not compile in the first place iirc..? I can't check in detail right now.

@matthiaskrgr
Copy link
Member

I uploaded the errors.json which contains the files and the clippy lints that failed to apply with them.
The summary was obtained via cat errors.json | grep clippy:: | sort -n | uniq -c | sort -n
errors.json.tar.gz

@xFrednet
Copy link
Member

Implement framework so that lints can be enabled in nightly only

I've tried to implement this in Clippy, but we determined, that this should be implemented in rustc instead. The compiler team requested us to create a MCP if we want this for rustc.

@Jarcho created a working implementation in rustc, but it was closed until an MCP was created and accepted: rust-lang/rust#109063.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: Tracking Issue I-false-positive Issue: The lint was triggered on code it shouldn't have P-high Priority: High
Projects
Roadmap 2021/2022
False positive rate
Development

No branches or pull requests

6 participants
@matthiaskrgr @llogiq @EdJoPaTo @flip1995 @xFrednet and others