Commit graph

11202 commits

Author SHA1 Message Date
Alex Macleod
66362efb09 Don't suggest Box::default() in functions with differing generics 2024-04-17 14:40:00 +00:00
Luv-Ray
da0ae33c15 [ptr_as_ptr]: Fix duplicate errors 2024-04-15 18:06:15 +02:00
bors
7063e3435c Auto merge of #12094 - yuxqiu:search_is_some, r=xFrednet,ARandomDev99
fix: incorrect suggestions when `.then` and `.then_some` is used

fixes #11910

In the current implementation of `search_is_some`, if a `.is_none` call is followed by a `.then` or `.then_some` call, the generated `!` will incorrectly negate the values returned by the `then` and `.then_some` calls. To fix this, we need to add parentheses to the generated suggestions when appropriate.

changelog: [`search_is_some`]: add parenthesis to suggestions when appropriate
2024-04-14 19:27:42 +00:00
bors
832fdb6d30 Auto merge of #12573 - modelflat:recognize-common-prepositions-in-module-name-repetitions, r=Jarcho
[`module_name_repetition`] Recognize common prepositions

Fixes #12544

changelog: [`module_name_repetition`]: don't report an item name if it consists only of a prefix from `allowed-prefixes` list and a module name (e.g. `AsFoo` in module `foo`). Prefixes allowed by default: [`to`, `from`, `into`, `as`, `try_into`, `try_from`]
2024-04-12 18:53:03 +00:00
bors
0d84f00156 Auto merge of #12635 - Alexendoo:doc-check-attributes, r=Jarcho
Use `check_attributes` in doc lints

Ensures we catch all the places that doc comments could occur, found one that we were currently missing - docs on `extern` items

changelog: none
2024-04-12 18:40:31 +00:00
bors
6b1c828d91 Auto merge of #12661 - jqnatividad:unsafe_derive_deserialize-why_is_this_bad-typo, r=Alexendoo
unsafe_derive_deserialize: `Why is this bad?` explanation typo

changelog: [`unsafe_derive_deserialize`]: Correct `Why is this bad?` explanation typo
2024-04-11 15:05:58 +00:00
bors
7dca8152cf Auto merge of #12660 - jqnatividad:fix-various-typos, r=Alexendoo
Fix various typos

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

changelog: fix several typos
2024-04-11 14:55:44 +00:00
cowlicks
8b5447c622
Fix typo in needless_borrows_for_generic_args.rs 2024-04-10 12:57:24 -05:00
Joel Natividad
d7a8622bf4
Why is this bad explanation typo 2024-04-10 08:46:03 -04:00
Joel Natividad
8de0a1bdbd
fix varname typo 2024-04-10 08:37:30 -04:00
Joel Natividad
e5b6d433fb
fix various comment typos 2024-04-10 08:37:02 -04:00
bors
62fd1d5377 Auto merge of #12646 - GuillaumeGomez:regression-test-12537, r=blyxyas
Turn `duplicated_attributes` into a late lint

Fixes #12537.

changelog: Turn `duplicated_attributes` into a late lint
2024-04-09 15:05:42 +00:00
Guillaume Gomez
f7d49a340d Turn duplicated_attributes into a late lint 2024-04-09 16:42:26 +02:00
bors
54e8ad88b6 Auto merge of #12652 - Wilfred:patch-2, r=Alexendoo
Fix markdown syntax in str_split_at_newline docs

changelog: [`str_split_at_newline`] Fix formatting of docs
2024-04-09 09:03:37 +00:00
modelflat
3705073a71 Recognize common prefixes when checking for items with module name suffix
Fixes #12544.

- don't report an item name if it consists only of a prefix from `allowed-prefixes` list and a module name (e.g. `AsFoo` in module `foo`).
- configured by `allowed-prefixes` config entry
- prefixes allowed by default: [`to`, `from`, `into`, `as`, `try_into`, `try_from`]
- update docs
2024-04-09 09:47:54 +02:00
bors
1b6561f59b Auto merge of #12630 - mira-eanda:master, r=Manishearth
Correct parentheses for [`needless_borrow`] suggestion

This fixes #12268

Clippy no longer adds unnecessary parentheses in suggestions when the expression is part of a tuple.

---

changelog: Fix [`needless_borrow`] unnecessary parentheses in suggestion.
2024-04-08 23:17:42 +00:00
Mariana Miranda
8ae7eaefdc fix: Refactor dereference code and fix test 2024-04-08 23:35:19 +01:00
Wilfred Hughes
db3a927432
Fix markdown syntax in str_split_at_newline docs 2024-04-08 12:50:28 -07:00
bors
2202493a67 Auto merge of #12626 - folkertdev:incorrect-boolean-simplification, r=blyxyas
fix incorrect suggestion for `!(a as type >= b)`

fixes #12625

The expression  `!(a as type >= b)` got simplified to `a as type < b`, but because of rust's parsing rules that `<` is interpreted as a start of generic arguments for `type`.  This is fixed by recognizing this case and adding extra parens around the left-hand side of the comparison.

changelog: [`nonminimal_bool`]: fix incorrect suggestion for  `!(a as type >= b)`
2024-04-08 11:05:09 +00:00
bors
1c9e96536b Auto merge of #12610 - ARandomDev99:manual_unwrap_or_default-12564, r=dswij
[`manual_unwrap_or_default`]: Check for Default trait implementation in initial condition when linting and use `IfLetOrMatch`

Fixes #12564

changelog: Fix [`manual_unwrap_or_default`] false positive when initial `match`/`if let` condition doesn't implement `Default` but the return type does.
2024-04-08 07:24:17 +00:00
Folkert
6a2cb33029
fix incorrect suggestion for !(a as type >= b) 2024-04-07 19:17:49 +02:00
Alex Macleod
d4a8f61eb3 Use check_attributes in doc lints 2024-04-05 16:12:07 +00:00
bors
08dac852a5 Auto merge of #12631 - franciscoBSalgueiro:11738, r=blyxyas
Allow `cast` lints in macros

closes: #11738

Removed the `from_expansion` guard clause for cast lints, so that these warnings can be generated for internal macros.

changelog: allow `cast` lints in macros
2024-04-04 23:02:55 +00:00
bors
a73e751d19 Auto merge of #12609 - Alexendoo:arc-with-non-send-sync-message, r=Jarcho
Reword `arc_with_non_send_sync` note and help messages

Addresses https://github.com/rust-lang/rust-clippy/issues/12608#issuecomment-2029688054

Makes the note more concise and reframes the `Rc` suggestion around whether it crosses threads currently due to a manual `Send`/`Sync` impl or may do in the future

changelog: none
2024-04-04 21:59:21 +00:00
Philipp Krones
277303b210
Merge remote-tracking branch 'upstream/master' into rustup 2024-04-04 19:48:31 +02:00
Mariana Miranda
38b8056fc6 Fix: #12268: Correct parentheses for needless_borrow suggestion
Clippy no longer adds unnecessary parentheses in suggestion when the expression is a part of a tuple.
2024-04-04 10:24:25 +01:00
bors
398a52a8dc Auto merge of #12340 - not-elm:fix/issue-12334, r=llogiq
FIX(12334): manual_swap auto fix

Fixed: #12334

Initialization expressions are now generated as needed if the slice index is bound to a variable.

----

changelog: Fix [`manual_swap`]
2024-04-04 09:16:44 +00:00
Francisco Salgueiro
ac225a3b1f
Fix #11738: allow cast lints in macros
Removed the `from_expansion` guard clause for cast lints, so that these warnings can be generated for internal macros.
2024-04-03 21:43:06 +01:00
bors
e80ca2f381 Auto merge of #12615 - Kobzol:fix-recursive-clone-from, r=blyxyas
Do not suggest `assigning_clones` in `Clone` impl

This PR modifies `assigning_clones` to detect situations where the `clone` call is inside a `Clone` impl, and avoids suggesting the lint in such situations.

r? `@blyxyas`

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

changelog: Do not invoke `assigning_clones` inside `Clone` impl
2024-04-03 19:07:51 +00:00
Jakub Beránek
571118f4b0 Do not suggest assigning_clones in Clone impl 2024-04-03 20:55:34 +02:00
Aneesh Kadiyala
ac18c24fe8 Use IfLetOrMatch to avoid repetition of code 2024-04-02 22:49:00 +05:30
bors
f9f854f428 Auto merge of #12617 - y21:issue-12616, r=Alexendoo
avoid an ICE in `ptr_as_ptr` when getting the def_id of a local

Fixes #12616

`Res::def_id` can panic, so avoid calling it in favor of `opt_def_id`, so we can gracefully handle resolutions that don't have a `DefId` (e.g. local variables) and get a false negative in the worst case, rather than an ICE

changelog: Fix ICE in [`ptr_as_ptr`] when the cast expression is a function call to a local variable
2024-04-02 13:40:00 +00:00
not-elm
0478d26c8b FIX(12334): manual_swap auto fix
Initialization expressions are now generated when index is bound to a variable.

FIX: Check to see if variables are used after swap

FIX:  rename StmtKind::Local to StmtKind::Let
2024-04-02 22:30:34 +09:00
y21
e575f05a8b avoid an ICE in ptr_as_ptr when getting the def_id of a local 2024-04-02 15:09:32 +02:00
bors
95c45be1ed Auto merge of #12603 - m-rph:12594, r=Manishearth
Elide unit variables linted by `let_unit` and use `()` directly instead

Situation: `let_unit` lints when an expression binds a unit (`()`) to a variable. In some cases this binding may be passed down to another function. Currently, the lint removes the binding without considering usage.

fixes: #12594

changelog: Suggestion Fix [`let_unit`]. Clippy will remove unit bindings and replace all their instances in the body with `()`.
2024-04-01 21:14:32 +00:00
Yuxiang Qiu
b89fa5364f
fix: fix ci errors 2024-04-01 16:59:46 -04:00
Yuxiang Qiu
9d1f824878
fix: check if receiver's hir_id matches expr's hir_id 2024-04-01 16:57:31 -04:00
Yuxiang Qiu
b2ea5eef44
fix: incorrect suggestions when .then and .then_some is used 2024-04-01 16:57:31 -04:00
J-ZhengLi
b456ed31e4 fix suggestion for [len_zero] with macros 2024-04-02 01:27:17 +08:00
Aneesh Kadiyala
6a6a917fe4 Check for Default trait in initial expression 2024-04-01 20:18:03 +05:30
Alex Macleod
9d4a36841a Reword arc_with_non_send_sync note and help messages 2024-04-01 13:18:27 +00:00
y21
91f514cc83 fix fallout from previous commit 2024-04-01 15:04:45 +02:00
Quinn Sinclair
eee4db928f Replace elided variable in let_unit with () when used
Situation: `let_unit` lints when an expression binds a unit (`()`)
to a variable. In some cases this binding may be passed down to
another function. Currently, the lint removes the binding without
considering usage.

Change: All usages of the elided variable are now replaced with `()`.

fixes: #12594
2024-04-01 13:40:36 +02:00
Alex Macleod
0f63fa8c33 Move box_default to style, do not suggest turbofishes
`Box::default()` had its `#[rustc_box]` attribute removed in 1.69 so is
no longer a perf related lint

The lint is moved to style but no longer produces suggestions containing
turbofishes, as they're often longer/more annoying to type
2024-03-31 16:46:44 +00:00
bors
797d50dfe6 Auto merge of #12562 - m-rph:12501, r=y21
Allow `filter_map_identity` when the closure is typed

This extends the `filter_map_identity` lint to support typed closures.

For untyped closures, we know that the program compiles, and therefore we can safely suggest using flatten.

For typed closures, they may participate in type resolution. In this case we use `Applicability::MaybeIncorrect`.

Details:
https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Should.20.60filter_map_identity.60.20lint.20when.20closures.20are.20typed.3F

changelog: `filter_map_identity` will now suggest using flatten for typed closures.

r? `@y21` && `@Centri3`
2024-03-31 12:16:01 +00:00
bors
3787a0ccb8 Auto merge of #11350 - y21:issue11349, r=xFrednet
[`type_id_on_box`]: lint on any `Box<dyn _>`

Closes #11349.

It now not only lints when calling `.type_id()` on the type `Box<dyn Any>`, but also on any `Box<dyn Trait>` where `Trait` is a subtrait of `Any`

changelog: FN: [`type_id_on_box`]: lint if `Any` is a sub trait
2024-03-30 21:26:36 +00:00
y21
36e4c2083b lint on any Box<dyn _>, but provide a suggestion for subtypes of dyn Any 2024-03-30 20:52:53 +01:00
bors
cebf879de8 Auto merge of #12312 - pitaj:legacy_numeric_constants, r=xFrednet
new lint `legacy_numeric_constants`

Rework of #10997

- uses diagnostic items
- does not lint imports of the float modules (`use std::f32`)
- does not lint usage of float constants that look like `f32::MIN`

I chose to make the float changes because the following pattern is actually pretty useful
```rust
use std::f32;
let omega = freq * 2 * f32::consts::PI;
```
and the float modules are not TBD-deprecated like the integer modules.

Closes #10995

---

changelog: New lint [`legacy_numeric_constants`]
[#12312](https://github.com/rust-lang/rust-clippy/pull/12312)
2024-03-30 17:50:36 +00:00
bors
e0e7ee183f Auto merge of #12563 - J-ZhengLi:issue11513, r=Alexendoo
make sure checked type implements `Try` trait when linting [`question_mark`]

(indirectly) fixes: #12412 and fixes: #11983

---

changelog: make sure checked type implements `Try` trait when linting [`question_mark`]
2024-03-30 13:21:20 +00:00
bors
88d842ed29 Auto merge of #12579 - J-ZhengLi:issue12569, r=Alexendoo
fix [`manual_unwrap_or_default`] suggestion ignoring side-effects

fixes: #12569
closes: #12580

change applicability to `MaybeIncorrect` base on suggestion in [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.60manual_unwrap_or_default.60.20suggestion.20removes.20comments)

---

changelog: fix [`manual_unwrap_or_default`] suggestion ignoring side-effects, and adjust its applicability.
2024-03-30 12:32:38 +00:00