Commit Graph

18312 Commits

Author SHA1 Message Date
bors
4a0c36d648 Auto merge of #11790 - Alexendoo:destructure-conf, r=Manishearth
Destructure `Conf` in `register_lints`

And some other miscellaneous clean-up in the area

changelog: none
2023-11-11 07:52:41 +00:00
Alex Macleod
f1979d48d7 Destructure Conf in register_lints 2023-11-10 23:47:52 +00:00
bors
9a4dd106d9 Auto merge of #11750 - Alexendoo:let-chains, r=flip1995
Replace if_chain with let chains

Closes #9353

Let chains are now supported by rustfmt 🎉

The PR is split into two commits
1. The result of running [`if-to-let-chain clippy*/**/*.rs`](https://github.com/Alexendoo/if-to-let-chain)
2. The manual clean up: fixing some errors/formatting, dogfood lints, removing the if_chain internal lint

r? `@flip1995`

changelog: none
2023-11-10 18:09:19 +00:00
Alex Macleod
13b4bb12ad Clean up after if chain removal 2023-11-10 18:03:13 +00:00
Alex Macleod
9681b4afe0 Run if-to-let-chain clippy*/**/*.rs
https://github.com/Alexendoo/if-to-let-chain
2023-11-10 17:29:28 +00:00
bors
6be0f7414d Auto merge of #11780 - Jacherr:vec-allocator-nolint, r=xFrednet
Disable `vec_box` when using different allocators

Fixes #7114

This PR disables the `vec_box` lint when the `Box` and `Vec` use different allocators (but not when they use the same - custom - allocator).

For example - `Vec<Box<i32, DummyAllocator>>` will disable the lint, and `Vec<Box<i32, DummyAllocator>, DummyAllocator>` will not disable the lint.

In addition, the applicability of this lint has been changed to `Unspecified` due to the automatic fixes potentially breaking code such as the following:

```rs
fn foo() -> Vec<Box<i32>> { // -> Vec<i32>
  vec![Box::new(1)]
}
```

It should be noted that the `if_chain->let-chains` fix has also been applied to this lint, so the diff does contain many changes.

changelog: disable `vec_box` lint when using nonstandard allocators
2023-11-09 23:33:46 +00:00
Jacherr
eabc64f56c add additonal non-trigger testcase 2023-11-09 23:03:44 +00:00
bors
34b7d1559f Auto merge of #11779 - partiallytyped:11775, r=blyxyas
[`mod_module_files`] Don't emit lint for mod.rs in tests

fixes: #11775

current state: indiscriminately emits the lint for mod files in tests.

The following

```
tests/
  common/
    mod.rs
  test.rs
```

is a common pattern for code shared across the tests and is suggested in the rust book. The change adds an additional check to verify that the mod file is not in tests.

changelog: Fix [`mod_module_files`]: false positive for mod files in tests folder
2023-11-08 22:27:13 +00:00
Jacherr
7cdaa3b574 replace incorrect bool 2023-11-08 21:47:58 +00:00
PartiallyTyped
7e716ff955 [mod_module_files] Don't emit lint for modules in tests
fixes: #11775

current state: indiscriminately emits the lint for mod files in tests.

The following

tests/
  common/
    mod.rs
  test.rs

is a common pattern for code shared across the tests and is suggested in
the rust book. The change adds an additional check to verify that the
mod file is not in tests.

changelog: Fix [`mod_module_files`]: false positive for mod files in
tests folder
2023-11-08 22:42:12 +01:00
Jacherr
483b109e6e cargo dev fmt 2023-11-08 21:17:40 +00:00
Jacherr
b6d56c47f9 add no-rustfix since suggestions are invalid 2023-11-08 21:15:11 +00:00
Jacherr
67bb503f26 add support for std::alloc::Global, add more tests 2023-11-08 21:10:27 +00:00
bors
e16d42f540 Auto merge of #11772 - partiallytyped:11714, r=blyxyas
[arc_with_non_send_sync] Improve suggested resolution

Fixes: #11714

Improved the lint message for [`arc_with_non_send_sync`] to suggest using `RC` unless user needs an Arc, then suggests wrapping in a mutex, and then suggests implementing `Sync` and `Send`.

---

changelog: [`arc_with_non_send_sync`]: Suggest RC over unsafe impl of Send and Sync
2023-11-08 20:30:02 +00:00
Jacherr
79325604da update testcases, cleanup 2023-11-08 18:42:58 +00:00
PartiallyTyped
399fe32893 [arc_with_non_send_sync] Improve suggested resolution
Fixes: #11714
changelog: [`arc_with_non_send_sync`]: Suggest RC over unsafe impl

Co-authored-by: Alejandra González <blyxyas@gmail.com>
2023-11-08 19:38:59 +01:00
Jacherr
3a91a11740 add logic to check allocator matching 2023-11-08 18:27:33 +00:00
Jacherr
73b9841a3e remove unnecessary find_map calls 2023-11-08 17:41:28 +00:00
bors
ba43632808 Auto merge of #11736 - gernot-ohner:issue-10267, r=flip1995
Make SpanlessEq more consistent

1) Remove wildcard as requested in https://github.com/rust-lang/rust-clippy/issues/10267.
2) Implement `hir_utils::eq_expr` for `ExprKind::Closure`, `ExprKind::ConstBlock`, `ExprKind::InlineAsm` and `ExprKind::Yield`.
3) Reorder branches of `hir_utils::eq_expr` to be in alphabetical order.

---
changelog: none
2023-11-08 09:58:56 +00:00
Gernot Ohner
171845d5a8 Reorder ExprKinds in hash_expr alphabetically 2023-11-06 11:51:07 -07:00
bors
6d9516ac1e Auto merge of #11758 - y21:clippy_config_references, r=flip1995
update references of old `msrvs` and `conf` paths

In #11685, `clippy_lints::utils::conf` and `clippy_utils::msrvs` were moved to a separate `clippy_config` crate.
I noticed that not all references to those paths were updated, so this small PR intends to fix those.

changelog: none
2023-11-06 10:03:11 +00:00
y21
b9efa3ee2c update references of clippy_utils::msrvs and clippy_lints::util::conf 2023-11-04 01:15:32 +01:00
bors
789bc73d8a Auto merge of #11756 - y21:issue11755, r=Manishearth
[`unused_enumerate_index`]: don't ICE on empty tuples

Fixes #11755

changelog: [`unused_enumerate_index`]: don't ICE on empty tuples

I'm going to nominate for beta backport because the code that is needed to trigger this seems likely to occur in real code
`@rustbot` label +beta-nominated
2023-11-03 23:39:14 +00:00
y21
294df80e2c [unused_enumerate_index]: don't ICE on empty tuples 2023-11-03 21:13:51 +01:00
bors
902c79c654 Auto merge of #11743 - Alexendoo:dbg-macro-stmt-span, r=xFrednet
Fix `dbg_macro` semi span calculation

`span_including_semi` was using a `BytePos` to index into a file's source which happened to work because the root file of the test started at `BytePos` 0, it didn't work for other files

changelog: none
2023-11-02 20:11:32 +00:00
bors
09ac14c901 Auto merge of #11747 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2023-11-02 16:32:10 +00:00
Philipp Krones
62a82b361c
Format let-chains across the code base
In the updated nightly version, it seems that rustfmt now supports formatting
let-chains. Since we're using them a lot, it's a lot of reformatting.
2023-11-02 17:24:30 +01:00
Philipp Krones
5eee19e1dc
Bump nightly version -> 2023-11-02 2023-11-02 17:24:26 +01:00
Philipp Krones
95dc7be92f
Merge remote-tracking branch 'upstream/master' into rustup 2023-11-02 17:24:19 +01:00
bors
01a0a36666 Auto merge of #11744 - matthri:get-first-deque-fix, r=Jarcho
Fix get_first false negative for VecDeque

fixes #11695

Also run the lint on `VecDeque` and suggest using `.front()` instead of `.get(0)` when trying to access the first element.

PS: At first I implemented the VecDeque Lint in a separate `if_chain` (see the previous commit).
Let me know if thats the preferred way, then I will remove the refactoring into one block.

changelog: [`get_first`]: fix false negative: Also lint `VecDeque` and suggest using `front()`
2023-11-02 09:23:39 +00:00
Matthias Richter
61c76dd4ff remove code duplication 2023-11-01 23:35:28 +01:00
Matthias Richter
3b759bce9d fix get_first false negative for VecDeque 2023-11-01 23:26:43 +01:00
Alex Macleod
57a464439e Fix dbg_macro semi span calculation 2023-11-01 16:25:15 +00:00
bors
919f698da0 Auto merge of #10404 - dnbln:feat/unused_enumerate_index, r=blyxyas
Add `unused_enumerate_index` lint

A lint for unused `.enumerate()` indexes (`for (_, x) in iter.enumerate()`).

I wasn't able to find a `rustc_span::sym::Enumerate`, so the code for checking that it's the correct `Enumerate` iterator is a bit weird.

---

changelog: New lint: [`unused_enumerate_index`]: A new lint for checking that the indexes from `.enumerate()` calls are used.
[#10404](https://github.com/rust-lang/rust-clippy/pull/10404)
<!-- changelog_checked -->
2023-11-01 15:52:56 +00:00
Dinu Blanovschi
bb9cc6d47c refactor: extract common pat_is_wild to clippy_utils
This function was previously defined for the iter_kv_map,
for_kw_map, and unused_enumerate_index lints. This commit extracts
it into clippy_utils.
2023-11-01 14:19:23 +01:00
Dinu Blanovschi
14b82909b0 Apply suggestions from code review
Co-authored-by: Alejandra González <blyxyas@gmail.com>
2023-10-31 18:21:34 +01:00
Dinu Blanovschi
0b90f72064 feat: unused_enumerate_index lint 2023-10-31 17:53:24 +01:00
bors
7d34406015 Auto merge of #11669 - y21:issue11577, r=Jarcho
new lint: `unnecessary_fallible_conversions`

Closes #11577

A new lint that looks for calls such as `i64::try_from(1i32)` and suggests `i64::from(1i32)`. See lint description (and linked issue) for more details for why.

There's a tiny bit of overlap with the `useless_conversion` lint, in that the other one warns `T::try_from(T)` (i.e., fallibly converting to the same type), so this lint ignores cases like `i32::try_from(1i32)` to avoid emitting two warnings for the same expression.

Also, funnily enough, with this one exception, this lint would warn on exactly every case in the `useless_conversion_try` ui test that `useless_conversion` didn't cover (but never two warnings at the same time), which is neat. I did add an `#![allow]` though since we don't want interleaved warnings from multiple lints in the same uitest.

changelog: new lint: `unnecessary_fallible_conversions`
2023-10-31 05:13:48 +00:00
bors
3da80dc752 Auto merge of #11498 - jonboh:issue11494_enumvariants_order_affects_lint, r=Centri3
fix enum_variant_names depending lint depending on order

changelog: [`enum_variant_names`]: fix single word variants preventing lint of later variant pre/postfixed with the enum name

fixes #11494

Single word variants prevented checking the `check_enum_start` and `check_enum_end` for being run on later variants
2023-10-31 01:33:25 +00:00
Gernot Ohner
6d840652dc Add branches in eq_expr 2023-10-30 18:04:36 -06:00
Gernot Ohner
67d379ba42 Reorder ExprKinds in eq_expr to alphabetical 2023-10-30 15:54:53 -06:00
Gernot Ohner
ed982afc8f Expliticly specify else branches in hir_utils::hash_expr 2023-10-30 15:16:23 -06:00
y21
69c3b9c252 new lint: unnecessary_fallible_conversions 2023-10-30 20:54:24 +01:00
bors
cdc4d56ae7 Auto merge of #11701 - Alexendoo:vec-init-then-push-docs, r=Jarcho
Use multiple pushes in `vec_init_then_push` example

Makes the perf argument clearer, since a single push doesn't have unnecessary allocations compared to `vec![x]`

changelog: none
2023-10-30 17:25:55 +00:00
bors
325e9fd339 Auto merge of #11723 - Alexendoo:clippy-utils-internal, r=Jarcho
Remove internal feature from clippy_utils

It's only used to gate a few `const`s, removing the feature gate means it doesn't have to be recompiled when moving between a normal and `-F internal` build/test/etc

changelog: none
2023-10-30 17:11:53 +00:00
bors
e245f7c29f Auto merge of #11735 - rust-lang:fix-11568, r=blyxyas
ignore lower-camel-case words in `doc_markdown`

This fixes #11568 by ignoring camelCase words starting with a lower case letter.

r? `@blyxyas`

---

changelog: none
2023-10-30 12:06:58 +00:00
David Tolnay
2e907aa90c Rename Since -> StableSince in preparation for a DeprecatedSince 2023-10-29 21:39:57 -07:00
bors
739f9e2503 Auto merge of #11727 - dswij:read-zero-byte-vec-nursery, r=Centri3
move `read_zero_byte_vec` to nursery

I think the concerns in #9274 are valid, and we should move this to nursery while we're reworking this.

changelog: [`read_zero_byte_vec`] moved to nursery
2023-10-29 22:09:07 +00:00
Andre Bogus
e6c804c457 ignore lower-camel-case words in doc_markdown 2023-10-29 23:04:17 +01:00
jonboh
c51e2a0f75 fix enum_variant_names depending lint depending on order 2023-10-29 17:34:11 +01:00