Commit Graph

10334 Commits

Author SHA1 Message Date
y21
b9efa3ee2c update references of clippy_utils::msrvs and clippy_lints::util::conf 2023-11-04 01:15:32 +01: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
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
95dc7be92f
Merge remote-tracking branch 'upstream/master' into rustup 2023-11-02 17:24:19 +01: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
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
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
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
bors
fa6fd8c346 Auto merge of #11726 - Wilfred:todo_docs, r=dswij
Expand docs on clippy::todo

https://doc.rust-lang.org/nightly/core/macro.todo.html describes that `todo!()` is intended for explicitly unfinished code. Explain this, and mention `unimplemented!()` as an alternative.

Whilst we're here, improve the punctuation on the other lints.

changelog: [`todo`]: expand docs
2023-10-29 09:07:51 +00:00
cui fliter
2030c58b81 Fix some typos
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-10-29 11:59:40 +08:00
dswij
2fea83b8c9 move read_zero_byte_vec to nursery 2023-10-29 03:40:45 +08:00
bors
5852ca8443 Auto merge of #11724 - rust-lang:fix-11559, r=blyxyas
Fix missing parenthesis in suboptimal floating point help

This fixes #11559 by adding a branch in the `Neg` implementation for `Sugg` that adds parentheses to keep precedence in order, then using that in the suggestion. I also removed some needless `.to_string()`s while I was at it.

---

changelog: none
2023-10-28 18:46:28 +00:00
bors
f8409ef85f Auto merge of #11696 - y21:iter_without_into_iter_suggestion, r=xFrednet
[`iter_without_into_iter`]: fix papercuts in suggestion and restrict linting to exported types

See #11692 for more context.

tldr: the lint `iter_without_into_iter` has suggestions that don't compile, which imo isn't that problematic because it does have the appropriate `Applicability` that tells external tools that it shouldn't be auto-applied.
However there were some obvious "errors" in the suggestion that really should've been included in my initial PR adding the lint, which is fixed by this PR:
- `IntoIterator::into_iter` needs a `self` argument.
- `IntoIterator::Iter` associated type doesn't exist. This should've just been `Item`.

This still doesn't make it machine applicable, and the remaining things are imho quite non-trivial to implement, as I've explained in https://github.com/rust-lang/rust-clippy/issues/11692#issuecomment-1773886111.
I personally think it's fine to leave it there and let the user change the remaining errors when copy-pasting the suggestion (e.g. errors caused by lifetimes that were permitted in fn return-position but are not in associated types).
This is how many of our other lint suggestions already work.

Also, we now restrict linting to only exported types. This required moving basically all of the tests around since they were previously in the `main` function. Same for `into_iter_without_iter`. The git diff is a bit useless here...

changelog: [`iter_without_into_iter`]: fix papercuts in suggestion and restrict linting to exported types

(cc `@lopopolo,` figured I should mention you since you created the issue)
2023-10-28 14:50:51 +00:00
y21
9a10d32c9a reword limitation section 2023-10-28 02:29:33 +02:00
Wilfred Hughes
58fe45102d Expand docs on clippy::todo
https://doc.rust-lang.org/nightly/core/macro.todo.html
describes that `todo!()` is intended for explicitly unfinished
code. Explain this, and mention `unimplemented!()` as an alternative.

Whilst we're here, improve the punctuation on the other lints.
2023-10-27 10:22:41 -07:00
Andre Bogus
1ed1001440 Fix missing parenthesis in suboptimal floating point help 2023-10-27 16:28:10 +02:00
Alex Macleod
f4b4e2ca1b Remove internal feature from clippy_utils 2023-10-27 13:13:26 +00:00
Oli Scherer
0c8caee7b9 Add gen blocks to ast and do some broken ast lowering 2023-10-27 13:05:48 +00:00
bors
2f0f4ddcf7 Auto merge of #11698 - a1phyr:waker_clone_and_wake, r=y21
Add `waker_clone_and_wake` lint to check needless `Waker` clones

Check for patterns of `waker.clone().wake()` and replace them with `waker.wake_by_ref()`.

An alternative name could be `waker_clone_then_wake`

changelog: [ `waker_clone_wake`]: new lint
2023-10-26 21:01:40 +00:00
bors
392b255280 Auto merge of #11712 - Alexendoo:remove-internal-warn, r=dswij
Remove the `internal_warn` lint category

`LINT_AUTHOR` and `DUMP_HIR` can be removed since their corresponding lint passes are only used for side effects

The metadata collector lint can be made an `internal` lint since `clippy::internal` is set to deny when running the collector

Also renames some internal lints/passes

changelog: none
2023-10-26 18:50:26 +00:00
bors
0da4dab720 Auto merge of #11584 - koka831:fix/11335, r=blyxyas
let_and_return: Wrap with parenthesis if necessary

- fixes https://github.com/rust-lang/rust-clippy/issues/11335

changelog: [`let_and_return`]: Wrap suggestion with parenthesis if necessary

r? `@Centri3`
2023-10-26 14:20:13 +00:00
y21
45f94c7598 mention restriction to exported types as a limitation 2023-10-26 01:07:20 +02:00
bors
7ce6e0d853 Auto merge of #11670 - lengyijun:ignored_unit_pattern_ref, r=dswij
[`ignored_unit_patterns`]: check &(), &&(), ...

changelog: [`ignored_unit_patterns`]: check &(), &&(), ...
2023-10-25 18:02:33 +00:00
Oli Scherer
c337899be6 Rename AsyncCoroutineKind to CoroutineSource
similar to how we have `MatchSource`, it explains where the desugaring came from.
2023-10-25 16:14:05 +00:00
Benoît du Garreau
ebf6667b57 Apply suggestions 2023-10-25 15:15:29 +02:00
Alex Macleod
0580080940 Remove the internal_warn lint category 2023-10-25 12:35:31 +00:00
Alex Macleod
7df1c8aa78 Hide config implementation details from public docs 2023-10-24 11:52:17 +00:00
Benoît du Garreau
f8790963d9 Add a lint to check needless Waker clones 2023-10-24 09:58:23 +02:00
Alex Macleod
4622203c9b Move configuration to new clippy_config crate 2023-10-23 20:05:10 +00:00
Alex Macleod
e1b287c3a6 Use multiple pushes in vec_init_then_push example 2023-10-23 18:32:51 +00:00
bors
033c763943 Auto merge of #11699 - Alexendoo:no-run-doctests, r=llogiq
Set doc-tests to `no_run`

This excludes `should_panic` tests, those are still run to ensure they panic. Most of our other doc snippets don't gain much from being run though so this frees up a nice bit of CI time

It also fixes the occasional issue such as `foo.txt`s being created f942470ca7/clippy_lints/src/permissions_set_readonly_false.rs (L19)

changelog: none
2023-10-23 18:15:01 +00:00
Alex Macleod
7347c1803f Set existing doc-tests to no_run 2023-10-23 15:28:26 +00:00
bors
9f5de6626b Auto merge of #11460 - J-ZhengLi:issue11429, r=Centri3
suggest passing function instead of calling it in closure for [`option_if_let_else`]

fixes: #11429

changelog: suggest passing function instead of calling it in closure for [`option_if_let_else`]
2023-10-23 14:37:13 +00:00
bors
f942470ca7 Auto merge of #11028 - BenWiederhake:dev-ifnotelse_neqzero, r=llogiq
Skip if_not_else lint for '!= 0'-style checks

Currently, clippy makes unhelpful suggestions such as this:

```
warning: unnecessary `!=` operation
   --> src/vm.rs:598:36
    |
598 |                     *destination = if source & 0x8000 != 0 { 0xFFFF } else { 0 };
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: change to `==` and swap the blocks of the `if`/`else`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else
    = note: `-W clippy::if-not-else` implied by `-W clippy::pedantic`
```

Bit tests often take on the form `if foo & 0x1234 != 0 { … } else { … }`, and the `!= 0` part reads as "has any bits set". Therefore, this code already has the "correct" order, and shouldn't be changed.

This PR disables the lint for these cases, and in fact all cases where the condition is "foo is non-zero".

I did my homework:
- \[X] Followed [lint naming conventions][lint_naming] → Not applicable, this PR fixes an existing lint
- \[X] Added passing UI tests (including committed `.stderr` file) → Yes, `tests/ui/if_not_else_bittest.rs`
- \[X] `cargo test` passes locally
- \[X] Executed `cargo dev update_lints`
- \[X] Added lint documentation → Not applicable, this PR fixes an existing lint
- \[X] Run `cargo dev fmt`

changelog: Fix [`if_not_else`] false positive when something like `bitflags != 0` is used
2023-10-23 07:42:15 +00:00
y21
3c501e4e41 [iter_without_into_iter]: fix papercuts + only lint on pub types 2023-10-22 20:19:31 +02:00
Philipp Krones
8e7d1678c4 Merge commit '2b030eb03d9e5837440b1ee0b98c50b97c0c5889' into clippyup 2023-10-21 14:16:11 +02:00
Philipp Krones
5f031561ef
Merge remote-tracking branch 'upstream/master' into rustup 2023-10-21 13:41:46 +02:00
bors
23af253fac Auto merge of #11539 - taiki-e:enforced-import-renames, r=Centri3
Warn missing_enforced_import_renames by default

Similar to https://github.com/rust-lang/rust-clippy/pull/8261 that did the same thing to disallowed_methods & disallowed_types.
This lint is also only triggered if import renames are defined in the `clippy.toml` file.

changelog: Moved [`missing_enforced_import_renames`] to `style` (Now warn-by-default)
[#11539](https://github.com/rust-lang/rust-clippy/pull/11539)
2023-10-21 10:40:29 +00:00