Commit Graph

9799 Commits

Author SHA1 Message Date
bors
3be3fb7231 Auto merge of #11016 - y21:issue10029, r=blyxyas,dswij
[`filter_next`]: suggest making binding mutable if it needs to be

Fixes #10029

changelog: [`filter_next`]: suggest making binding mutable if it needs to be and adjust applicability
2023-07-10 10:47:37 +00:00
bors
9ab7137686 Auto merge of #11133 - GuillaumeGomez:fix-description-typo, r=Manishearth
Fix typo in `needless_pass_by_ref_mut` lint description

Someone nicely showed me that I made a small typo in https://github.com/rust-lang/rust-clippy/pull/10900.

changelog: none
2023-07-10 09:45:22 +00:00
y21
23ac72316d adjust applicability and suggest making binding mutable 2023-07-10 11:24:16 +02:00
Guillaume Gomez
d1575d1f54 changelog: Fix typo in needless_pass_by_ref_mut lint description 2023-07-10 10:27:23 +02:00
bors
9058b040c8 Auto merge of #11096 - y21:issue11091, r=giraffate
[`manual_range_patterns`]: lint negative values

Fixes #11091.

Now also lints negative values in patterns (`-1 | -2 | -3`)

changelog: [`manual_range_patterns`]: lint negative values
2023-07-10 00:04:08 +00:00
bors
507d1c282e Auto merge of #11110 - y21:unnecessary_literal_unwrap_ignore_expn, r=Jarcho
[`unnecessary_literal_unwrap`]: don't lint if binding initializer comes from expansion

Fixes https://github.com/rust-lang/rust-clippy/discussions/11109

changelog: [`unnecessary_literal_unwrap`]: don't lint if binding initializer comes from expansion
2023-07-09 20:09:22 +00:00
bors
ebd8d31542 Auto merge of #11055 - smoelius:try-this, r=dswij
"try this" -> "try"

Current help messages contain a mix of "try", "try this", and one "try this instead". In the spirit of #10631, this PR adopts the first, as it is the most concise.

It also updates the `lint_message_conventions` test to catch cases of "try this".

(Aside: #10120 unfairly contained multiple changes in one PR. I am trying to break that PR up into smaller pieces.)

changelog: Make help messages more concise ("try this" -> "try").
2023-07-09 15:07:25 +00:00
bors
b46033e9ce Auto merge of #10900 - GuillaumeGomez:needless-pass-by-ref, r=llogiq
Add `needless_pass_by_ref_mut` lint

changelog: [`needless_pass_by_ref_mut`]: This PR add a new lint `needless_pass_by_ref_mut` which emits a warning in case a `&mut` function argument isn't used mutably. It doesn't warn on trait and trait impls functions.

Fixes #8863.
2023-07-09 14:25:10 +00:00
Samuel Moelius
3bf2138289 Fix #10535 2023-07-08 19:12:10 -04:00
bors
6ae065ffd6 Auto merge of #11129 - c410-f3r:lock-1, r=Manishearth
[significant_drop_tightening] Fix #11128

Fix #11128

```
changelog: [`significant_drop_tightening`]: Consider manual alias of the `drop` function.
```
2023-07-08 21:10:43 +00:00
Caio
6384221910 Dogfood 2023-07-08 18:08:48 -03:00
Caio
2be695bf29 [significant_drop_tightening] Fix #11128 2023-07-08 17:43:34 -03:00
bors
8e261c09bb Auto merge of #11049 - Centri3:manual_is_infinite, r=blyxyas,xFrednet
New lints [`manual_is_infinite`] and [`manual_is_finite`]

Closes #9665

changelog: New lints [`manual_is_infinite`] and [`manual_is_finite`]
[#11049](https://github.com/rust-lang/rust-clippy/pull/11049)
2023-07-08 18:45:35 +00:00
Catherine
41438c2b90 Refactor, remove Constant::to_bits 2023-07-08 13:17:35 -05:00
Catherine
a5dfb68491 refactor 2023-07-08 13:11:56 -05:00
Centri3
844afbfeba use other instead of self 2023-07-08 13:02:54 -05:00
Centri3
004e89d4cf rename to manual_partial_ord_and_ord_impl
cargo dev fmt

cargo test passes

cargo test passes

refactor a lil

Update bool_comparison.stderr

heavily refactor + bump `clippy::version`

refactor

refactor

check bounds to increase accuracy, and add todos
2023-07-08 13:02:54 -05:00
Centri3
2a1fd22f81 implement manual_partial_ord_impl
first try at this
2023-07-08 13:02:38 -05:00
Nilstrieb
5df1f6681d Pass correct substs to implements_trait in incorrect_impls
`Copy<T>` does in fact not exist. The substs on the trait_ref contain
the `Self` type of the impl as the first parameter, so passing that
to `implements_trait`, which then nicely prepends the `Self` type
for us does not end will.
2023-07-07 20:28:51 +02:00
y21
c927912c5b [manual_range_patterns]: document what range we don't lint 2023-07-07 17:25:28 +02:00
y21
5cc0c04826 [manual_range_patterns]: lint negative values 2023-07-07 17:25:28 +02:00
Alex Macleod
4939a716e8 arc_with_non_send_sync: reword and move to suspicious 2023-07-07 12:02:05 +00:00
Catherine
5949f762bf Make suggestion give multiple alternatives 2023-07-06 20:27:21 -05:00
Catherine
f12edfdb53 manual_float_methods 2023-07-06 20:27:21 -05:00
bors
dd8e44c5a2 Auto merge of #11111 - Alexendoo:regex-def-paths, r=giraffate
Fix regex lints for regex 1.9.0

regex 1.9.0 was [just released](https://blog.burntsushi.net/regex-internals/), which changes where the types are defined. Instead of updating the definitions to the ones in 1.9.0 this PR uses [`def_path_def_ids`](https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/fn.def_path_def_ids.html) on the canonical paths so that we don't have to worry about third party crate internals

This means that it still works with older regex versions too, and will for any future layout changes. I tested it with 1.8.4 and 1.9.0

changelog: [`INVALID_REGEX`], [`TRIVIAL_REGEX`]: now works with regex 1.9.0
2023-07-06 23:40:33 +00:00
Alex Macleod
f945351170 Fix regex lints for regex 1.9.0 2023-07-05 18:29:43 +00:00
y21
6868c0a74b [unnecessary_literal_unwrap]: don't lint if binding initializer is expn 2023-07-05 13:03:34 +02:00
bors
1e656d8d6d Auto merge of #10970 - y21:read_line_without_trim, r=giraffate
new lint: `read_line_without_trim`

This adds a new lint that checks for calls to `Stdin::read_line` with a reference to a string that is then attempted to parse into an integer type without first trimming it, which is always going to fail at runtime.
This is something that I've seen happen a lot to beginners, because it's easy to run into when following the example of chapter 2 in the book where it shows how to program a guessing game.
It would be nice if we could point beginners to clippy and tell them "let's see what clippy has to say" and have clippy explain to them why it fails 👀

I think this lint can later be "generalized" to work not just for `Stdin` but also any `BufRead` (which seems to be where the guarantee about the trailing newline comes from) and also, matching/comparing it to a string slice that doesn't end in a newline character (e.g. `input == "foo"` is always going to fail)

changelog: new lint: [`read_line_without_trim`]
2023-07-05 00:13:59 +00:00
Guillaume Gomez
f048f73251 Add warning about semver compatibility if it's a public function 2023-07-04 20:35:23 +02:00
bors
3f4e5999b2 Auto merge of #11094 - y21:issue11084, r=Alexendoo
[`useless_vec`]: add more tests and don't lint inside of macros

Closes #11084.

I realized that the fix I added in #11081 itself also causes an error in a suggestion when inside of a macro. Example:
```rs
macro_rules! x {
  () => {
    for _ in vec![1, 2] {}
  }
}
x!();
```
Here it would suggest replacing `vec![1, 2]` with `[x!()]`, because that's what the source callsite is (reminder: it does this to get the correct span of `x!()` for code like `for _ in vec![x!()]`), but that's wrong when *inside* macros, so I decided to make it not lint if the whole loop construct is inside a macro to avoid this issue.

changelog: [`useless_vec`]: add more tests and don't lint inside of macros

r? `@Alexendoo` since these were your tests, I figured it makes most sense to assign you
2023-07-03 21:07:44 +00:00
y21
8fad54e8f9 new lint: read_line_without_trim 2023-07-03 22:51:38 +02:00
Guillaume Gomez
33adfcd327 Add warning for NEEDLESS_PASS_BY_REF_MUT lint about the fact that it changes API 2023-07-03 22:48:40 +02:00
Guillaume Gomez
dd3e00f102 Fix warnings of needless_pass_by_ref_mut in clippy 2023-07-03 22:25:36 +02:00
Guillaume Gomez
b41fc6784f Add needless_pass_by_ref lint 2023-07-03 22:25:36 +02:00
y21
b4549c50b5 [useless_vec]: add more tests for macro combinations 2023-07-03 19:48:27 +02:00
bors
ba3bd8f0f1 Auto merge of #11078 - Centri3:11068, r=llogiq
[`needless_raw_string_hashes`]: Only reset hashes needed if not following quote

Fixes #11068

changelog: none
2023-07-03 17:01:27 +00:00
bors
3f17c5c388 Auto merge of #10924 - est31:manual_let_else_question_mark, r=Centri3,flip1995,Manishearth
Don't lint manual_let_else in cases where ? would work

Don't lint `manual_let_else` where the question mark operator `?` would be sufficient, that is, mostly in cases like:

```Rust
let v = if let Some(v) = ex { v } else { return None };
```

Also, this PR emits the `question_mark` lint for `let...else` patterns that could be written with `?` (also, only `return None` like cases).

```
changelog: [`manual_let_else`]: don't lint in cases where question_mark already lints
changelog: [`question_mark`]: lint for `let Some(...) = ex else { return None };`
```

Fixes  #8755
2023-07-03 14:18:32 +00:00
bors
a959061763 Auto merge of #11081 - y21:issue11075, r=Manishearth
[`useless_vec`]: use the source span for initializer

Fixes #11075.

changelog: [`useless_vec`]: use the source span for the initializer expression when inside of a macro
2023-07-03 12:08:36 +00:00
y21
1f77f8cc3c [useless_vec]: use the source span 2023-07-03 13:40:33 +02:00
Catherine
9a581077d4 Fix FP [needless_raw_string_hashes] 2023-07-03 06:35:04 -05:00
bors
2b03bb08b2 Auto merge of #11077 - y21:issue11076, r=Manishearth
[`arc_with_non_send_sync`]: don't lint if type has nested type parameters

Fixes #11076

changelog: [`arc_with_non_send_sync`]: don't lint if type has nested type parameters

r? `@Manishearth`
2023-07-03 09:48:05 +00:00
y21
75c339cd0a [arc_with_non_send_sync]: look for nested type parameters 2023-07-03 11:35:25 +02:00
est31
d80581c7d2 Move pat_and_expr_can_be_question_mark into clippy_utils 2023-07-03 09:42:54 +02:00
est31
6990eaa972 Don't suppress manual_let_else if question_mark is allowed
If question_mark is allowed, there is no overlap any more,
so we can just not suppress it.
2023-07-03 09:42:54 +02:00
bors
c46ddeb9e1 Auto merge of #10987 - y21:type_id_on_box, r=llogiq
new lint: `type_id_on_box`

Closes #7687.

A new lint that detects calling `.type_id()` on `Box<dyn Any>` (and not on the underlying `dyn Any`), which can make up for some pretty confusing bugs!

changelog: new lint: [`type_id_on_box`]
2023-07-03 06:16:14 +00:00
bors
4752466c8e Auto merge of #11069 - y21:issue11063, r=Alexendoo
[`missing_fields_in_debug`]: make sure self type is an adt

Fixes #11063, another ICE that can only happen in core.

This lint needs the `DefId` of the implementor to get its fields, but that ICEs if the implementor does not have a `DefId` (as is the case with primitive types, e.g. `impl Debug for bool`), which is where this ICE comes from.

This PR changes the check I added in #10897 to be more... robust against `Debug` implementations we don't want to lint.
Instead of just checking if the self type is a type parameter and "special casing" one specific case we don't want to lint, we should probably rather just check that the self type is either a struct, an enum or a union and only then continue.
That prevents weird edge cases like this one that can only happen in core.

Again, I don't know if it's even possible to add a test case for this since one cannot implement `Debug` for primitive types outside of the crate that defined `Debug` (core).
I did make sure that this PR no longer ICEs on `impl<T> Debug for T` and `impl Debug for bool`.
Maybe writing such a test is possible with `#![no_core]` and then re-defining the `Debug` trait or something like that...?

changelog: [`missing_fields_in_debug`]: make sure self type is an adt (fixes an ICE in core)

r? `@Alexendoo` (reviewed the last PRs for this lint)
2023-07-02 21:12:10 +00:00
y21
555ceb83fe [missing_fields_in_debug]: make sure self is an adt 2023-07-02 21:42:39 +02:00
bors
83d0682d5e Auto merge of #11061 - Alexendoo:let-and-return-closures, r=llogiq
`let_and_return`: lint 'static lifetimes, don't lint borrows in closures

Fixes #11056

Now also ignores functions returning `'static` lifetimes, since I noticed the `stdin.lock()` example was still being linted but doesn't need to be since https://github.com/rust-lang/rust/pull/93965

changelog: none
2023-07-02 15:14:46 +00:00
Alex Macleod
e29a5acf6f let_and_return: lint 'static lifetimes, don't lint borrows in closures 2023-07-02 14:25:40 +00:00
bors
1990b72e8a Auto merge of #11058 - Centri3:typos, r=xFrednet
Fix typos

Just a couple misc typos I found

changelog: none
2023-07-02 12:11:30 +00:00