Commit graph

18326 commits

Author SHA1 Message Date
y21
d89890d154 move suspicious_doc_comments to doc pass 2023-11-13 13:44:00 +01:00
bors
07bc130074 Auto merge of #11760 - compiler-errors:escaping, r=Jarcho
Don't check for late-bound vars, check for escaping bound vars

Fixes an assertion that didn't make sense. Many valid and well-formed types *have* late-bound vars (e.g. `for<'a> fn(&'a ())`), they just must not have *escaping* late-bound vars in order to be normalized correctly.

Addresses rust-lang/rust-clippy#11230, cc `@jyn514` and `@matthiaskrgr`

changelog: don't check for late-bound vars, check for escaping bound vars. Addresses rust-lang/rust-clippy#11230
2023-11-12 22:15:43 +00:00
Michael Goulet
1539eb8c03 Don't check for late-bound vars, check for escaping bound vars 2023-11-12 12:15:30 -08:00
Michael Goulet
661e91be57 Add test 2023-11-12 12:14:41 -08:00
bors
6a15f3bd49 Auto merge of #11787 - Jarcho:divergence_check, r=dswij
Fixes to `manual_let_else`'s divergence check

A few changes to the divergence check in `manual_let_else` and moves it the implementation to `clippy_utils` since it's generally useful:
* Handle internal `break` and `continue` expressions.
    e.g. The first loop is divergent, but the second is not.
    ```rust
    {
        loop {
            break 'outer;
        };
    }
    {
        loop {
            break;
        };
    }
    ```
* Match rust's definition of divergence which is defined via the type system.
    e.g. The following is not considered divergent by rustc as the inner block has a result type of `()`:
    ```rust
    {
        'a: {
            panic!();
            break 'a;
        };
    }
    ```
* Handle when adding a single semicolon would make the expression divergent.
    e.g. The following would be a divergent if a semicolon were added after the `if` expression:
    ```rust
    { if panic!() { 0 } else { 1 } }
    ```

changelog: None
2023-11-12 15:44:13 +00:00
bors
886d5fbeb0 Auto merge of #11508 - Jarcho:issue_11474, r=blyxyas
Lint `needless_borrow` and `explicit_auto_deref` on most union field accesses

Changes both lints to follow rustc's rules around auto-deref through `ManuallyDrop` union fields rather than just bailing on union fields.

changelog: [`needless_borrow`] & [`explicit_auto_deref`]: Lint on most union field accesses
2023-11-12 11:24:01 +00:00
bors
8ee9a9c549 Auto merge of #11767 - matthri:unnecessary-fallible-conversions-ext-notes, r=blyxyas
Add type details to unnecessary_fallible_conversions note

fixes: #11753

changelog: [`unnecessary_fallible_conversions`]: add type details to lint note
2023-11-11 22:51:27 +00:00
Jason Newcomb
1a01132417 Lint explicit_auto_deref on most union field accesses. 2023-11-11 15:54:58 -05:00
Matthias Richter
4dead776e1 add type details to unnecessary_fallible_conversions note 2023-11-11 21:01:36 +01:00
Jason Newcomb
a68cd88860 Lint needless_borrow on most union field accesses 2023-11-11 14:50:19 -05:00
bors
d487579efd Auto merge of #11792 - y21:issue11764, r=llogiq
[`map_identity`]: respect match ergonomics

Fixes #11764

Note: the original tests before this were slightly wrong themselves already and had to be changed. They were calling `map` on an iterator of `&(i32, i32)`s, so this PR would stop linting there, but they were meant to test something else unrelated to binding modes, so I just changed them to remove the references so that it iterates over owned values and they all bind by value. This way they continue to test what they checked for before: the identity function for tuple patterns.

changelog: [`map_identity`]: respect match ergonomics
2023-11-11 14:58:00 +00:00
y21
b2cf8f7a24 [map_identity]: respect match ergonomics 2023-11-11 13:48:26 +01:00
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
Jason Newcomb
a44bb07900 Change divergence checking to match the compiler's type system based definition of divergence. 2023-11-09 17:57:06 -05:00
Jason Newcomb
16d58a2982 Lift expr_diverges to clippy_utils as is_never_expr 2023-11-09 17:45:59 -05: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