Commit Graph

19164 Commits

Author SHA1 Message Date
bors
fb060815b3 Auto merge of #11136 - y21:enhance_read_line_without_trim, r=dswij
[`read_line_without_trim`]: detect string literal comparison and `.ends_with()` calls

This lint now also realizes that a comparison like `s == "foo"` and calls such as `s.ends_with("foo")` will fail if `s` was initialized by a call to `Stdin::read_line` (because of the trailing newline).

changelog: [`read_line_without_trim`]: detect string literal comparison and `.ends_with()` calls

r? `@giraffate` assigning you because you reviewed #10970 that added this lint, so this is kinda a followup PR ^^
2024-02-27 03:36:12 +00:00
bors
d12b53e481 Auto merge of #12116 - J-ZhengLi:issue12101, r=Alexendoo
fix suggestion error in [`useless_vec`]

fixes: #12101

---

changelog: fix suggestion error in [`useless_vec`]

r+ `@matthiaskrgr` since they opened the issue?
2024-02-26 22:38:24 +00:00
y21
fd85db3636 restructure lint code, update description, more cases 2024-02-26 20:24:46 +01:00
y21
cfddd91c91 [read_line_without_trim]: catch string eq checks 2024-02-26 20:19:15 +01:00
bors
1c5094878b Auto merge of #12342 - lucarlig:empty-docs, r=llogiq
Empty docs

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

changelog: [`empty_doc`]: Detects documentation that is empty.
changelog: Doc comment lints now trigger for struct field and enum variant documentation
2024-02-26 18:03:13 +00:00
bors
d71899573a Auto merge of #12355 - Ethiraric:fix-11927, r=Alexendoo
[`box_default`]: Preserve required path segments

When encountering code such as:
```rs
Box::new(outer::Inner::default())
```
clippy would suggest replacing with `Box::<Inner>::default()`, dropping the `outer::` segment. This behavior is incorrect and that commit fixes it.

What it does is it checks the contents of the `Box::new` and, if it is of the form `A::B::default`, does a text replacement, inserting `A::B` in the `Box`'s quickfix generic list.
If the source does not match that pattern (including `Vec::from(..)` or other `T::new()` calls), we then fallback to the original code.

Fixes #11927

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`box_default`]: Preserve required path segments
2024-02-26 17:25:43 +00:00
Ethiraric
97dc4b22c6 [box_default]: Preserve required path segments
When encountering code such as:
```
Box::new(outer::Inner::default())
```
clippy would suggest replacing with `Box::<Inner>::default()`, dropping
the `outer::` segment. This behavior is incorrect and that commit fixes
it.

What it does is it checks the contents of the `Box::new` and, if it is
of the form `A::B::default`, does a text replacement, inserting `A::B`
in the `Box`'s quickfix generic list.
If the source does not match that pattern (including `Vec::from(..)`
or other `T::new()` calls), we then fallback to the original code.

Fixes #11927
2024-02-26 17:39:00 +01:00
bors
a11875bd22 Auto merge of #12353 - lucarlig:book, r=flip1995
add cargo.toml lint section way of adding lints in the book

changelog: add cargo.toml lint section way of adding lints in the book

as from [discussion on zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.E2.9C.94.20clippy.20config)
2024-02-26 15:53:46 +00:00
Philipp Krones
6d0b70e08f
Clean up Allowing/Denying Lints section 2024-02-26 16:43:05 +01:00
lucarlig
fca77c0976 docs and imports 2024-02-26 19:15:44 +04:00
lucarlig
80bafa5d45 add cargo.toml lint section way of adding lints 2024-02-26 18:59:05 +04:00
bors
b09fb8ab3b Auto merge of #12350 - hamirmahal:style/sync-GitHub-Corner-colors, r=xFrednet
style: sync GitHub Corner colors

fixes #12349.

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: sync site GitHub Corner colors
2024-02-26 08:28:00 +00:00
Hamir Mahal
3ef693c555
refactor: remove CSS variables that are now unused 2024-02-26 00:00:33 -08:00
lucarlig
93deced553 change rs doc to no_run 2024-02-26 07:02:40 +04:00
bors
aa2c94e416 Auto merge of #12308 - y21:more_implied_bounds, r=xFrednet
Look for `implied_bounds_in_impls` in more positions

With this, we lint `impl Trait` implied bounds in more positions:
- Type alias impl trait
- Associated type position impl trait
- Argument position impl trait
  - these are not opaque types, but instead are desugared to `where` clauses, so we need extra logic for finding them (`check_generics`), however the rest of the logic is the same

Before this, we'd only lint RPIT `impl Trait`s.
"Hide whitespaces" and reviewing commits individually might make this easier

changelog: [`implied_bounds_in_impls`]: start linting implied bounds in APIT, ATPIT, TAIT
2024-02-25 22:20:37 +00:00
y21
bbfe1c1ec3 lint implied bounds in APIT 2024-02-25 23:12:28 +01:00
y21
ec29b0d6b8 lint implied bounds in *all* opaque impl Trait types 2024-02-25 23:09:59 +01:00
bors
7353bd0341 Auto merge of #12256 - y21:single_call_fn_rm_visitor, r=llogiq
Merge `single_call_fn` post-crate visitor into lint pass

The `single_call_fn` lint worked by first collecting a list of function definitions in the lint pass, then populating the list of uses for each function in a second visitor after the crate is checked.
Doing another pass through the crate shouldn't be needed, and we should be able to do it in the same lint pass, by looking for path references to functions only and then processing them post-crate.

Other changes:
- `FxHashMap` -> `FxIndexMap` so that we emit warnings in a consistent order, as we see them (making the diff a bit confusing to look at, because warnings were moved around)
- no longer storing a `Vec<Span>` per function: an enum representing "seen once" or "seen more than once" should be enough (only the first element is used later)
- "used here" help is now a note

I also noticed that it lints on trait methods with a default implementation, but not on regular trait methods without a body (because that's what `check_fn` does). I'm not sure if that's useful though, maybe we shouldn't lint trait methods at all? It's not like you can avoid it sometimes (but then again it's a restriction lint). Either way, I left the behavior where it was before so that there are no functional changes made in this PR and it's purely a refactor. I can change it though

changelog: none
2024-02-25 22:02:55 +00:00
Hamir Mahal
30ee7af2ca
style: sync GitHub Corner colors 2024-02-25 12:54:46 -08:00
lucarlig
5152050c5f move lint directly into check_attrs 2024-02-25 23:17:03 +04:00
lucarlig
ee50d5df90 correct wrong doc syntax 2024-02-25 22:52:44 +04:00
lucarlig
d84d9d32f1 lint on variant and fields as well 2024-02-25 22:33:16 +04:00
bors
10c99031ce Auto merge of #12348 - Alexendoo:remove-get-parent-node, r=y21
Remove `clippy_utils::get_parent_node`

Since it's forwarding to a single method it seems reasonable to use that one directly instead

changelog: none
2024-02-25 17:43:59 +00:00
lucarlig
f066be7e1e use span of fragments 2024-02-25 21:31:46 +04:00
lucarlig
d7ad85f521 move the the check into check_atr function 2024-02-25 21:26:43 +04:00
lucarlig
f32e92cdc9 add 1 more test and dont trim other code 2024-02-25 21:18:38 +04:00
Alex Macleod
bee4111a61 Remove clippy_utils::get_parent_node 2024-02-25 16:35:17 +00:00
y21
9a56153c5e [single_call_fn]: merge post-crate visitor into lint pass 2024-02-25 17:13:47 +01:00
bors
c469cb0023 Auto merge of #12336 - not-elm:fix/issue-12243, r=y21
FIX(12243): redundant_guards

Fixed #12243

changelog: Fix[`redundant_guards`]

I have made a correction so that no warning does  appear when y.is_empty() is used within a constant function as follows.

```rust
pub const fn const_fn(x: &str) {
    match x {
        // Shouldn't lint.
        y if y.is_empty() => {},
        _ => {},
    }
}
```
2024-02-25 14:56:07 +00:00
lucarlig
5a50cede29 add single letter test 2024-02-25 18:01:53 +04:00
lucarlig
97e4c57f24 fix lint doc 2024-02-25 17:51:58 +04:00
lucarlig
ee0cbeaa77 ignore empty comment in semicolon_if_nothing_returned 2024-02-25 17:41:41 +04:00
lucarlig
0ea449597e pop before trimming 2024-02-25 17:23:15 +04:00
lucarlig
9ac6125e1d add extra variant because no more than 3 bools 2024-02-25 17:16:07 +04:00
lucarlig
a3fea80a68 bless tests 2024-02-25 17:04:58 +04:00
lucarlig
09c7c5d2c9 fix bug in check_exprs 2024-02-25 16:52:58 +04:00
lucarlig
84219f45a3 working naive with outside check_attrs 2024-02-25 16:11:14 +04:00
bors
76e4864119 Auto merge of #12339 - GuillaumeGomez:add-unnecessary_get_then_check, r=llogiq
Add new `unnecessary_get_then_check` lint

No issue linked to this as far as I can see. It's a lint I discovered that could be added when I worked on another lint.

r? `@llogiq`

changelog: Add new `unnecessary_get_then_check` lint
2024-02-25 10:39:24 +00:00
bors
8ef1b73442 Auto merge of #12346 - klensy:itertools-bump, r=llogiq
bump itertools to 0.12

Bumps itertools to newer 0.12 version, https://github.com/rust-itertools/itertools/blob/v0.12.1/CHANGELOG.md

changelog: none
2024-02-25 10:25:16 +00:00
klensy
cdaccd7fce bump itertools to 0.12 2024-02-25 13:14:07 +03:00
bors
0d1ba48cb4 Auto merge of #12345 - xFrednet:00000-some-healthy-life-choices, r=xFrednet
Pause PR assignments for xFrednet :)

My life is currently a bit chaotic, and it feels like I can't give reviews the attention they need. I'll finish the PRs I'm assigned to, write the changelogs, and am available when I get pinged etc.

This is only intended as a temporary pause, as I still genuinely enjoy working with everyone in this repo and seeing Clippy grow day by day.

---

changelog: none

r? `@ghost`
2024-02-25 09:57:59 +00:00
xFrednet
6b7700ef49
Pause PR assignments for xFrednet :) 2024-02-25 10:18:55 +01:00
not-elm
5a63cd82cb FIX(12243): redundant_guard
A warning is now suppressed when "<str_va> if <str_var>.is_empty" is used in a constant function.

FIX: instead of clippy_util::in_const

FIX: Merged `redundant_guards_const_fn.rs` into `redundant_guards.rs`.
2024-02-25 15:38:18 +09:00
lucarlig
3093b291f6 WIP: empty doc span is still broken 2024-02-25 09:55:58 +04:00
Guillaume Gomez
5e2707d343 Fix new lint warnings 2024-02-24 15:02:10 +01:00
Guillaume Gomez
a1971414ec Update ui tests 2024-02-24 15:02:10 +01:00
Guillaume Gomez
40cff2d99f Add ui test for unnecessary_get_then_check 2024-02-24 15:02:10 +01:00
Guillaume Gomez
ad319484f1 Add new unnecessary_get_then_check clippy lint 2024-02-24 15:02:10 +01:00
bors
a2c1d565e5 Auto merge of #12259 - GuillaumeGomez:multiple-bound-locations, r=llogiq
Add new `multiple_bound_locations` lint

Fixes #7181.

r? `@llogiq`

changelog: Add new `multiple_bound_locations` lint
2024-02-24 13:43:34 +00:00
bors
64054693eb Auto merge of #12322 - sanxiyn:expression-with-attribute, r=llogiq
Be careful with expressions with attributes

Fix #9949.

changelog: [`unused_unit`]: skip expressions with attributes
2024-02-24 10:52:55 +00:00