Commit Graph

20539 Commits

Author SHA1 Message Date
Jason Newcomb
8bcecfff95 Handle or patterns in single_match and single_match_else 2024-08-07 11:40:15 -04:00
Jason Newcomb
514824ff9d Refactor single_match 2024-08-07 11:32:06 -04:00
Jason Newcomb
16633a2d7b Replace in_constant with is_in_const_context. Use only the state in LateContext to avoid walking the HIR tree. 2024-08-07 09:57:27 -04:00
kyoto7250
5e25e7c370 add a test for ice-3717.rs
https://github.com/rust-lang/rust-clippy/issues/13099
2024-08-07 21:48:47 +09:00
bors
5ead90f13a Auto merge of #12150 - ithinuel:add_misleading_use_of_ok, r=y21
Add lint for `unused_result_ok`

This PR adds a lint to capture the use of `expr.ok();` when the result is not _really_ used.

This could be interpreted as the result being checked (like it is with `unwrap()` or `expect`) but
it actually only ignores the result.

`let _ = expr;` expresses that intent better.

This was also mentionned in #8994 (although not being the main topic of that issue).

changelog: [`misleading_use_of_ok`]: Add new lint to capture `.ok();` when the result is not _really_ used.
2024-08-06 19:01:41 +00:00
bors
9d9a0dcb64 Auto merge of #13225 - Jarcho:warnings, r=flip1995
Use `-D warnings` instead of `deny-warnings` feature.

r? `@flip1995`
changelog: none
2024-08-06 14:58:50 +00:00
Jason Newcomb
4e57b2c46f Use -D warnings instead of deny-warnings feature. 2024-08-06 10:46:39 -04:00
bors
a411267453 Auto merge of #13210 - Alexendoo:lintcheck-force-warn, r=xFrednet
lintcheck: force warn all lints

It occurred to me that like `--filter` we could use `--force-warn` for normal operations, we especially want to see lints that crates decided were too annoying or were false positives

Also excludes `clippy::cargo` from the default set as nobody is really writing those and it slows things down

r? `@xFrednet`

changelog: none
2024-08-06 09:46:08 +00:00
bors
cfb38819cc Auto merge of #13145 - xFrednet:07797-restriction-and-then-why, r=Jarcho
Make restriction lint's use `span_lint_and_then` (q -> w)

This migrates a few restriction lints to use `span_lint_and_then`. This change is motivated by https://github.com/rust-lang/rust-clippy/issues/7797.

I've also cleaned up some lint message. Mostly minor stuff. For example: suggestions with a longer message than `"try"` now use `SuggestionStyle::ShowAlways`

---

cc: https://github.com/rust-lang/rust-clippy/issues/7797

sister PR of: https://github.com/rust-lang/rust-clippy/pull/13136

changelog: none
2024-08-06 04:47:27 +00:00
y21
4c6a3f4b6e pass the right ParamEnv to might_permit_raw_init_strict 2024-08-06 01:53:50 +02:00
bors
5f6d07b64e Auto merge of #13222 - dtolnay-contrib:deterministic, r=flip1995
Use a deterministic number of digits in rustc_tools_util commit hashes

Using `git rev-parse --short` in rustc_tools_util causes nondeterministic compilation of projects that use `setup_version_info!` and `get_version_info!` when built from the exact same source code and git commit. The number of digits printed by `--short` is sensitive to how many other branches and tags in the repository have been fetched so far, what other commits have been worked on in other branches, how recently you had run `git gc`, platform-specific variation in git's default configuration, and platform differences in the sequence of steps performed by the release pipeline. Someone can compile a tool from a particular commit, switch branches to work on a different commit (or simply do a git fetch), go back to the first commit and be unable to reproduce the binary that was built from it previously.

Currently, variation in short commit hashes causes Clippy version strings to be out of sync between different targets. On x86_64-unknown-linux-gnu:

```console
$ clippy-driver +1.80.0 --version
clippy 0.1.80 (0514789 2024-07-21)
```

Whereas on aarch64-apple-darwin:

```console
$ clippy-driver +1.80.0 --version
clippy 0.1.80 (05147895 2024-07-21)
```

---

changelog: none
2024-08-05 19:36:16 +00:00
David Tolnay
9f6536ce6f
Use a deterministic number of digits in rustc_tools_util commit hashes 2024-08-05 08:17:18 -07:00
bors
c082bc2cb8 Auto merge of #13136 - xFrednet:07797-restriction-and-then, r=blyxyas
Make restriction lint's use `span_lint_and_then` (a -> e)

This migrates a few restriction lints to use `span_lint_and_then`. This change is motivated by https://github.com/rust-lang/rust-clippy/issues/7797.

I'm also interested if it will have an impact on performance. With some of these lints, like [`clippy::implicit_return`](https://rust-lang.github.io/rust-clippy/master/index.html#/implicit_return) I expect an impact, as it was previously creating a suggestion **for every implicit return** which is just wild.

I've also cleaned up some lint message. Mostly minor stuff. For example: suggestions with a longer message than `"try"` now use `SuggestionStyle::ShowAlways`

---

`@blyxyas` Could you benchmark this PR? I want to get all the numbers :3

---

This also crashed our new lintcheck CI with the following message:

> Error: $GITHUB_STEP_SUMMARY upload aborted, supports content up to a size of 1024k, got 46731k. For more information see: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary

Which is just wild. Like, I've [tested the first 20 lints](https://github.com/xFrednet/rust-clippy/actions/runs/10027528172) and got like four changes and then this. 50 MB of changed lint messages o.O. Looks like I'll create a separate PR to fix that step ^^

---

cc: https://github.com/rust-lang/rust-clippy/issues/7797

changelog: none

r? `@blyxyas`
2024-08-05 13:33:16 +00:00
bors
e17d254e2b Auto merge of #13180 - Jarcho:deprecated_shrink, r=flip1995
Simplify lint deprecation

A couple of small changes:
* A few deprecations were changed to renames. They all had a message similar to "this lint has been replaced by ..." which is just describing a rename.
* The website and warning message are now the same. The website description was usually just a wordier version that contained no extra information. This can be worked around if needed, but I don't think that will happen.
* The legacy deprecations have been removed. rustc should handle this since it already suggests adding the `clippy::` for all lints (deprecated or not) when they're used without it. It wouldn't be a problem to add them back in.
* The website no longer has a "view source" link for deprecated lints since they're no longer read from the HIR tree. I could store the line number, but the link seems totally useless for these lints.

This came up as part of separating the internal lints into their own crate. Both the metadata collector and the lint registration code needs access to the deprecated and renamed lists. This form lets all the deprecations be a separate crate.

r? `@flip1995`

changelog: none
2024-08-05 13:23:16 +00:00
Jason Newcomb
c2186e14de Make cargo dev deprecate require a reason 2024-08-05 09:17:46 -04:00
Jason Newcomb
2c34d58159 Store deprecated lints as an array of tuples.
Remove legacy deprecations.
Remove "View Source" link for deprecated lints.
2024-08-05 09:15:55 -04:00
Jason Newcomb
1672d5d4ed Mark some lint deprecations as renames 2024-08-05 09:10:49 -04:00
bors
e611c8e1c4 Auto merge of #13217 - dtolnay-contrib:toolsutil, r=flip1995
Check exit status of subcommands spawned by rustc_tools_util

The git commands `git rev-parse --short HEAD` and `git log -1 --date=short --pretty=format:%cd` that clippy runs from its build script might fail with **"fatal: not a git repository (or any of the parent directories): .git"** if clippy is being built from a source tarball rather than a git repository. That message is written by git to stderr, and nothing is written to stdout.

For `clippy-driver --version` this PR wouldn't make a difference because it treats empty stdout and failed spawns (`git` is not installed) identically:

7ac242c3d0/rustc_tools_util/src/lib.rs (L35-L42)

But other users of `rustc_tools_util` should be able to expect that the distinction between Some and None is meaningful. They shouldn't need extra code to handle None vs Some-and-empty vs Some-and-nonempty.

---

changelog: none
2024-08-05 13:00:02 +00:00
y21
234a1d35d9 recognize metavariables in tail expressions 2024-08-05 12:02:08 +02:00
David Tolnay
234ea1fcd9
Check exit status of subcommands spawned by rustc_tools_util 2024-08-04 11:13:06 -07:00
bors
7ac242c3d0 Auto merge of #13213 - Alexendoo:multispan-sugg, r=y21
Remove `multispan_sugg[_with_applicability]`

They're thin wrappers over the corresponding diag method so we should just use that instead

changelog: none
2024-08-04 15:05:27 +00:00
Alex Macleod
1ea7bddbdf Remove multispan_sugg[_with_applicability] 2024-08-04 13:14:23 +00:00
rzvxa
5364cbea80 Respect allow inconsistent_struct_constructor on the type definition 2024-08-03 22:52:22 +03:30
bors
377d72ae8b Auto merge of #13194 - sheshnath-at-knoldus:fix-typos, r=Jarcho
fix-typos

fixes some typos in lintcheck

changelog: None
2024-08-03 18:51:51 +00:00
sheshnath-at-knoldus
b9716dd32a fix-typos 2024-08-03 23:18:29 +05:30
bors
8dd459d4c7 Auto merge of #13209 - Alexendoo:nonminimal-bool-limit-ops, r=y21
Limit number of `nonminimal_bool` ops

Fixes https://github.com/rust-lang/rust-clippy/issues/11257
Fixes https://github.com/rust-lang/rust-clippy/issues/13206

changelog: none
2024-08-03 15:50:00 +00:00
bors
eb7b6769f1 Auto merge of #13208 - alex-semenyuk:fix_doc_from_iter_instead_of_collect, r=llogiq
Add clarification for from_iter_instead_of_collect

Close #13147

As mentioned at #13147 we should prefer to use collect depends on situation so clarify this at documentation and provide examples this cases.

changelog: none
2024-08-03 15:09:06 +00:00
alexey semenyuk
35dcc9bbfa Add clarification for from_iter_instead_of_collect 2024-08-03 19:28:21 +05:00
Alex Macleod
d18ce7cea0 lintcheck: force warn all lints 2024-08-03 12:28:52 +00:00
Alex Macleod
b2d0631300 Limit number of nonminimal_bool ops 2024-08-03 12:07:42 +00:00
bors
0347280d5f Auto merge of #13107 - yaxum62:i5757, r=xFrednet
Add test for `try_err` lint within try blocks.

Fixes #5757

Turns out the current `try_err` implementation already skips expressions inside of a try block.

When inside of a try block, `Err(_)?` is desugared to a `break` instead of normal `return` . This makes `find_return_type()` function at [this line](eb4d88e690/clippy_lints/src/matches/try_err.rs (L29)) always returns `None` and skips the check.

I just added a test case for try block.

changelog: none
2024-08-03 08:25:37 +00:00
xFrednet
0532104247
Migrating restriction lints to span_lint_and_then (e -> i) 2024-08-03 10:18:15 +02:00
xFrednet
a9d72c7107
Migrating restriction lints to span_lint_and_then (a -> d) 2024-08-03 10:18:05 +02:00
bors
1ea827fa03 Auto merge of #13115 - tesuji:rm-dup-peels, r=dswij
Remove duplicated `peel_middle_ty_refs`

TODO: Should we move `ty::peel_mid_ty_refs_is_mutable` to super module too?

changelog: none
2024-08-03 07:32:30 +00:00
bors
1aa686b9c0 Auto merge of #13126 - apoisternex:issue12751, r=dswij
Fix [`redundant_slicing`] when the slice is behind a mutable reference

Fixes #12751

changelog: Fix [`redundant_slicing`] when the slice is behind a mutable reference and a immutable reference is expected.
2024-08-03 07:23:58 +00:00
Esteban Küber
5ef38a3bc7 Do not underline suggestions for code that is already there
When a suggestion part is for already present code, do not highlight it. If after that there are no highlights left, do not show the suggestion at all.

Fix clippy lint suggestion incorrectly treated as `span_help`.
2024-08-01 18:53:42 +00:00
bors
2fc74a3931 Auto merge of #13108 - tesuji:fix_redundant_closure, r=xFrednet
Fix `redundant_closure` false positive with closures has return type contains  `'static`

Fix #13073 .

Please enable "ignore white-space change" settings in github UI for easy reviewing.

HACK: The third commit contains a hack to check if a type `T: 'static` when `fn() -> U where U: 'static`.
I don't have a clean way to check for it.

changelog: [`redundant_closure`] Fix false positive with closures has return type contains  `'static`
2024-08-01 07:55:37 +00:00
bors
5542309895 Auto merge of #13195 - GuillaumeGomez:fix-false-positive-13183, r=Manishearth
Fix false positive for `missing_backticks` in footnote references

Fixes #13183.

changelog: Fix false positive for `missing_backticks` in footnote references
2024-07-31 16:06:27 +00:00
Guillaume Gomez
edca73003b Fix false positive for missing_backticks in footnote references 2024-07-31 17:27:53 +02:00
bors
ea06fa326d Auto merge of #13177 - GuillaumeGomez:fix-broken-list-lints-config, r=xFrednet
Fix broken list for lints config

Follow-up of #13166.

Finally figured out that it was a transformation and not the source that was the problem. It now looks like this:

![Screenshot from 2024-07-29 16-29-10](https://github.com/user-attachments/assets/4b89b3fe-8f85-47b8-8d9a-505badeaeac4)

r? `@xFrednet`

changelog: none
2024-07-31 11:11:39 +00:00
bors
c6f45df3c1 Auto merge of #13181 - Alexendoo:implicit-hasher-suggestion, r=llogiq
Use a single multipart suggestion for `implicit_hasher`

The second commit individually shows the diagnostic change

----

changelog: none
2024-07-30 20:02:53 +00:00
alexey semenyuk
8bf5a83322
Fix example 2024-07-30 22:34:56 +05:00
Guillaume Gomez
7c5209121d Add new settings menu 2024-07-30 17:31:42 +02:00
Guillaume Gomez
b7e7975ded Move style into its file 2024-07-30 16:01:36 +02:00
bors
8f3cfb4974 Auto merge of #13182 - Alexendoo:remove-allows, r=Manishearth
Remove some miscellaneous `#[allow]`s

Some were unneeded, others were removed by fixing/removing the thing they allow

changelog: none
2024-07-30 02:34:26 +00:00
bors
accf6868ee Auto merge of #13178 - GuillaumeGomez:clippy-lints-page-improvement, r=Alexendoo
Add possibility to focus on search input using keyboard

This PR adds the possibility to focus on the search input with `S` or `/` like in rustdoc and `mdbook` and `docs.rs` (unification++). Pressing escape will blur it.

r? `@Alexendoo`

changelog: Add possibility to focus on search input using keyboard
2024-07-29 19:58:12 +00:00
Alex Macleod
943a8e0646 Remove some miscellaneous #[allow]s 2024-07-29 19:57:39 +00:00
Guillaume Gomez
63174792c2 Add possibility to focus on search input using keyboard 2024-07-29 21:55:36 +02:00
Alex Macleod
33b16d31c2 implicit_hasher: use a single multipart suggestion 2024-07-29 17:56:27 +00:00
Alex Macleod
79783e95ad Fix implicit_hasher test not compiling 2024-07-29 17:44:57 +00:00