Commit graph

11844 commits

Author SHA1 Message Date
Jason Newcomb
1d06ad5599 Mark the lints for each config via an attribute instead of a doc comment.. 2024-07-28 00:55:46 -04:00
Slanterns
0812732cfc stabilize is_sorted 2024-07-28 03:11:54 +08: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
xFrednet
4bf4c475ee
Make restriction lint's use span_lint_and_then (t -> w) 2024-07-27 13:45:02 +02:00
xFrednet
7de9c20145
Make restriction lint's use span_lint_and_then (q -> s) 2024-07-27 13:45:00 +02: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
2acbd31686 Auto merge of #121676 - Bryanskiy:polarity, r=petrochenkov
Support ?Trait bounds in supertraits and dyn Trait under a feature gate

This patch allows `maybe` polarity bounds under a feature gate. The only language change here is that corresponding hard errors are replaced by feature gates. Example:
```rust
#![feature(allow_maybe_polarity)]
...
trait Trait1 : ?Trait { ... } // ok
fn foo(_: Box<(dyn Trait2 + ?Trait)>) {} // ok
fn bar<T: ?Sized + ?Trait>(_: &T) {} // ok
```
Maybe bounds still don't do anything (except for `Sized` trait), however this patch will allow us to [experiment with default auto traits](https://github.com/rust-lang/rust/pull/120706#issuecomment-1934006762).

This is a part of the [MCP: Low level components for async drop](https://github.com/rust-lang/compiler-team/issues/727)
2024-07-26 20:14:16 +00: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
bors
479491ebce Auto merge of #13130 - nyurik:ref-lints, r=Centri3
Avoid ref when using format!

Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing).

Inlining format args prevents accidental `&` misuse.

See also https://github.com/rust-lang/rust/issues/112156

changelog: none
2024-07-26 17:21:30 +00:00
Alex Macleod
84e36e6ce5 Make std_instead_of_core somewhat MSRV aware 2024-07-26 16:08:03 +00:00
Guillaume Gomez
b5fa6e28d4 Fix display of configs in clippy doc page 2024-07-26 14:23:46 +02: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
Guillaume Gomez
3c6e5ef4ae Add comment explaining what the matching items are for TOO_LONG_FIRST_DOC_PARAGRAPH lint 2024-07-26 11:21:32 +02:00
Guillaume Gomez
4969960a9c Fix dogfood lints 2024-07-26 11:21:32 +02:00
Guillaume Gomez
f455587fee Set the limit of characters to 200 and don't run the lint on private items unless config allows it 2024-07-26 11:21:32 +02:00
Guillaume Gomez
855a9d1377 Add new too_long_first_doc_paragraph first paragraph lint 2024-07-26 11:21:32 +02:00
Guillaume Gomez
760c3fab4f Fix case where doc_markdown is triggered on words ending with "ified" 2024-07-26 11:12:35 +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
bors
95ee06c749 Auto merge of #128193 - flip1995:clippy-subtree-update, r=matthiaskrgr
Clippy subtree update

r? `@Manishearth`

Updates Cargo.lock due to the Clippy version update and the ui_test bump to v0.24
2024-07-26 03:36:34 +00: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
Bryanskiy
dc49aa3884 Support ?Trait bounds in supertraits and dyn Trait under a feature gate 2024-07-25 20:53:33 +03:00
Lzu Tao
0bc9f003a3 Check for 'static lifetime in return type 2024-07-26 00:27:40 +07:00
Lzu Tao
e53182a2b4 Factor out check_closure function
Also get the receiver T in `T.method(|| f())`.
2024-07-26 00:27:38 +07:00
Philipp Krones
4e6851e50b Merge commit '37f4fbb92913586b73a35772efd00eccd1cbbe13' into clippy-subtree-update 2024-07-25 18:29:17 +02:00
Philipp Krones
71b0f0fcac
Bump Clippy version -> 0.1.82 2024-07-25 18:23:37 +02:00
Philipp Krones
9f53fc32cf
Merge remote-tracking branch 'upstream/master' into rustup 2024-07-25 18:23:27 +02:00
Matthias Krüger
36214e9838 Rollup merge of #121364 - Urgau:unary_precedence, r=compiler-errors
Implement lint against ambiguous negative literals

This PR implements a lint against ambiguous negative literals with a literal and method calls right after it.

## `ambiguous_negative_literals`

(deny-by-default)

The `ambiguous_negative_literals` lint checks for cases that are confusing between a negative literal and a negation that's not part of the literal.

### Example

```rust,compile_fail
-1i32.abs(); // equals -1, while `(-1i32).abs()` equals 1
```

### Explanation

Method calls take precedence over unary precedence. Setting the precedence explicitly makes the code clearer and avoid potential bugs.

<details>
<summary>Old proposed lint</summary>

## `ambiguous_unary_precedence`

(deny-by-default)

The `ambiguous_unary_precedence` lint checks for use the negative unary operator with a literal and method calls.

### Example

```rust
-1i32.abs(); // equals -1, while `(-1i32).abs()` equals 1
```

### Explanation

Unary operations take precedence on binary operations and method calls take precedence over unary precedence. Setting the precedence explicitly makes the code clearer and avoid potential bugs.

</details>

-----

Note: This is a strip down version of https://github.com/rust-lang/rust/pull/117161, without the binary op precedence.

Fixes https://github.com/rust-lang/rust/issues/117155
`@rustbot` labels +I-lang-nominated
cc `@scottmcm`
r? compiler
2024-07-25 16:48:17 +02:00
bors
df0cb6c51e Auto merge of #13125 - xFrednet:changelog-1-80, r=dswij
Changelog for Clippy 1.80 🌞

Roses are red,
Violets are blue,
Summer is fun,
So much sun

---

### The cat of this release is *Maunzer* submitted by `@llogiq:`

<img height=500 src="https://github.com/rust-lang/rust-clippy/assets/4200835/a1da6948-446d-4ccf-95a7-c816a8afdc3f" alt="The cats of this Clippy release" />

Cats for the next release can be nominated in the comments :D

---

changelog: none

I wish everyone reading this a beautiful and happy day =^.^=
2024-07-25 12:48:54 +00: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
Alex Macleod
6d28e1a954 Lint casts to u128 in cast_lossless 2024-07-24 14:32:41 +00:00
bors
16953cef82 Auto merge of #12830 - blyxyas:more-controlflow, r=y21,xFredNet
Use ControlFlow in more places

Now, instead of manually using variables in visitors to signify that a visit is "done" and that the visitor should stop traversing. We use the trait type "Result" to signify this (in relevant places).

I'll schedule a perf run, I don't think it will be much of a difference, but every bit of performance is welcomed :)

changelog: Improve performance, less memory use in visitors

Fixes #12829
r? `@y21`
2024-07-24 09:48:19 +00:00
bors
6d674685ae Auto merge of #127524 - oli-obk:feed_item_attrs2, r=petrochenkov
Make ast `MutVisitor` have the same method name and style as `Visitor`

It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer.

tracking issue: https://github.com/rust-lang/rust/issues/127615
2024-07-24 09:36:57 +00:00
bors
959477ea36 Auto merge of #13153 - Alexendoo:bind-instead-of-map-struct, r=Manishearth
Make `BindInsteadOfMap` a struct

Makes it codegen once instead of three times

changelog: none
2024-07-24 00:44:30 +00:00
blyxyas
b21a91ae3a Replace local variables signifying "done" or "loop break", use ControlFlow #12830 2024-07-24 01:40:58 +02: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
493498b65f Make BindInsteadOfMap a struct
Makes it codegen once instead of three times
2024-07-23 20:57:35 +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
df1baedfde Auto merge of #13050 - Jarcho:misc_small, r=xFrednet
Misc refactorings

Various small re-orderings to check the HIR tree or AST before doing other checks. Also includes a small bug fix for `arc_with_small_send_sync` not actually checking for `Arc::new`.

changelog: none
2024-07-22 20:25:05 +00:00
Michael Goulet
e2a7000b6b Get rid of infer_ctxt_ext 2024-07-22 16:15:52 -04: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
bors
637d39fab8 Auto merge of #13065 - Jarcho:misc_small2, r=xFrednet
Misc refactorings part 2

A couple of theses are a bit more involved. No behaviour changes included in this set.

changelog: none
2024-07-22 19:40:50 +00:00
xFrednet
d17f113474
Make restriction lint's use span_lint_and_then (m -> m) 2024-07-22 19:47:34 +02: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
Oli Scherer
221ac86e09 Always pass the visitor as the first argument to walk* functions 2024-07-22 14:01:24 +00:00
Oli Scherer
3149037b57 Sync mut_visit function names with immut visit ones (s/noop_visit/walk/) 2024-07-22 14:01:24 +00:00
Michael Goulet
efde1c065b Fix tools 2024-07-21 22:34:37 -04: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
5f3d385421 Auto merge of #120812 - compiler-errors:impl-sorting, r=lcnr
Remove unnecessary impl sorting in queries and metadata

Removes unnecessary impl sorting because queries already return their keys in HIR definition order: https://github.com/rust-lang/rust/issues/120371#issuecomment-1926422838

r? `@cjgillot` or `@lcnr` -- unless I totally misunderstood what was being asked for here? 😆

fixes #120371
2024-07-21 22:43:47 +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
Yuri Astrakhan
266abf3c08 Avoid ref when using format!
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing).

Inlining format args prevents accidental `&` misuse.
2024-07-19 16:10:24 -04:00
bors
8051d073d1 Auto merge of #125915 - camelid:const-arg-refactor, r=BoxyUwU
Represent type-level consts with new-and-improved `hir::ConstArg`

### Summary

This is a step toward `min_generic_const_exprs`. We now represent all const
generic arguments using an enum that differentiates between const *paths*
(temporarily just bare const params) and arbitrary anon consts that may perform
computations. This will enable us to cleanly implement the `min_generic_const_args`
plan of allowing the use of generics in paths used as const args, while
disallowing their use in arbitrary anon consts. Here is a summary of the salient
aspects of this change:

- Add `current_def_id_parent` to `LoweringContext`

  This is needed to track anon const parents properly once we implement
  `ConstArgKind::Path` (which requires moving anon const def-creation
  outside of `DefCollector`).

- Create `hir::ConstArgKind` enum with `Path` and `Anon` variants. Use it in the
  existing `hir::ConstArg` struct, replacing the previous `hir::AnonConst` field.

- Use `ConstArg` for all instances of const args. Specifically, use it instead
  of `AnonConst` for assoc item constraints, array lengths, and const param
  defaults.

- 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 https://github.com/rust-lang/rust/issues/127009.

### Followup items post-merge

- Use `ConstArgKind::Path` for all const paths, not just const params.
- Fix (no github dont close this issue) #127009
- If a path in generic args doesn't resolve as a type, try to resolve as a const
  instead (do this in rustc_resolve). Then remove the special-casing from
  `rustc_ast_lowering`, so that all params will automatically be lowered as
  `ConstArgKind::Path`.
- (?) Consider making `const_evaluatable_unchecked` a hard error, or at least
  trying it in crater

r? `@BoxyUwU`
2024-07-19 08:44:51 +00:00
Michael Goulet
8a0ccd30d1 Make clippy and rustdoc happy 2024-07-18 16:51:05 -04:00
apoisternex
58027e2657 Fix [redundant_slicing] when the slice is behind a mutable reference
Fixes #12751

changelog: Fix [`redundant_slicing`] when the slice is behind a mutable reference
2024-07-18 15:23:04 -03:00
xFrednet
e34db99b2e
Update version attribute for 1.80 lints 2024-07-18 20:13:39 +02: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
Ralf Jung
b0209dc028 valtree construction: keep track of which type was valtree-incompatible 2024-07-18 11:58:16 +02:00
Lzu Tao
3c50e7af5a Lint only if array length is a literal zero. 2024-07-18 12:22:08 +07: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
Lzu Tao
5540060d5d Skip linting if array length is from a macro. 2024-07-17 18:33:36 +07:00
Lzu Tao
a5fd2c98bd Remove duplicated peel_middle_ty_refs
TODO: Should we move `ty::peel_mid_ty_refs_is_mutable` to super module too?
2024-07-17 12:51:08 +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
Noah Lev
6e99e2d748 Use ConstArg for array lengths 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
Michael Goulet
185f4b06a7 Fix trivial gen ident usage in tools 2024-07-14 14:52:36 -04:00
bors
206e4adb52 Auto merge of #13046 - Jarcho:check_conv, r=dswij
Refactor `checked_conversions`

Removes redundant checks across functions and check the HIR tree before anything else.

changelog: none
2024-07-13 16:07:29 +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
bors
0cbbee1e6e Auto merge of #13090 - J-ZhengLi:issue9790, r=blyxyas
[`unwrap_or_default`]: skip warning when calling inside of suggested method's implementation

fixes: #10228

---

changelog: [`unwrap_or_default`]: skip warning when calling inside of suggested method's implementation
2024-07-12 14:37:10 +00: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
Florian Bartels
edeb0fcddc Fix syntax errors in example code 2024-07-12 11:12:01 +02: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
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
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
Sander Saares
e42a380afc Revert accidental "Why restrict this?" change 2024-07-10 08:10:35 +03:00
bors
8fa406b03f Auto merge of #13069 - Jarcho:misc_small4, r=Manishearth
Misc refactorings part 4

And even more rearrangements to check the HIR tree before other checks.

changelog: none
2024-07-09 15:47:24 +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
a04dbb0ab9 Tidy the example code and ensure it builds as standalone snippets 2024-07-09 10:28:11 +03: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
87f8a5b374 Auto merge of #13056 - y21:rm-compiler-lint-functions, r=Manishearth
Remove internal `compiler_lint_functions` lint

This internal lint has effectively been superseded by `disallowed_methods` when we started using that in #11811 (I didn't even know that we also had this internal lint at the time of when I created that PR).

Some of the methods that this looks for also don't exist anymore (`span_lint_note` and `span_lint_help`), though there was one that that lint had but wasn't disallowed in clippy.toml (`LintContext::lint`)

changelog: none
2024-07-08 23:10:11 +00:00
bors
e64236ca3a Auto merge of #13044 - Jarcho:bool_int, r=Manishearth
Refactor `bool_to_int_with_if`

Rearranges things to check the HIR tree first and simplifies how the literals are read.

changelog: None
2024-07-08 22:58:50 +00:00
bors
058e6eaa3a Auto merge of #13043 - Jarcho:assign_clone, r=Manishearth
Refactor `assigning_clones`

Short list of changes:
* Inline and simplify `extract_call`
* Inline `is_ok_to_suggest`
* Inline `skip_drop_block`
* Check the HIR tree before the macro check
* Don't call `outer_expn_data`
* Use `find` instead of a loop in `clone_source_borrows_from_dest`

changelog: none
2024-07-08 22:48:19 +00:00
bors
f6020fbd44 Auto merge of #13042 - Jarcho:almost_range, r=Manishearth
`almost_complete_range`: Delay suggestion creation.

Does less work when the lint doesn't trigger.

changelog: none
2024-07-08 22:39:01 +00:00
Michael Goulet
920cbcdd45 Move trait selection error reporting to its own top-level module 2024-07-08 16:04:47 -04:00
John Arundel
d23df74712 resolve code review comments 2024-07-08 19:05:35 +01:00
bors
510cfe3dc4 Auto merge of #13067 - Jarcho:misc_small3, r=Manishearth
Misc refactorings part 3

And some more changes. Same general idea of checking the HIR tree first when linting.

changelog: none
2024-07-08 17:52:47 +00: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
0c72a99cac raw_strings Check HIR tree first. 2024-07-07 22:19:06 -04:00
Jason Newcomb
e12ff630fd permissions_set_readonly_false: Check HIR tree first. 2024-07-07 22:17:43 -04:00
Jason Newcomb
15eac5abd6 Simplify option_env_unwrap. 2024-07-07 22:17:31 -04:00
Jason Newcomb
ff28de20b4 neg_cmp_op_on_partial_ord: Delay macro check 2024-07-07 22:14:43 -04:00
Jason Newcomb
7c17dd331b needless_for_each: Check HIR tree first. 2024-07-07 22:14:24 -04:00
Jason Newcomb
139dad8849 mut_mut: Delay macro check 2024-07-07 22:13:05 -04:00
Jason Newcomb
c22608823f needless_borrowed_ref: Check HIR tree first. 2024-07-07 22:13:05 -04:00
Jason Newcomb
58aa804ada mismatching_type_param_order: Delay macro check. 2024-07-07 22:06:15 -04: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
Jason Newcomb
eda45aaba1 minmax: use let chain 2024-07-07 18:12:39 -04:00
Jason Newcomb
488a545a50 map_unit_fn: Delay macro check 2024-07-07 18:12:05 -04:00
Jason Newcomb
7a942a5c99 manual_unwrap_or_default: Check HIR tree first. 2024-07-07 18:11:55 -04:00
Jason Newcomb
5d333e862b manual_strip: Delay msrv check. 2024-07-07 18:11:43 -04:00
Jason Newcomb
c0068ba5ac manual_slice_size_calculation: Delay constant check. 2024-07-07 18:11:05 -04:00
Jason Newcomb
03117026ae manual_retain: Remove redundant match. 2024-07-07 18:10:46 -04:00
Jason Newcomb
0f4cd13f66 manual_rem_euclid: Check HIR tree first. 2024-07-07 18:08:44 -04:00
Jason Newcomb
44f87e8cc1 manual_range_patterns: Delay macro check. 2024-07-07 18:08:11 -04:00
Jason Newcomb
2309f8e4a1 manual_non_exhaustive: Delay msrv check. 2024-07-07 18:08:02 -04:00
Jason Newcomb
f46c981f3f manual_main_separator_str: Check HIR tree first. 2024-07-07 18:07:52 -04:00
Jason Newcomb
2d9e67ea8a manual_let_else: Delay msrv and macro checks. 2024-07-07 18:07:36 -04:00
Jason Newcomb
95348adcb9 manual_float_methods:
* Check HIR tree first.
* Use `partition_in_place`.
2024-07-07 18:07:16 -04:00
Jason Newcomb
b9ba340db6 manual_bits: Delay msrv check 2024-07-07 18:06:36 -04:00
Jason Newcomb
c0fa6a92f0 literal_representation: Delay macro check. 2024-07-07 18:06:27 -04:00
Jason Newcomb
15f640a7cb let_with_type_underscore:
* Delay macro check.
* Use `is_from_proc_macro
2024-07-07 18:06:17 -04:00
Jason Newcomb
5332def0fd let_underscore: Delay macro check. 2024-07-07 18:06:00 -04:00
Jason Newcomb
fed75b3895 let_if_seq: use array_windows. 2024-07-07 18:05:51 -04:00
Jason Newcomb
ff4e62d3ec len_zero: Check HIR tree first 2024-07-07 18:05:41 -04:00
Jason Newcomb
5ae33c7699 legacy_numeric_constants: Check HIR tree first. 2024-07-07 16:52:59 -04:00
Jason Newcomb
03036c11b3 large_include_file: Check HIR tree first. 2024-07-07 16:52:33 -04:00
Jason Newcomb
c3dd028d3e large_futures: Delay macro check 2024-07-07 16:52:13 -04:00
Jason Newcomb
430c02cbd0 large_enum_variant: Delay macro check 2024-07-07 16:51:58 -04:00
Jason Newcomb
3092c8a5fd large_const_arrays: Check HIR tree first. 2024-07-07 16:51:33 -04:00
Jason Newcomb
6b10b4360c iter_without_into_iter: Delay macro check 2024-07-07 16:51:20 -04:00
Jason Newcomb
fa1a690b23 iter_not_returning_iterator:
* Check HIR tree first.
* Check name by symbol.
2024-07-07 16:43:07 -04:00
Jason Newcomb
ca5c2813eb items_after_statements: Do less work in the default case. 2024-07-07 16:41:36 -04:00
Jason Newcomb
aef0710054 instant_subtraction: Reduce redundant work. 2024-07-07 16:37:51 -04:00
Jason Newcomb
dc8403f0f5 inline_fn_without_body: inline into a single function 2024-07-07 16:37:31 -04:00
Jason Newcomb
8e2ddc800b inherent_to_string: Check HIR tree before checking for macros. 2024-07-07 16:35:05 -04:00
Jason Newcomb
f493d71a38 infinite_iter: Only lock the symbol table once. 2024-07-07 16:27:27 -04:00
Jason Newcomb
c73aceb043 indexing_slicing: Check HIR tree first. 2024-07-07 16:26:57 -04:00
Jason Newcomb
06f83b4e26 index_refutable_slice: Check HIR tree first. 2024-07-07 16:26:42 -04:00
Jason Newcomb
b58b491d16 inconsistent_struct_constructor: Check HIR tree first. 2024-07-07 16:26:04 -04:00
Jason Newcomb
3869e93408 ignored_unit_patterns: Reorder checks. 2024-07-07 16:24:45 -04:00
Jason Newcomb
517e1ac225 if_then_some_else_none: Check HIR tree before other checks. 2024-07-07 16:23:50 -04:00
Jason Newcomb
b26b820f3f Refactor if_not_else:
* Check HIR tree first.
* Merge lint calls.
2024-07-07 16:23:18 -04:00