Commit graph

17403 commits

Author SHA1 Message Date
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
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
85f535b25f add test cases for u32, f32, bool, String 2023-07-03 22:57:33 +02:00
y21
8fad54e8f9 new lint: read_line_without_trim 2023-07-03 22:51:38 +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
ea4ca225fb Auto merge of #10920 - blyxyas:speedtest, r=llogiq
Add `SPEEDTEST`

In the `master` branch, we currently don't have any way to test the performance of a single lint in changes.
This PR adds `SPEEDTEST`, the environment variable which lets you do a speed test on a lint / category of tests with various configuration options.

Maybe we should merge this with `lintcheck` 🤔
See the book page for more information.

changelog:none
2023-07-02 15:48:50 +00: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
17a48c2652 Auto merge of #11053 - Alexendoo:ci-build-tests, r=flip1995
Use `cargo build --tests` in CI

I noticed that we run a `cargo build` but end up downloading/building a bunch of deps after that for tests in CI

https://github.com/rust-lang/rust-clippy/actions/runs/5426673277/jobs/9869019973#step:6:12
https://github.com/rust-lang/rust-clippy/actions/runs/5426673277/jobs/9869019973#step:7:11

This builds the tests in the build step too, it may speed up runs by downloading/building more in parallel

changelog: none
2023-07-02 12:24: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
Catherine
885a18207f Fix typos 2023-07-02 07:11:05 -05:00
bors
37f4c1725d Auto merge of #11012 - Centri3:manual_try_fold, r=blyxyas,xFrednet
New lint [`manual_try_fold`]

Closes #10208

---

changelog: New lint [`manual_try_fold`]
[#11012](https://github.com/rust-lang/rust-clippy/pull/11012)
2023-07-01 22:43:12 +00:00
Catherine
cb5d7e344a address comments 2023-07-01 12:37:16 -05:00
Catherine
fbb3f759e2 update docs 2023-07-01 12:36:02 -05:00
Catherine
04b0857691 Typo 2023-07-01 12:36:02 -05:00
Catherine
24039ca2c6 Add msrv tests 2023-07-01 12:36:02 -05:00
Catherine
354172a18e New lint manual_try_fold 2023-07-01 12:36:02 -05:00
bors
c7bf05c1a4 Auto merge of #11020 - Centri3:tuple_array_conversion, r=llogiq
New lint [`tuple_array_conversions`]

Closes #10748

PS, the implementation is a bit ugly 😅 ~~I will likely refactor soon enough :)~~ Done :D

changelog: New lint [`tuple_array_conversions`]
2023-07-01 15:27:35 +00:00
Alex Macleod
2f7f1393c9 Use cargo build --tests in CI 2023-06-30 21:34:28 +00:00
bors
464edbed05 Auto merge of #11051 - Centri3:eq_op, r=llogiq
Make `eq_op` suggest `.is_nan()`

changelog: Enhancement: [`eq_op`]: Suggests `is_nan()` for `x != x` where `x` is a float
2023-06-30 18:26:28 +00:00
est31
20dfaba035 Put into one pass 2023-06-30 19:47:22 +02:00
Catherine
efac83813d Make eq_op suggest .is_nan() 2023-06-30 11:43:02 -05:00
est31
c6be62159f Fix the now stricter lint in manual_rem_euclid.rs 2023-06-30 18:01:28 +02:00
est31
86391abc70 Don't lint manual_let_else in cases where the question mark operator would work
Also, lint question_mark for `let...else` clauses that can be simplified to use `?`.
This lint isn't perfect as it doesn't support the unstable try blocks.
2023-06-30 18:01:27 +02:00
bors
2c40b99d08 Auto merge of #11048 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2023-06-30 14:09:53 +00:00
Philipp Krones
30d08d35f2
Bump nightly version -> 2023-06-29 2023-06-30 16:09:15 +02:00
Philipp Krones
8010c3462d
Merge remote-tracking branch 'upstream/master' into rustup 2023-06-30 16:09:06 +02:00
bors
73f14176e3 Auto merge of #10774 - c410-f3r:lock-1, r=Jarcho
[significant_drop_tightening] Fix #10413

Fix #10413

This is quite a rewrite that unfortunately took a  large amount of time. I tried my best to comment what is going on to easy review but feel free to ask any question.

The problem basically is that the current algorithm is only taking into consideration single blocks which means that things like the following don't work or show unpredictable results.

```rust
let mutex = Mutex::new(1);
{
  let lock = mutex.lock().unwrap();
  {
    let _ = *lock;
  }
}
```

The solve the issue, each path that refers a lock is now being tracked individually.

```
changelog: [`significant_drop_tightening`]: Lift the restriction of only considerate single blocks
```
2023-06-30 02:51:15 +00:00
bors
3d4c536e87 Auto merge of #11013 - Centri3:redundant_rest_pattern, r=giraffate
New lint [`redundant_at_rest_pattern`]

Closes #11011

It's always a great feeling when a new lint triggers on clippy itself 😄

changelog: New lint [`redundant_at_rest_pattern`]
2023-06-29 23:54:35 +00:00
Caio
fc832f0eb7 Dogfood 2023-06-29 09:30:04 -03:00
Caio
f0619024b8 Fix #10413 2023-06-29 09:27:49 -03:00
Catherine
826edd75ef heavily refactor 2023-06-29 06:46:28 -05:00
Catherine
95b24d44a6 Fix FP 2023-06-29 06:46:28 -05:00
Catherine
b1acbde618 Add msrv check and make test pass 2023-06-29 06:46:28 -05:00
Catherine
bfcc8ba444 New lint tuple_array_conversions 2023-06-29 06:46:00 -05:00
bors
9020937bbe Auto merge of #11030 - darklyspaced:master, r=Centri3,xFrednet
suggests `is_some_and` over `map().unwrap`

changelog: Enhancement: [`option_map_unwrap_or`] now considers the [`msrv`] config when creating the suggestion.

 * modified option_map_unwrap_or lint to recognise when an `Option<T>` is mapped to an `Option<bool>` with false being used when `None` is detected; suggests the use of `is_some_and` instead
 * msrv is set to 1.70.0 for this lint; when `is_some_and` was stabilised

fixes #9125
2023-06-29 09:54:51 +00:00
darklyspaced
bb42b18081
ran cargo collect-metadata 2023-06-29 17:30:39 +08:00
darklyspaced
211278bc86
updated list of lints that use msrv 2023-06-29 10:18:38 +08:00