Commit graph

8963 commits

Author SHA1 Message Date
Jason Newcomb
e34c6dbae5 Refactor for using config values:
* Construct lint passes by taking `Conf` by reference.
* Use `HashSet` configs in less places
* Move some `check_crate` code into the pass constructor when possible.
2024-07-17 14:05:49 -04:00
Alex Macleod
0b0c39ca4d Show progress while running dogfood test 2024-07-17 12:29:18 +00:00
Lzu Tao
5540060d5d Skip linting if array length is from a macro. 2024-07-17 18:33:36 +07:00
Lzu Tao
c65ddb8728 Add regression test for issue 13110 2024-07-17 18:32:18 +07:00
Noah Lev
f2c1265483 Add ConstArgKind::Path and make ConstArg its own HIR node
This is a very large commit since a lot needs to be changed in order to
make the tests pass. The salient changes are:

- `ConstArgKind` gets a new `Path` variant, and all const params are now
  represented using it. Non-param paths still use `ConstArgKind::Anon`
  to prevent this change from getting too large, but they will soon use
  the `Path` variant too.

- `ConstArg` gets a distinct `hir_id` field and its own variant in
  `hir::Node`. This affected many parts of the compiler that expected
  the parent of an `AnonConst` to be the containing context (e.g., an
  array repeat expression). They have been changed to check the
  "grandparent" where necessary.

- Some `ast::AnonConst`s now have their `DefId`s created in
  rustc_ast_lowering rather than `DefCollector`. This is because in some
  cases they will end up becoming a `ConstArgKind::Path` instead, which
  has no `DefId`. We have to solve this in a hacky way where we guess
  whether the `AnonConst` could end up as a path const since we can't
  know for sure until after name resolution (`N` could refer to a free
  const or a nullary struct). If it has no chance as being a const
  param, then we create a `DefId` in `DefCollector` -- otherwise we
  decide during ast_lowering. This will have to be updated once all path
  consts use `ConstArgKind::Path`.

- We explicitly use `ConstArgHasType` for array lengths, rather than
  implicitly relying on anon const type feeding -- this is due to the
  addition of `ConstArgKind::Path`.

- Some tests have their outputs changed, but the changes are for the
  most part minor (including removing duplicate or almost-duplicate
  errors). One test now ICEs, but it is for an incomplete, unstable
  feature and is now tracked at #127009.
2024-07-16 19:27:28 -07:00
Yuri Astrakhan
197b444407 Ignore underscore-prefixed args for needless_pass_by_value lint
When a user explicitly tags a param as unused (yet?), there is no need to raise another lint on it.
2024-07-16 18:00:11 -04:00
yaxum62
1821defc39 add expected output for try_err test 2024-07-15 21:54:15 -07:00
yaxum62
fceeb13399 Add test for try_err lint within try blocks. 2024-07-15 21:21:52 -07:00
Michael Goulet
c1c945a350 Move rustc_infer::infer::error_reporting to rustc_infer::error_reporting::infer 2024-07-15 20:16:12 -04:00
apoisternex
489a77831c fix [excessive_precision] suggestions on float literal written in scientific notation
fixes: #12954

changelog: fix [`excessive_precision`] suggestions on float literal written in scientific notation
2024-07-15 18:52:18 -03:00
bors
eb4d88e690 Auto merge of #13102 - tesuji:fix-needless_option_as_deref, r=Alexendoo
Fix `needless_option_as_deref` false-positive on struct literals

changelog: [`needless_option_as_deref`] Fix false-positive on struct literals.

Fixes #13077 .

r?  Alexendoo
2024-07-15 16:23:41 +00:00
Lzu Tao
dcee2e8a0f Dont stop find loop node at struct field node 2024-07-15 15:56:17 +00:00
Lzu Tao
4264548283 Add regression test for issue 13077 2024-07-15 15:55:22 +00:00
Oli Scherer
3b390d416d Bump clippy version 2024-07-15 08:51:04 +00:00
bors
10ba798736 Auto merge of #13093 - waywardmonkeys:more-doc-valid-idents, r=Alexendoo
Add more doc-valid-idents

* "AccessKit" is a commonly used accessibility toolkit used in Rust GUIs.
* "CoreFoundation", "CoreGraphics", "CoreText" are frameworks on Apple OSes.
* "Direct2D", "Direct3D", "DirectWrite" are frameworks on Windows
* "PostScript" is a programming language and is mentioned when talking about text and vector graphics.
* "OpenAL" is an audio framework / API.
* "OpenType" is a font format (TrueType is already mentioned).
* "WebRTC", "WebSocket", "WebTransport" are web networking technologies.
* "NetBSD" and "OpenBSD" are like the already included FreeBSD.

changelog: [`doc_markdown`]: Add AccessKit, CoreFoundation, CoreGraphics, CoreText, Direct2D, Direct3D, DirectWrite, PostScript, OpenAL, OpenType, WebRTC, WebSocket, WebTransport, NetBSD, and OpenBSD to `doc-valid-idents`.
2024-07-14 14:09:20 +00:00
bors
e7d17e6cb2 Auto merge of #13061 - tesuji:fix-map-unwrap-or-13018, r=dswij
Fix `manual_unwrap_or` false positive

changelog: [`manual_unwrap_or`]: fix false positive of `if let Option<T>`

Closes #13018
2024-07-13 15:59:11 +00:00
J-ZhengLi
cc1bb8f57a make [or_fun_call] and [unwrap_or_default] recursive. 2024-07-13 23:15:40 +08:00
Bruce Mitchener
39378cf4f4 Add more doc-valid-idents
* "AccessKit" is a commonly used accessibility toolkit used in Rust GUIs.
* "CoreFoundation", "CoreGraphics", "CoreText" are frameworks on Apple OSes.
* "Direct2D", "Direct3D", "DirectWrite" are frameworks on Windows
* "PostScript" is a programming language and is mentioned when talking about
  text and vector graphics.
* "OpenAL" is an audio framework / API.
* "OpenType" is a font format (TrueType is already mentioned).
* "WebRTC", "WebSocket", "WebTransport" are web networking technologies.
* "NetBSD" and "OpenBSD" are like the already included FreeBSD.
2024-07-13 15:50:29 +07:00
J-ZhengLi
983b4c3720 [unwrap_or_default]: skip warning when calling inside of suggested method's implementation 2024-07-12 17:23:08 +08:00
Philipp Krones
c1fd25d0aa Merge commit 'b794b8e08c16517a941dc598bb1483e8e12a8592' into clippy-subtree-update 2024-07-11 15:44:03 +02:00
Philipp Krones
1ced73e66a
Merge remote-tracking branch 'upstream/master' into rustup 2024-07-11 15:29:08 +02:00
Urgau
5f3a6e1805 Remove unary neg from clippy::precedence lint 2024-07-11 00:46:47 +02:00
bors
ef3cfaa4f2 Auto merge of #13081 - GuillaumeGomez:fix-iter_next_loop.rs, r=y21
Fix `iter_next_loop.rs` ui test

I'm uncovering bugs while working on https://github.com/rust-lang/rust-clippy/pull/11421. ^^'

changelog: none
2024-07-10 20:26:03 +00:00
bors
8d3b1f9e30 Auto merge of #12984 - bitfield:fix_doc_nits_c, r=Alexendoo
Fix doc nits

More tender love and polish for the documentation and suggestion texts: adding formatting, links, full stops, tweaking wording for readability, changing 'which' to 'that' where appropriate, and other standard copyediting changes.

changelog: Docs [ `await_holding_lock` ]: fix doc nits
changelog: Docs [ `await_holding_refcell_ref` ]: fix doc nits
changelog: Docs [ `await_holding_invalid_type` ]: fix doc nits
changelog: Docs [ `cast_precision_loss` ]: fix doc nits
changelog: Docs [ `cast_sign_loss` ]: fix doc nits
changelog: Docs [ `cast_possible_truncation` ]: fix doc nits
changelog: Docs [ `cast_possible_wrap` ]: fix doc nits
changelog: Docs [ `cast_lossless` ]: fix doc nits
changelog: Docs [ `unnecessary_cast` ]: fix doc nits
changelog: Docs [ `cast_ptr_alignment` ]: fix doc nits
changelog: Docs [ `fn_to_numeric_cast` ]: fix doc nits
changelog: Docs [ `fn_to_numeric_cast_with_truncation` ]: fix doc nits
changelog: Docs [ `fn_to_numeric_cast_any` ]: fix doc nits
changelog: Docs [ `char_lit_as_u8` ]: fix doc nits
changelog: Docs [ `ptr_as_ptr` ]: fix doc nits
changelog: Docs [ `ptr_cast_constness` ]: fix doc nits
changelog: Docs [ `as_ptr_cast_mut` ]: fix doc nits
changelog: Docs [ `little_endian_bytes` ]: fix doc nits
changelog: Docs [ `big_endian_bytes` ]: fix doc nits
changelog: Docs [ `bind_instead_of_map` ]: fix doc nits
changelog: Docs [ `same_name_method` ]: fix doc nits
2024-07-10 17:55:08 +00:00
Guillaume Gomez
a987c308cd Fix iter_next_loop.rs ui test 2024-07-10 17:18:05 +02:00
bors
b012421501 Auto merge of #12944 - Jarcho:overflow_check, r=y21
Fix and rename `overflow_check_conditional`

fixes #2457

Other changes:
* Limit the lint to unsigned types.
* Actually check if the operands are the same rather than using only the first part of the path.
* Allow the repeated expression to be anything as long as there are no side effects.

changelog: Rename `overflow_check_conditional` to `panicking_overflow_check` and move to `correctness`
2024-07-10 09:02:11 +00:00
bors
ab7c910590 Auto merge of #13079 - sandersaares:u/sasaares/no-epsilon-guidance, r=y21
Fix guidance of [`float_cmp`] and [`float_cmp_const`] to not incorrectly recommend `f__::EPSILON` as the error margin.

Using `f32::EPSILON` or `f64::EPSILON` as the floating-point equality comparison error margin is incorrect, yet `float_cmp` has until now recommended this be done. This change fixes the given guidance (both in docs and compiler hints) to not reference these unsuitable constants.

Instead, the guidance now clarifies that the scenarios in which an absolute error margin is usable, provides a sample implementation for using a user-defined absolute error margin (as an absolute error margin can only be used-defined and may be different for different comparisons) and references the floating point guide for a reference implementation of relative error based equality comparison for cases where absolute error margins cannot be identified.

changelog: [`float_cmp`] Fix guidance to not incorrectly recommend `f__::EPSILON` as the error margin.
changelog: [`float_cmp_const`] Fix guidance to not incorrectly recommend `f__::EPSILON` as the error margin.

Fixes #6816
2024-07-10 06:36:10 +00:00
Philipp Gesang
296dcf09fb
unnecessary_struct_initialization: extend to assignments moving all fields
This lint makes Clippy warn about situations where an owned
struct is essentially recreated by moving all its fields into a
new instance of the struct. Until now this lint only triggered
for structs recreated from a base struct.

NB: The new functionality too will cause false positives for the
situation where a non-copy struct consisting of all copy members
is touched again in subsequent code.
2024-07-09 13:53:11 +02:00
Sander Saares
a067cd24ac Replace incorrect suggested fix for float_cmp
Using `f32::EPSILON` or `f64::EPSILON` as the floating-point equality comparison error margin is incorrect, yet `float_cmp` has until now recommended this be done. This change fixes the given guidance (both in docs and compiler hints) to not reference these unsuitable constants.

Instead, the guidance now clarifies that the scenarios in which an absolute error margin is usable, provides a reference implementation of using a user-defined absolute error margin (as an absolute error margin can only be used-defined and may be different for different comparisons) and references the floating point guide for a reference implementation of relative error based equaltiy comparison for when absolute error margin cannot be used.

changelog: Fix guidance of [`float_cmp`] and [`float_cmp_const`] to not incorrectly recommend `f64::EPSILON` as the error margin.

Fixes #6816
2024-07-09 10:12:09 +03:00
bors
dfb92532fa Auto merge of #12870 - lrh2000:sig-drop-while, r=blyxyas
`significant_drop_in_scrutinee`: Trigger lint also for scrutinees in `while let` and `if let`

This lint should also work for `if let` and `while let`, so this PR makes it actually work.

For `while let`, I can't think of any reason why this lint shouldn't be enabled. The only problem is that the lint suggests moving the significant drop above the `while let`, which is clearly invalid in the case of `while let`. I don't know if this is fixable, but this PR simply disables the wrong suggestions.

For `if let`, it seems that another lint called `if_let_mutex` has some overlapping functionality. But `significant_drop_in_scrutinee` is a bit stricter, as it will trigger even if the `else` branch does not try to lock the same mutex.

changelog: [`significant_drop_in_scrutinee`]: Trigger lint also for scrutinees in `while let` and `if let`.

r? `@blyxyas` (the third PR as promised in https://github.com/rust-lang/rust-clippy/pull/12740#issuecomment-2094876350, thanks for your review!)
2024-07-08 15:09:45 +00:00
bors
2ad8cdc81b Auto merge of #13045 - J-ZhengLi:missing_const_for_fn_FP, r=blyxyas
[`missing_const_for_fn`]: fix FP when arg ty is impl trait alias ty

closes: #13009

---

changelog: [`missing_const_for_fn`]: fix FP when arg ty is impl trait alias ty
2024-07-08 14:39:12 +00:00
J-ZhengLi
08992d0372 [missing_const_for_fn]: fix FP when arg ty is impl trait alias ty 2024-07-08 18:09:49 +08:00
Jason Newcomb
36a14e3a12 misc:
* Delay macro checks.
* Use `span_lint_hir`.
2024-07-07 22:05:26 -04:00
Jason Newcomb
5b7ffa1a63 Rework init_numbered_fields:
* Only check the name of a single field
* Don't lint in macros
* Check for side effects
* Don't use a binary heap
2024-07-07 20:15:19 -04:00
bors
09c07ed63f Auto merge of #13048 - Jarcho:disallowed_methods, r=blyxyas
Refactor `disallowed_methods` and narrow span

Using the span of the call site just produces noisy diagnostics for long calls. Especially multi-line calls.

changelog: none
2024-07-07 14:28:44 +00:00
Jason Newcomb
23d96f65e4 Rename overflow_check_conditional to panicking_overflow_checks. 2024-07-07 10:24:42 -04:00
Jason Newcomb
aa371c37c2 Rewrite overflow_check_conditional 2024-07-07 10:22:29 -04:00
Lzu Tao
c46c1f6da6 Fix 13018: self should be T
with `Option::unwrap_or(self, T) -> T`.
2024-07-07 20:41:55 +07:00
John Arundel
f7050b0c78 resolve code review comments 2024-07-07 10:44:27 +01:00
Lzu Tao
e864519fbc Add test for manual_unwrap_or in issue 13018 2024-07-07 03:34:38 +00:00
lukas
e0f32e09de Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
bors
3ed690f07a Auto merge of #12974 - alex-semenyuk:rename_thread_local_initializer_can_be_made_const, r=Alexendoo
Rename thread_local_initializer_can_be_made_const to missing_const_for_thread_local

Close #12934
As discussed at #12934 name `thread_local_initializer_can_be_made_const` sounds against convention for other lints which describe the issue/wrong code but not suggestion and it is quite long. The new name take example from existing lint `missing_const_for_fn`

changelog: `thread_local_initializer_can_be_made_const` : Rename to [`missing_const_for_thread_local`]
2024-07-05 17:50:06 +00:00
Alexey Semenyuk
6621e6cbfa Rename thread_local_initializer_can_be_made_const to missing_const_for_thread_local 2024-07-05 19:40:37 +05:00
bors
94a000b613 Auto merge of #11293 - mrnossiom:11234, r=Jarcho
feat: add cfg_not_test lint

<!--
- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[ ] Added lint documentation
- \[x] Run `cargo dev fmt`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
-->

Fixes #11234

changelog: new lint: [`cfg_not_test`]

I don't know whether to lint only the `attr` or also the item associated to it. I guess this would mean putting the check in another place than `check_attribute` but I can't find a way to get the associated item to the attribute.

Also, I'm not sure how to document this lint, I feel like my explications are bad.
2024-07-05 11:42:47 +00:00
bors
3ef366705b Auto merge of #13049 - Jarcho:is_in_test, r=Alexendoo
Remove `is_in_test_module_or_function`

Uses are replaced with `is_in_test` for consistency with other lints and to simplify the implementation of the lints. This means the module name is no longer checked, but that was a horrible hack from a time when late passes couldn't see `#[cfg(..)]` attributes.

changelog: none
2024-07-05 11:33:46 +00:00
Milo Moisson
dd37441a64
test: add cfg_not_test tests 2024-07-05 10:28:26 +02:00
Jason Newcomb
60af2585f7 Refactor disallowed_methods:
* Simplify `def_id` extraction.
* Use the span of the method name instead of the call.
2024-07-05 02:37:09 -04:00
Jason Newcomb
4c44b4e3c8 Remove is_test_module_or_function and use is_in_test instead. 2024-07-05 02:17:24 -04:00
bors
885f97e2ce Auto merge of #11656 - y21:unnecessary_string_from_utf8, r=Jarcho
[`unnecessary_to_owned`]: catch `to_owned` on byte slice to create temporary `&str`

Closes #11648

Detects the pattern `&String::from_utf8(bytes.to_vec()).unwrap()` and suggests `core::str::from_utf8(bytes).unwrap()`, which avoids the unnecessary intermediate allocation.

I decided to put this in the existing `unnecessary_to_owned` lint (rather than creating a new lint) for a few reasons:
- we get to use some of its logic (for example, recognizing any of the functions in the `to_owned` family, e.g. `to_vec`)
- the actual inefficient operation that can be avoided here is the call to `.to_vec()`, so this is in a way similar to the other cases caught by `unnecessary_to_owned`, just through a bunch of type conversions
- we can make this more "generic" later and catch other cases, so imo it's best not to tie this lint specifically to the `String` type

changelog: [`unnecessary_to_owned`]: catch `&String::from_utf8(bytes.to_vec()).unwrap()` and suggest `core::str::from_utf8(bytes).unwrap()`
2024-07-05 02:04:06 +00:00
bors
0aac16e5b2 Auto merge of #13037 - J-ZhengLi:issue13008, r=llogiq
[`missing_const_for_fn`]: fix suggestions for fn with abi that requires `const_extern_fn` feature

closes: #13008

---

changelog: [`missing_const_for_fn`]: fix suggestions for fn with abi that requires `const_extern_fn` feature.
2024-07-05 00:20:56 +00:00
Bennet Bleßmann
26cdeed27e bless tests 2024-07-04 22:31:53 +02:00
Bennet Bleßmann
37d8462bd9 fix tests after rebase 2024-07-04 21:27:52 +02:00
Marcel Müller
88c4a22480
New Lint: byte_char_slices
This patch adds a new lint that checks for potentially harder to read
byte char slices: `&[b'a', b'b']` and suggests to replace them with the
easier to read `b"ab"` form.

Signed-Off-By: Marcel Müller <m.mueller@ifm.com>
Co-authored-by: Matthias Beyer <matthias.beyer@ifm.com>

Use iterator to skip validation

Signed-off-by: Marcel Müller <m.mueller@ifm.com>
Suggested-by: Alex Macleod <alex@macleod.io>

Convert quote escapes to proper form

Signed-off-by: Marcel Müller <m.mueller@ifm.com>

Add more convertable test cases

Signed-off-by: Marcel Müller <m.mueller@ifm.com>
2024-07-04 14:31:15 +02:00
J-ZhengLi
3a71223812 [missing_const_for_fn]: fix suggestions for fn with abi that requires const_extern_fn feature 2024-07-04 15:56:11 +08:00
bors
d2400a49a4 Auto merge of #12873 - lochetti:issue_11103, r=llogiq
Add new lint `hashset_insert_after_contains`

This PR closes https://github.com/rust-lang/rust-clippy/issues/11103.

This is my first PR creating a new lint (and the second attempt of creating this PR, the first one I was not able to continue because of personal reasons). Thanks for the patience :)

The idea of the lint is to find insert in hashmanps inside if staments that are checking if the hashmap contains the same value that is being inserted. This is not necessary since you could simply call the insert and check for the bool returned if you still need the if statement.

changelog: new lint: [hashset_insert_after_contains]
2024-07-04 05:39:28 +00:00
Ruihan Li
378962f861 Lint significant drop on while let and if let 2024-07-04 13:18:38 +08:00
Esteban Küber
9b7227cf3f Properly handle removal suggestion rendering
Do not leave a `+ ` line with only whitespace. In reality, the user will want to remove the entire line.
2024-07-04 05:04:48 +00:00
bors
a4bdab38f0 Auto merge of #13027 - xFrednet:12998-expect-returns, r=Jarcho
`needless_return`: Support `#[expect]` on the return statement

A fix for https://github.com/rust-lang/rust-clippy/issues/9361 suppresses `clippy::needless_return` if there are any attributes on the `return` statement. This leads to some unexpected behavior, as described in https://github.com/rust-lang/rust-clippy/issues/12998, where adding `#[expect(clippy::needless_return)]` suppresses the lint, but doesn't fulfill the expectation.

I now decided to manually fulfill any expectations, if they are before the attribute check.

---

Closes: https://github.com/rust-lang/rust-clippy/issues/12998

changelog: none
2024-07-03 19:18:46 +00:00
xFrednet
903874d2f4
needless_return: Support #[expect] on the return statement 2024-07-03 20:58:21 +02:00
Renato Lochetti
6661e83e7b
Rename lint, generalize function, add known issues, use multispan 2024-07-03 19:42:34 +01:00
Renato Lochetti
0f915f6f30
Add new lint hashset_insert_after_contains 2024-07-03 19:41:26 +01:00
bors
0f4035fde3 Auto merge of #12976 - tesuji:fix-explicit_auto_deref, r=xFrednet
Fix some false-positive cases of `explicit_auto_deref`

changelog: [`explicit_auto_deref`] Fix some false-positive cases

Fix part of #9841
Fix  #12969

r? xFrednet
2024-07-03 18:24:23 +00:00
Lzu Tao
c4c41d1352 Fix 12969 and fix 9841 2024-07-03 21:25:43 +07:00
Lzu Tao
7b76b94780 add test 12969 and 9841 2024-07-03 21:09:38 +07:00
bors
918ae1bec4 Auto merge of #11647 - flip1995:needless-pass-by-ref-mut-pub-api, r=xFrednet
Honor `avoid-breaking-exported-api` in `needless_pass_by_ref_mut`

Until now, the lint only emitted a warning, when breaking public API. Now it doesn't lint at all when the config value is not set to `false`, bringing it in line with the other lints using this config value.

Also ensures that this config value is documented in the lint.

changelog: none
(I don't think a changelog is necessary, since this lint is in `nursery`)

---

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

cc `@GuillaumeGomez`

Marking as draft: Does this lint even break public API? If I change a function signature from `fn foo(x: &mut T)` to `fn foo(x: &T)`, I can still call it with `foo(&mut x)`. The only "breaking" thing is that the `clippy::unnecessary_mut_passed` lint will complain that `&mut` at the callsite is not necessary, possibly trickling down to the crate user having to remote a `mut` from a variable. [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=058165a7663902e84af1d23e35c10d66).

Are there examples where this actually breaks public API, that I'm missing?
2024-07-03 07:55:05 +00:00
bors
3af20058eb Auto merge of #13010 - notriddle:notriddle/unbalanced-ticks-backslash, r=blyxyas
doc_markdown: detect escaped `` ` `` when checking unmatched

```
changelog: [`doc_markdown`]: correctly detect backslash-escaped `` ` ``
```
2024-07-02 21:30:36 +00:00
Michael Howell
70c8579e21 doc_markdown: detect escaped ` `` when checking unmatched
Add explanatory comment to complex bounds check

Format
2024-07-02 23:27:14 +02:00
Philipp Krones
2da0edbdf1
Honor avoid-breaking-exported-api in needless_pass_by_ref_mut
Until now, the lint only emitted a warning, when breaking public API. Now it
doesn't lint at all when the config value is not set to `false`, bringing it in
line with the other lints using this config value.

Also ensures that this config value is documented in the lint.
2024-07-02 19:30:01 +02:00
Astra Tsai
ba05b764bc Add regression test for #12964 2024-07-01 19:00:10 -07:00
bors
c4125286ce Auto merge of #12840 - tesuji:const-asserts, r=llogiq
Don't lint `assertions_on_constants` on any const assertions

close #12816
close #12847
cc #12817

----

changelog: Fix false positives in consts for `assertions_on_constants` and `unnecessary_operation`.
2024-07-01 22:06:06 +00:00
Roman Franchuk
b08b8b8a75 Implement a lint to replace bit manual rotations with rotate_left/rotate_right 2024-06-29 22:31:10 +02:00
bors
1aa236d59b Auto merge of #13006 - flip1995:manual-inspect-error-message, r=Jarcho
Add error message to manual_inspect lint

r? `@Jarcho`

changelog: none
2024-06-28 18:47:12 +00:00
Deadbeef
2fcef6e9f7 address review comments 2024-06-28 15:44:20 +00:00
Deadbeef
74bc964e60 finishing touches, move fixed ICEs to ui tests 2024-06-28 10:57:35 +00:00
Philipp Krones
01a6dfa29f
Add error message to manual_inspect lint 2024-06-28 10:29:18 +02:00
Michael Howell
6de87829da doc_lazy_continuation: blank comment line for gap
This change addresses cases where doc comments are separated
by blank lines, comments, or non-doc-comment attributes,
like this:

```rust
/// - first line
// not part of doc comment
/// second line
```

Before this commit, Clippy gave a pedantically-correct
warning about how you needed to indent the second line.
This is unlikely to be what the user intends, and has
been described as a "false positive" (since Clippy is
warning you about a highly unintuitive behavior that
Rustdoc actually has, we definitely want it to output
*something*, but the suggestion to indent was poor).

https://github.com/rust-lang/rust-clippy/issues/12917
2024-06-27 17:09:54 -07:00
Philipp Krones
abdd057163 Merge commit '68a799aea9b65e2444fbecfe32217ce7d5a3604f' into clippy-subtree-update 2024-06-27 18:56:04 +02:00
Philipp Krones
e9e7a815a7
Merge remote-tracking branch 'upstream/master' into rustup 2024-06-27 18:49:59 +02:00
xFrednet
3bbec6aade sudo CI=green && Review changes <3 2024-06-25 18:06:22 +02:00
xFrednet
1b4c281fe7 RFC 2383: Stabilize lint_reasons in Clippy 🖇️ 2024-06-25 17:50:48 +02:00
Vadim Petrochenkov
8c718e5524 ast: Standardize visiting order for attributes and node IDs 2024-06-24 16:08:51 +03:00
bors
32374a196d Auto merge of #12930 - DaniPopes:missing-const-for-fn-suggestion, r=Jarcho
[`missing_const_for_fn`]: add machine-applicable suggestion

Add a machine-applicable suggestion to the `missing_const_for_fn` lint.

changelog: [`missing_const_for_fn`]: add machine-applicable suggestion
2024-06-23 20:04:27 +00:00
Andre Bogus
51ccad6986
use short message format in integration test 2024-06-23 17:20:07 +02:00
John Arundel
625091d236 Fix doc nits 2024-06-23 13:11:54 +01:00
Guillaume Gomez
58fc27f571 Rollup merge of #126723 - estebank:dot-dot-dot, r=Nadrieril
Fix `...` in multline code-skips in suggestions

When we have long code skips, we write `...` in the line number gutter.

For suggestions, we were "centering" the `...` with the line, but that was inconsistent with what we do in every other case *and* off-center.
2024-06-22 12:57:19 +02:00
bors
0ce07f61db Auto merge of #12961 - GuillaumeGomez:fix-manual_unwrap_or_default, r=Alexendoo
Fix incorrect suggestion for `manual_unwrap_or_default`

Fixes #12928.

If this not a "simple" pattern, better not emit the lint.

changelog: Fix incorrect suggestion for `manual_unwrap_or_default`
2024-06-21 17:05:43 +00:00
Guillaume Gomez
54b45f7f93 Fix incorrect suggestion for manual_unwrap_or_default 2024-06-21 18:18:28 +02:00
vohoanglong0107
2f9f204123 feat: unnecessary_min_max lint 2024-06-20 13:57:16 +00:00
Esteban Küber
3baafd2e8c Fix ... in multline code-skips in suggestions
When we have long code skips, we write `...` in the line number gutter.

For suggestions, we were "centering" the `...` with the line, but that was consistent with what we do in every other case.
2024-06-20 04:25:17 +00:00
y21
ed9ccf66e9 [unnecessary_to_owned]: catch to_owned from byte slice to string 2024-06-20 00:09:31 +02:00
Renato Lochetti
b147b6d03d
Don't lint implicit_return on proc macros 2024-06-19 19:16:09 +01:00
Trevor Gross
c693f31ee2 Update float tests to include f16 and f128 2024-06-19 13:30:21 -04:00
bors
9e54ff2952 Auto merge of #12906 - lochetti:manual_unwrap_or_if_let, r=y21
Lint `manual_unwrap_or` for it let cases

This PR modifies `manual_unwrap_or` to lint for `if let` cases as well. This effort is part of the fixes desired by https://github.com/rust-lang/rust-clippy/issues/12618

changelog:[`manual_unwrap_or`]: Lint for `if let` cases.
2024-06-17 21:21:56 +00:00
bors
51c5eee9e6 Auto merge of #12945 - Jarcho:octal_escape, r=Alexendoo
Rework `octal_escapes`

Main changes are not doing UTF-8 decoding, noting each occurrence as an individual lint emission, and narrowing the span to point to the escape itself.

changelog: none
2024-06-17 20:12:43 +00:00
bors
0625183e28 Auto merge of #12903 - Jarcho:issue_12284, r=y21
Fix ICE in `upper_case_acronyms`

fixes #12284

The logic has been rewritten to avoid allocations. The old version allocated multiple vecs and strings for each identifier. The new logic allocates a single string only when the lint triggers.

This also no longer lints on strings which don't start with an uppercase letter (e.g. `something_FOO`).

changelog: none
2024-06-17 15:45:38 +00:00
Jason Newcomb
4b16e265a7 Rework octal_escapes. 2024-06-16 22:36:24 -04:00
Jason Newcomb
22710f33a8 Add lint manual_inspect 2024-06-16 18:33:43 -04:00
kyle oneill
3405ce3bca Add field_scoped_visibility_modifiers lint 2024-06-16 15:54:48 -04:00
AurelienFT
51c6630d4f Change MSRV check for manual_pattern_char_comparison only for pattern arrays 2024-06-15 21:52:42 +02:00
AurelienFT
63388cbab8 add MSRV for manual_pattern_char_comparison 2024-06-15 21:45:35 +02:00
bors
0dc265ff82 Auto merge of #12756 - y21:assigning_clones_lifetimes, r=Alexendoo
Avoid emitting `assigning_clones` when cloned data borrows from the place to clone into

Fixes #12444
Fixes #12460
Fixes #12749
Fixes #12757
Fixes #12929

I think the documentation for the function should describe what- and how this is fixing the issues well.
It avoids emitting a warning when the data being cloned borrows from the place to clone into, which is information that we can get from `PossibleBorrowerMap`. Unfortunately, it is a tiny bit tedious to match on the MIR like that and I'm not sure if this is possibly relying a bit too much on the exact MIR lowering for assignments.

Things left to do:
- [x] Handle place projections (or verify that they work as expected)
- [x] Handle non-`Drop` types

changelog: [`assigning_clones`]: avoid warning when the suggestion would lead to a borrow-check error
2024-06-15 18:25:42 +00:00
DaniPopes
82f0dc95a0
[missing_const_for_fn]: add machine-applicable suggestion 2024-06-14 14:43:08 +02:00
Esteban Küber
fa9274c99b Tweak output of import suggestions
When both `std::` and `core::` items are available, only suggest the
`std::` ones. We ensure that in `no_std` crates we suggest `core::`
items.

Ensure that the list of items suggested to be imported are always in the
order of local crate items, `std`/`core` items and finally foreign crate
items.

Tweak wording of import suggestion: if there are multiple items but they
are all of the same kind, we use the kind name and not the generic "items".

Fix #83564.
2024-06-13 20:22:21 +00:00
bors
ba347f9815 Auto merge of #126398 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? `@Manishearth`

Updates `Cargo.lock` with Clippy version bump.
2024-06-13 16:17:56 +00:00
Philipp Krones
3bff119f63 Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
Waffle Lapkin
c3d463333f Fixup clippy tests
Don't depend on the fact that `!` falls back to `()` and so panic-ish things
can be used in `-> impl ImplementedForUnit` functions
2024-06-13 12:24:31 +02:00
Philipp Krones
cc63143bbf
Merge remote-tracking branch 'upstream/master' into rustup 2024-06-13 12:24:08 +02:00
bors
aaade2d12d Auto merge of #12855 - tesuji:fix-author-lint, r=Jarcho
Fix typos of author lint

changelog: none
2024-06-11 22:49:18 +00:00
bors
38d12a9bc0 Auto merge of #12681 - y21:issue12677, r=Jarcho
Let `qualify_min_const_fn` deal with drop terminators

Fixes #12677

The `method_accepts_droppable` check that was there seemed overly conservative.
> Returns true if any of the method parameters is a type that implements `Drop`.
> The method can't be made const then, because `drop` can't be const-evaluated.

Accepting parameters that implement `Drop` should still be fine as long as the parameter isn't actually dropped, as is the case in the linked issue where the droppable is moved into the return place. This more accurate analysis ("is there a `drop` terminator") is already done by `qualify_min_const_fn` [here](f5e250180c/clippy_utils/src/qualify_min_const_fn.rs (L298)), so I don't think this additional check is really necessary?

Fixing the other, second case in the linked issue was only slightly more involved, since `Vec::new()` is a function call that has the ability to panic, so there must be a `drop()` terminator for cleanup, however we should be able to freely ignore that. [Const checking ignores cleanup blocks](https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/transform/check_consts/check.rs#L382-L388), so we should, too?

r? `@Jarcho`

----

changelog: [`missing_const_for_fn`]: continue linting on fns with parameters implementing `Drop` if they're not actually dropped
2024-06-11 22:38:52 +00:00
AurelienFT
c86b19f1ef Add lint to check manual pattern char comparison and merge its code with single_char_pattern lint 2024-06-11 21:56:14 +02:00
bors
9ddea51a73 Auto merge of #12912 - lochetti:fix_12824, r=dswij
Don't lint indexing_slicing lints on proc macros

This pr fixes https://github.com/rust-lang/rust-clippy/issues/12824

Even though the issue mentions the indexing case only, it was easy to apply the fix to the slicing case as well.

changelog: [`out_of_bounds_indexing`, `indexing_slicing`]: Don't lint on procedural macros.
2024-06-11 15:27:36 +00:00
bors
87c895ad83 Auto merge of #12915 - belyakov-am:lint/single_char_add_str, r=xFrednet
Handle single chars with `to_string()` for `single_char_add_str`

Add support for single chars / literals with `to_string()` call for `push_str()` and `insert_str()`.

changelog: [`single_char_add_str`]: handle single chars with `to_string()` call

Closes #12775
2024-06-11 11:08:45 +00:00
Renato Lochetti
f7515ae905
Don't lint indexing_slicing lints on proc macros 2024-06-10 09:08:56 +01:00
Artem Belyakov
55344c84a5 Handle single chars with to_string() for single_char_add_str 2024-06-09 21:01:00 +03:00
clubby789
5acc25e700 Update icu4x dependencies 2024-06-09 07:47:42 +01:00
Renato Lochetti
70ca9a1e7e
Lint manual_unwrap_or for it let cases 2024-06-08 14:39:03 +01:00
Lzu Tao
2855a876a7 fix typos of author lint 2024-06-08 12:31:49 +00:00
Lzu Tao
a0234b4e8b Ignore non ExprKind::{Path,Lit) inside const context
- remove now dead code in ASSERTIONS_ON_CONSTANTS
  cc #11966
- Partially revert "ignore `assertions-on-constants` in const contexts"
  This reverts commit c7074de420a2192fb40d3f2194a20dd0d1b65cc6.
2024-06-08 18:44:40 +07:00
Lzu Tao
ac600282a0 ignore assertions-on-constants in const contexts 2024-06-08 16:50:25 +07:00
Lzu Tao
e18b27aa2a add uitest for issue 12816 2024-06-08 16:50:25 +07:00
Lzu Tao
2c61b45576 do not lint on indexing inside const contexts 2024-06-08 16:50:25 +07:00
Lzu Tao
aff0e6d6d3 add uitest for indexing in unnecessary const items 2024-06-08 16:50:25 +07:00
bors
48686adf48 Auto merge of #12805 - Alexendoo:blocks-in-conditions-closures, r=dswij
Don't lint blocks in closures for blocks_in_conditions

Seemed like an outlier for the lint which generally caught only the syntactically confusing cases, it lints blocks in closures but excludes closures passed to iterator methods, this changes it to ignore closures in general

changelog: none
2024-06-08 09:45:22 +00:00
Jason Newcomb
059eaf1386 Fix ICE in upper_case_acronyms and remove most of the string allocations. 2024-06-08 00:00:32 -04:00
León Orell Valerian Liehr
fe6f332193 Rollup merge of #125951 - slanterns:error_in_core_stabilization, r=Amanieu
Stabilize `error_in_core`

Closes: https://github.com/rust-lang/rust/issues/103765.

`@rustbot` label: +T-libs-api

r? libs-api
2024-06-08 04:25:44 +02:00
bors
0ea88b90d8 Auto merge of #12900 - Alexendoo:no-lazy-static, r=llogiq
Remove `lazy_static` mention

I planned to replace any mention with `LazyLock` but I think `thread_local` is more appropriate here - `const`s that aren't `Sync` wouldn't be able to go in a `lazy_static`/`static LazyLock` either

Also removed a test file that was mostly commented out so wasn't testing anything

changelog: none
2024-06-07 22:54:02 +00:00
bors
d553ebef57 Auto merge of #12851 - samueltardieu:issue12846, r=y21
Add required parentheses around method receiver

Fix #12846

changelog: [`needless_bool`]: Add missing parentheses around method receiver
2024-06-07 21:27:46 +00:00
y21
973f318514 qualify_min_const_fn: ignore cleanup bbs 2024-06-07 20:56:22 +02:00
y21
6fdf295664 let qualify_min_const_fn deal with drop checks 2024-06-07 20:56:22 +02:00
J-ZhengLi
1781333ec7 [match_same_arms]: add a test case with lifetimes 2024-06-08 00:06:20 +08:00
Alex Macleod
65af5d7b22 Remove lazy_static mention 2024-06-07 12:51:37 +00:00
Alex Macleod
b21ee38fa9 Don't lint blocks in closures for blocks_in_conditions 2024-06-07 11:21:38 +00:00
bors
f990ea155e Auto merge of #12844 - Alexendoo:to-string-in-format-args, r=dswij
Fix `to_string_in_format_args` with macro call receiver

Fixes part of #12837

changelog: none
2024-06-07 09:52:17 +00:00
bors
0f87a81882 Auto merge of #12822 - Alexendoo:for-each-expr, r=dswij
Make `for_each_expr` visit closures by default, rename the old version `for_each_expr_without_closures`

A lot of the time `for_each_expr` is picked when closures should be visited so I think it makes sense for this to be the default with the alternative available for when you don't need to visit them.

The first commit renames `for_each_expr` to `for_each_expr_without_closures` and `for_each_expr_with_closures` to `for_each_expr`

The second commit switches a few uses that I caught over to include closures to fix a few bugs

changelog: none
2024-06-07 09:42:37 +00:00
bors
0b441d5ac5 Auto merge of #12877 - y21:const_host_ice, r=dswij
Handle const effects inherited from parent correctly in `type_certainty`

This fixes a (debug) ICE in `type_certainty` that happened in the [k256 crate]. (I'm sure you can also specifically construct an edge test case that will run into type_certainty false positives visible outside of debug builds from this bug)

<details>
<summary>Minimal ICE repro</summary>

```rs
use std::ops::Add;
Add::add(1_i32, 1).add(i32::MIN);
```
</details>

The subtraction here overflowed:
436675b477/clippy_utils/src/ty/type_certainty/mod.rs (L209)

... when we have something like `Add::add` where `add` fn has 0 generic params but the `host_effect_index` is `Some(2)` (inherited from the parent generics, the const trait `Add`), and we end up executing `0 - 1`.

(Even if the own generics weren't empty and we didn't overflow, this would still be wrong because it would assume that a trait method with 1 generic parameter didn't have any generics).

So, *only* exclude the "host" generic parameter if it's actually bound by the own generics

changelog: none

[k256 crate]: https://github.com/RustCrypto/elliptic-curves/tree/master/k256
2024-06-07 09:33:48 +00:00
bors
127f3e18c1 Auto merge of #125918 - oli-obk:const_block_ice, r=compiler-errors
Revert: create const block bodies in typeck via query feeding

as per the discussion in https://github.com/rust-lang/rust/pull/125806#discussion_r1622563948

It was a mistake to try to shoehorn const blocks and some specific anon consts into the same box and feed them during typeck. It turned out not simplifying anything (my hope was that we could feed `type_of` to start avoiding the huge HIR matcher, but that didn't work out), but instead making a few things more fragile.

reverts the const-block-specific parts of https://github.com/rust-lang/rust/pull/124650

`@bors` rollup=never had a small perf impact previously

fixes https://github.com/rust-lang/rust/issues/125846

r? `@compiler-errors`
2024-06-07 09:08:59 +00:00
Oli Scherer
abd011638d Revert "Create const block DefIds in typeck instead of ast lowering"
This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42.
2024-06-07 08:33:58 +00:00
Slanterns
246d4fe791 bless std_instead_of_core 2024-06-07 08:37:05 +08:00
Renato Lochetti
478d44487e
Allow manual_unwrap_or_default at useless_conversion_try tests 2024-06-06 21:44:06 +01:00
Rémy Rakic
5ea5f6351e Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwco"
This reverts commit 57dad1d75e562ff73051c1c43b07eaf65c7dbd74, reversing
changes made to 36316df9fe6c3e246153fe6e78967643cf08c148.
2024-06-06 20:39:54 +00:00
Renato Lochetti
5b63ab1131
Lint manual_unwrap_or_default for Result as well 2024-06-06 21:33:37 +01:00
Samuel Tardieu
35b2aa99f3 Add required parentheses around method receiver 2024-06-06 20:53:08 +02:00
Maja Kądziołka
c6cc160ec6
needless_borrows_for_generic_args: Fix for &mut
This commit fixes a bug introduced in #12706, where the behavior of the
lint has been changed, to avoid suggestions that introduce a move. The
motivation in the commit message is quite poor (if the detection for
significant drops is not sufficient because it's not transitive, the
proper fix would be to make it transitive). However, #12454, the linked
issue, provides a good reason for the change — if the value being
borrowed is bound to a variable, then moving it will only introduce
friction into future refactorings.

Thus #12706 changes the logic so that the lint triggers if the value
being borrowed is Copy, or is the result of a function call, simplifying
the logic to the point where analysing "is this the only use of this
value" isn't necessary.

However, said PR also introduces an undocumented carveout, where
referents that themselves are mutable references are treated as Copy,
to catch some cases that we do want to lint against. However, that is
not sound — it's possible to consume a mutable reference by moving it.

To avoid emitting false suggestions, this PR reintroduces the
referent_used_exactly_once logic and runs that check for referents that
are themselves mutable references.

Thinking about the code shape of &mut x, where x: &mut T, raises the
point that while removing the &mut outright won't work, the extra
indirection is still undesirable, and perhaps instead we should suggest
reborrowing: &mut *x. That, however, is left as possible future work.

Fixes #12856
2024-06-06 17:04:12 +02:00
bors
4e7f97467a Auto merge of #12827 - Alexendoo:lint-groups-priority, r=Jarcho
`lint_groups_priority`: ignore lints & groups at the same level

Fixes #12270

changelog: none
2024-06-06 12:09:58 +00:00
bors
6cfd4ac955 Auto merge of #10632 - Alexendoo:needless-maybe-sized, r=Jarcho
Add `needless_maybe_sized` lint

changelog: new lint: [`needless_maybe_sized`]

Closes #10600
2024-06-05 20:11:03 +00:00
bors
d955d0a41f Auto merge of #12891 - paultag:paultag/fix-lint-description, r=Manishearth
Fix grammer for the Safety documentation check

The original message ("unsafe function's docs miss `# Safety` section") reads quite awkwardly. I've changed it to "unsafe function's docs are missing a `# Safety` section" to have it read better.

```
changelog: [`missing_headers`]: Tweak the grammar in the lint message
```
2024-06-05 20:00:59 +00:00
bors
1105e9debe Auto merge of #12700 - Luv-Ray:overly_complex_bool_expr, r=Jarcho
[`overly_complex_bool_expr`]: Fix trigger wrongly on never type

fixes #12689

---

changelog: fix [`overly_complex_bool_expr`] triggers wrongly on never type
2024-06-05 19:47:43 +00:00
bors
bc00d7b94d Auto merge of #12845 - cookie-s:dedup-boolmethods-diags, r=Jarcho
Dedup nonminimal_bool_methods diags

Relates to #12379

Fix `nonminimal_bool` lint so that it doesn't check the same span multiple times.

`NotSimplificationVisitor` was called for each expression from `NonminimalBoolVisitor` whereas `NotSimplificationVisitor` also recursively checked all expressions.

---

changelog: [`nonminimal_bool`]: Fix duplicate diagnostics
2024-06-05 19:09:55 +00:00
Paul R. Tagliamonte
35e2027a35 Fix grammer for the Safety documentation check
The original message ("unsafe function's docs miss `# Safety` section")
reads quite awkwardly. I've changed it to "unsafe function's docs are missing
a `# Safety` section" to have it read better.

Signed-off-by: Paul R. Tagliamonte <paultag@gmail.com>
2024-06-05 14:11:56 -04:00
bors
10d1f32685 Auto merge of #12886 - GuillaumeGomez:fix-needless_character_iteration, r=blyxyas
Fix false positive for `needless_character_iteration` lint

Fixes #12879.

changelog: Fix false positive for `needless_character_iteration` lint
2024-06-05 13:12:39 +00:00
Guillaume Gomez
158b65889c Fix false positive for needless_character_iteration lint 2024-06-04 21:12:08 +02:00
y21
708ef7955d only run flop lints on inherent method calls 2024-06-03 21:42:00 +02:00
bors
4f3180adac Auto merge of #12875 - y21:deprecate_cfg_lints, r=flip1995
Deprecate `maybe_misused_cfg` and `mismatched_target_os`

All cases that these two lints would catch are now caught by cargo/rustc's own check-cfg feature.

This was previously discussed on zulip: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Deprecate.20maybe_misused_cfg.20and.20mismatched_target_os

For the most part, this PR was automated with `cargo dev deprecate`

r? `@flip1995` cc `@Urgau`

changelog: deprecate [`maybe_misused_cfg`] and [`mismatched_target_os`]
2024-06-03 08:57:34 +00:00
bors
61d3e14718 Auto merge of #12815 - GuillaumeGomez:add-needless_character_iteration, r=xFrednet
Add `needless_character_iteration` lint

Fixes #4817.

r? `@xFrednet`

changelog: Add `needless_character_iteration` lint
2024-06-03 08:09:18 +00:00
bors
568f4fc732 Auto merge of #12871 - Jacherr:issue-12768, r=blyxyas
Modify str_to_string to be machine-applicable

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

I'm not sure if there is any potential for edge cases with this - since it only ever acts on `&str` types I can't think of any, and especially since the methods do the same thing anyway.

changelog: allow `str_to_string` lint to be automatically applied
2024-06-02 21:11:06 +00:00
y21
25d40c9f6b handle parent const effects correctly in type_certainty 2024-06-01 20:10:48 +02:00
y21
f950961c42 deprecate mismatched_target_os 2024-06-01 14:11:07 +02:00
y21
4aa20d2e95 deprecate maybe_misused_cfg 2024-06-01 13:44:13 +02:00
bors
436675b477 Auto merge of #12868 - VitalikButerinEth:master, r=llogiq
chore: fix some comments

 fix some comments

----

changelog: none
2024-06-01 11:16:14 +00:00
Jacher
5d0fcfbf56 modify str_to_string to be machine-applicable 2024-06-01 09:05:27 +00:00
bors
28e887fe71 Auto merge of #12488 - Jacherr:issue-11525, r=llogiq
Disable `indexing_slicing` for custom Index impls

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

Disables `indexing_slicing` for custom Index impls, specifically any implementations that also do not have a `get` method anywhere along the deref chain (so, for example, it still lints on Vec, which has its `get` method as part of the deref chain).

Thanks `@y21` for pointing me in the right direction with a couple of handy util functions for deref chain and inherent methods, saved a headache there!

changelog: FP: Disable `indexing_slicing` for custom Index impls
2024-05-31 16:42:50 +00:00
bors
0b598b636b Auto merge of #12865 - J-ZhengLi:issue12853, r=y21
fix [`redundant_closure`] suggesting incorrect code with `F: Fn()`

fixes: #12853

---

changelog: fix [`redundant_closure`] suggesting incorrect code with `F: Fn()`
2024-05-31 15:23:39 +00:00
bors
e7efe4381a Auto merge of #12857 - WeiTheShinobi:non_canonical_impls, r=y21
fix: let non_canonical_impls skip proc marco

Fixed #12788

Although the issue only mentions `NON_CANONICAL_CLONE_IMPL`, this fix will also affect `NON_CANONICAL_PARTIAL_ORD_IMPL` because I saw
> Because of these unforeseeable or unstable behaviors, macro expansion should often not be regarded as a part of the stable API.

on Clippy Documentation and these two lints are similar, so I think it might be good, not sure if it's right or not.

---

changelog: `NON_CANONICAL_CLONE_IMPL`, `NON_CANONICAL_PARTIAL_ORD_IMPL` will skip proc marco now
2024-05-30 15:58:48 +00:00
WeiTheShinobi
1038927b47 fix: add test case, use a better conditional expression. 2024-05-30 23:40:17 +08:00
VitalikButerinEth
b92501f124 chore: fix some comments
Signed-off-by: VitalikButerinEth <csyingyu@126.com>
2024-05-30 22:53:43 +08:00
Jacher
1c117f12ea ignore generics in handling 2024-05-30 13:15:25 +00:00
Jacherr
ae59f5002d add additional testcases 2024-05-30 11:45:57 +00:00
Jacherr
e186ed2ad1 check return type of get and indexing 2024-05-30 11:45:57 +00:00
Jacherr
93b39d8910 disable indexing_slicing for custom Index impls 2024-05-30 11:45:43 +00:00
bors
03654badfd Auto merge of #12864 - tesuji:non-no-effect, r=y21
ignore array from `deref_addrof` lint

Split from https://github.com/rust-lang/rust-clippy/pull/12854

changelog: ignore array from `deref_addrof` lint

r? y21
2024-05-30 10:16:50 +00:00
Philipp Krones
f67f72695a Merge commit 'c9139bd546d9cd69df817faeab62c5f9b1a51337' into clippy-subtree-update 2024-05-30 10:49:05 +02:00
Philipp Krones
89037ea18f
Merge remote-tracking branch 'upstream/master' into rustup 2024-05-30 09:44:14 +02:00
Lzu Tao
8bd2a17dfe ignore array from deref_addrof lint
Note that semantics of repeat expr in array are the same
2024-05-30 08:34:44 +07:00
Vadim Petrochenkov
d38920f677 ast: Revert a breaking attribute visiting order change 2024-05-29 21:55:24 +03:00
J-ZhengLi
db30f6ce9f fix [redundant_closure] suggesting incorrect code with F: Fn() 2024-05-29 16:21:59 +08:00
Lzu Tao
4dcab72c1c add test for *&[a, b,...]` 2024-05-29 02:20:49 +00:00
Oli Scherer
e3e27ba3dd Create const block DefIds in typeck instead of ast lowering 2024-05-28 13:38:43 +00:00
bors
da4b2127c0 Auto merge of #12859 - cookie-s:dedup-single-char-name-diag, r=Alexendoo
[`many_single_char_names`]: Deduplicate diagnostics

Relates to #12379

Fix `many_single_char_names` lint so that it doesn't emit diagnostics when the current level of the scope doesn't contain any single character name.

```rust
let (a, b, c, d): (i32, i32, i32, i32);
match 1 {
  1 => (),
  e => {},
}
```
produced the exact same MANY_SINGLE_CHAR_NAMES diagnostic at each of the Arm `e => {}` and the Block `{}`.

---

changelog: [`many_single_char_names`]: Fix duplicate diagnostics
2024-05-28 12:41:14 +00:00
bors
76eee82e79 Auto merge of #12823 - schvv31n:fix-iter-on-empty-collections, r=y21
Suppress `iter_on_empty_collections` if the iterator's concrete type is relied upon

changelog: fixed #12807
2024-05-27 16:18:41 +00:00
bors
7e4c1ae0b6 Auto merge of #12843 - mdm:fix-unnecessary-to-owned-println-interaction, r=y21
Fix `unnecessary_to_owned` interaction with macro expansion

fixes #12821

In the case of an unnecessary `.iter().cloned()`, the lint `unnecessary_to_owned` might suggest to remove the `&` from references without checking if such references are inside a macro expansion. This can lead to unexpected behavior or even broken code if the lint suggestion is applied blindly. See issue #12821 for an example.

This PR checks if such references are inside macro expansions and skips this part of the lint suggestion in these cases.

changelog: [`unnecessary_to_owned`]: Don't suggest to remove `&` inside macro expansion
2024-05-27 14:26:50 +00:00
Guillaume Gomez
566dfd9008 Add needless_character_iteration lint 2024-05-27 14:16:02 +02:00
Marc Dominik Migge
4a64180dd5 unnecessary_to_owned should not suggest to remove & in macro expansion 2024-05-27 12:05:18 +02:00
bors
4dd07f4e4e Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote
[perf] Delay the construction of early lint diag structs

Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666.

See individual commits for details. The first three commits are not strictly necessary.
However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement.
It's also pretty sweet on its own if I may say so myself.
2024-05-27 08:44:12 +00:00
bors
722de3b546 Auto merge of #12842 - J-ZhengLi:issue12801, r=y21
add parentheses to [`let_and_return`]'s suggestion

closes: #12801

---

changelog: suggest adding parentheses when linting [`let_and_return`] and [`needless_return`]
2024-05-27 08:04:36 +00:00
J-ZhengLi
03306b6ab6 suggest adding parentheses when linting [let_and_return] and [needless_return] 2024-05-27 11:49:10 +08:00
cookie-s
7110f471d3
[many_single_char_names]: Deduplicate diagnostics 2024-05-26 22:56:23 -04:00
WeiTheShinobi
c53cea90ad fix: let non_canonical_impls skip proc marco 2024-05-26 18:59:40 +08:00
bors
5aae5f6ae6 Auto merge of #12740 - lrh2000:sig-drop, r=blyxyas
`significant_drop_in_scrutinee`: Trigger lint only if lifetime allows early significant drop

I want to argue that the following code snippet should not trigger `significant_drop_in_scrutinee` (https://github.com/rust-lang/rust-clippy/issues/8987). The iterator holds a reference to the locked data, so it is expected that the mutex guard must be alive until the entire loop is finished.
```rust
use std::sync::Mutex;

fn main() {
    let mutex_vec = Mutex::new(vec![1, 2, 3]);
    for number in mutex_vec.lock().unwrap().iter() {
        dbg!(number);
    }
}
```

However, the lint should be triggered when we clone the vector. In this case, the iterator does not hold any reference to the locked data.
```diff
-     for number in mutex_vec.lock().unwrap().iter() {
+     for number in mutex_vec.lock().unwrap().clone().iter() {
```

Unfortunately, it seems that regions on the types of local variables are mostly erased (`ReErased`) in the late lint pass. So it is hard to tell if the final expression has a lifetime relevant to the value with a significant drop.

In this PR, I try to make a best-effort guess based on the function signatures. To avoid false positives, no lint is issued if the result is uncertain. I'm not sure if this is acceptable or not, so any comments are welcome.

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

changelog: [`significant_drop_in_scrutinee`]: Trigger lint only if lifetime allows early significant drop.

r? `@flip1995`
2024-05-25 13:11:21 +00:00
bors
5d10538fb4 Auto merge of #12809 - GuillaumeGomez:missing-backticks-fix, r=y21
Correctly handle closing parens in `missing_backticks` doc lint

Fixes #12795.

changelog: Correctly handle closing parens in `doc_markdown` lint
2024-05-25 12:03:07 +00:00
cookie-s
93a77f2812
[nonminimal_bool]: Deduplicate diagnostics 2024-05-24 20:27:12 -04:00
Hamir Mahal
17cc0a3a7d
feat: auto-fix for bare URLs in doc comments 2024-05-24 14:30:42 -07:00
Alex Macleod
95b295d976 Fix to_string_in_format_args with macro call receiver 2024-05-24 19:27:39 +00:00
Jakob Schwarz
7f30b20b28
fulfill expectations in check_partial_eq_without_eq
changelog: fulfill expectations in [derive_partial_eq_without_eq]
2024-05-24 08:44:41 +02:00
León Orell Valerian Liehr
0c653d9f91 Remove LintDiagnostic::msg
* instead simply set the primary message inside the lint decorator functions
* it used to be this way before [#]101986 which introduced `msg` to prevent
  good path delayed bugs (which no longer exist) from firing under certain
  circumstances when lints were suppressed / silenced
* this is no longer necessary for various reasons I presume
* it shaves off complexity and makes further changes easier to implement
2024-05-23 04:08:35 +02:00
Ruihan Li
6641f9f6e1 Track lifetime on values with significant drop 2024-05-23 00:37:02 +08:00
bors
05c4053628 Auto merge of #12398 - WeiTheShinobi:bug-lint-numbered_fields, r=Manishearth
bug fix: lint numbered_fields message error

fixes #12367

changelog: [`numbered_fields`]: fix macro expand message error.
2024-05-22 15:50:46 +00:00
WeiTheShinobi
038f6179d7 bug fix: lint numbered_fields message error 2024-05-22 15:26:32 +08:00
schvv31n
7439ecb07c Added check for type unification with the iter 2024-05-21 22:21:33 +01:00
bors
ea535c97d5 Auto merge of #12804 - B14CK313:master, r=y21
fulfill expectations in `check_unsafe_derive_deserialize`

The utility function `clippy_utils::fulfill_or_allowed` is not used because using it would require to move the check for allowed after the check iterating over all inherent impls of the type, doing possibly unnecessary work.
Instead, `is_lint_allowed` is called as before, but additionally, once certain that the lint should be emitted, `span_lint_hir_and_then` is called instead of `span_lint_and_help` to also fulfill expectations.

Note: as this is my first contribution, please feel free to nitpick or request changes. I am happy to adjust the implementation.

fixes: #12802

changelog: fulfill expectations in [`unsafe_derive_deserialize`]
2024-05-21 19:05:36 +00:00
Philipp Krones
4363278c73 Merge commit '2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2' into clippy-subtree-update 2024-05-21 10:39:30 -07:00