Commit graph

8844 commits

Author SHA1 Message Date
y21
1a1c978f8e [if_let_mutex]: make the mutex check part of the expr visitor 2024-07-28 18:27:53 +02:00
bors
236c8c782b Auto merge of #13159 - Alexendoo:missing-trait-methods-stable-order, r=dswij
`missing_trait_methods`: lint methods in definition order

Lintcheck for #13157 showed a bunch of changes for `missing_trait_methods`

This is because `values_sorted` was sorting the entries by the key's [`DefPathHash`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/def_id/struct.DefPathHash.html), this is stable for a given compiler but can change across versions

changelog: none
2024-07-27 15:32:18 +00:00
bors
d20be39c7f Auto merge of #13149 - jusexton:issue-13123, r=dswij
Fix while_let_on_iterator dropping loop label when applying fix.

Loop label was not persisted when displaying help and was therefore producing broken rust code when applying fixes.

Solution was to store the `ast::Label` when creating a `higher::WhileLet` from an expression and add the label name to the lint suggestion and diagnostics.

---

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

changelog: [`while_let_on_iterator`]: Fix issue dropping loop label when displaying help and applying fixes.
2024-07-27 15:23:21 +00:00
bors
92768eeac4 Auto merge of #13053 - nyurik:rename-set_contains_or_insert, r=llogiq
Add `BTreeSet` detection to the `set_contains_or_insert` lint

* Detect `BTreeSet::contains` + `BTreeSet::insert` usage in the same way as with the `HashSet`.
CC: `@lochetti` `@bitfield`

----

changelog: [`set_contains_or_insert`]: Handle `BTreeSet` in addition to `HashSet`
2024-07-27 11:48:24 +00:00
bors
1ec502569e Auto merge of #13168 - Alexendoo:std-instead-of-core-msrv, r=Manishearth
Make `std_instead_of_core` somewhat MSRV aware

For #13158, this catches some things e.g. `core::net` and the recently stable `core::error` but not things moved individually like `UnwindSafe`, as far as I can see the version for those isn't easily available

Beta nominating since ideally we'd get this change in the same version as `core::error` becomes stable

cc `@kpreid`

changelog: none
2024-07-27 02:55:15 +00:00
Yuri Astrakhan
9964b4e053 Add BTreeSet to set_contains_or_insert
* Detect `BTreeSet::contains` + `BTreeSet::insert` usage in the same way as with the `HashSet`.
2024-07-26 22:52:07 -04:00
bors
6713631b0f Auto merge of #13165 - riyueguang:master, r=Jarcho
chore: fix some comments

fix some comments

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

changelog: none
2024-07-26 17:37:20 +00:00
Alex Macleod
84e36e6ce5 Make std_instead_of_core somewhat MSRV aware 2024-07-26 16:08:03 +00:00
Alex Macleod
10fb062c48 missing_trait_methods: lint methods in definition order 2024-07-26 11:25:06 +00:00
riyueguang
8ca8ed9b07 chore: fix some comments
Signed-off-by: riyueguang <rustruby@outlook.com>
2024-07-26 17:51:22 +08:00
Philipp Krones
82b44345a5
Bump ui_test version -> 0.25 2024-07-26 11:40:27 +02:00
bors
345c94c98f Auto merge of #13144 - xFrednet:07797-restriction-and-then-what, r=y21
Make restriction lint's use `span_lint_and_then` (i -> p)

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

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

changelog: none
2024-07-26 07:44:21 +00:00
xFrednet
90c19635fd
Make restriction lint's use span_lint_and_then (n -> p) 2024-07-26 09:41:38 +02:00
Jakub Beránek
e9852cc7c9
Only apply dereference-removing special case for actual references 2024-07-25 22:20:59 +02:00
bors
062b66d45c Auto merge of #12892 - meithecatte:needless-borrows-mutrefs, r=xFrednet
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

changelog: none
2024-07-25 18:48:27 +00:00
Philipp Krones
9f53fc32cf
Merge remote-tracking branch 'upstream/master' into rustup 2024-07-25 18:23:27 +02:00
bors
5e6540f049 Auto merge of #13146 - Alexendoo:cast-lossless-128, r=y21
Lint casts to `u128` in `cast_lossless`

Reverts #12496 per https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Should.20.60as.20u128.60.20trigger.20cast_lossless

Also changes the lint messages and refactors the suggestion production - Fixes #12695

changelog: [`cast_lossless`]: lint casts to `u128`
2024-07-24 21:00:05 +00:00
Maja Kądziołka
e63061d75b
Apply review suggestion
Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>
2024-07-24 22:29:35 +02:00
Alex Macleod
6d28e1a954 Lint casts to u128 in cast_lossless 2024-07-24 14:32:41 +00:00
bors
615284aa5a Auto merge of #13151 - Alexendoo:nextest, r=Jarcho
Fix running compile-test under cargo nextest

`ui_test` itself has `cargo nextest` support which we now use - https://github.com/oli-obk/ui_test/pull/161

It prints `ui_test` as its test name whereas we printed `compile_test`, this ended up being treated as a test name filter causing all the tests to be filtered out

changelog: none
2024-07-23 22:30:02 +00:00
bors
e91d82eabb Auto merge of #13143 - Alexendoo:transmute-ptr-to-ptr-suggestions, r=y21
Suggest `.cast`/`.cast_const`/`.cast_mut` in `transmute_ptr_as_ptr`

Essentially pre-applies `ptr_as_ptr` - https://github.com/rust-lang/rust-clippy/issues/6372#issuecomment-1830438907

changelog: none
2024-07-23 21:48:07 +00:00
Alex Macleod
af6d49d97c Fix running compile-test under cargo nextest 2024-07-23 16:15:54 +00:00
Alex Macleod
7010d3c67e Don't suggest .cast_mut/.cast_const for types with erased lifetimes 2024-07-23 11:12:26 +00:00
jusexton
0cdf6e172c Fix while_let_on_iterator dropping loop label when applying fix. 2024-07-23 02:55:58 -05:00
bors
f9c240720a Auto merge of #13072 - Jarcho:misc_small5, r=xFrednet
Misc refactorings part 5

`toplevel_ref_arg` gets a small fix so it can be allowed on function arguments. Otherwise just some rearrangements.

changelog: none
2024-07-22 19:58:25 +00:00
xFrednet
bc8fc6b1d8
Make restriction lint's use span_lint_and_then (i -> l) 2024-07-22 19:47:29 +02:00
Alex Macleod
afe811ad30 Suggest .cast/.cast_const/.cast_mut in transmute_ptr_as_ptr 2024-07-22 17:31:45 +00:00
Michael Goulet
897c4d3adb Move all error reporting into rustc_trait_selection 2024-07-21 22:34:35 -04:00
bors
1807580a49 Auto merge of #12772 - phi-gamma:redundant-struct-recreation, r=y21
add lint for recreation of an entire struct

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. The lint is not machine-applicable because the source
struct may have been partially moved.

This lint originated in something I spotted during peer review. While
working on their branch a colleague ended up with a commit where a
function returned a struct that 1:1 replicated one of its owned inputs
from its members. Initially I suspected they hadn’t run their code
through Clippy but AFAICS there is no lint for this situation yet.

changelog: new lint: [`redundant_owned_struct_recreation`]

### New lint checklist

- \[+] Followed [lint naming conventions][lint_naming]
- \[+] Added passing UI tests (including committed `.stderr` file)
- \[+] `cargo test` passes locally
- \[+] Executed `cargo dev update_lints`
- \[+] Added lint documentation
- \[+] Run `cargo dev fmt`
2024-07-21 23:02:38 +00:00
bors
8fe5c757d5 Auto merge of #11700 - lengyijun:pathbuf_join, r=xFrednet
[`pathbuf_init_then_push`]:  Checks for calls to `push` immediately a…

changelog: [`pathbuf_init_then_push`]: new lint: Checks for calls to `push` immediately after creating a new `PathBuf`

Just a mirror of VEC_INIT_THEN_PUSH
2024-07-21 06:39:01 +00:00
lengyijun
cb77f12600 [pathbuf_init_then_push]: Checks for calls to push immediately after creating a new PathBuf
Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>
2024-07-21 14:22:48 +08:00
Bruce Mitchener
cf4270d13b Reduce typo count. 2024-07-20 12:50:36 +07:00
bors
bc2feea519 Auto merge of #13117 - GuillaumeGomez:fix-single_element_loop-suggestion, r=Alexendoo
Fix wrong suggestion for `single_element_loop` where parens were missing

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

changelog: Fix missing parens in `single_element_loop` suggestion
2024-07-18 12:53:59 +00:00
Guillaume Gomez
8dd310ddd7 Fix wrong suggestion for single_element_loop where parens were missing 2024-07-18 14:50:45 +02:00
bors
073f9d9080 Auto merge of #13116 - tesuji:fix_zero_repeat_side_effects, r=y21
Lint `zero_repeat_side_effects`  only if array length is a literal zero

changelog: [`zero_repeat_side_effects` ] Lint only if array length is a literal zero
Fixes #13110 .
r? y21
2024-07-18 11:56:13 +00:00
Lzu Tao
3c50e7af5a Lint only if array length is a literal zero. 2024-07-18 12:22:08 +07:00
bors
acc41f4239 Auto merge of #13100 - Alexendoo:dogfood-progress, r=xFrednet
Show progress while running dogfood test

Outputs the regular cargo progress in colour when running the dogfood test, helpful to see because it can take a long time to run

changelog: none
2024-07-17 18:41:48 +00:00
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
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