Commit graph

10417 commits

Author SHA1 Message Date
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
Oli Scherer
d9259fdedd s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
868e513935 s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
bors
090df7a8af Auto merge of #11678 - slinkydeveloper:master, r=Alexendoo
Now `declare_interior_mutable_const` and `borrow_interior_mutable_const` respect the `ignore-interior-mutability` configuration entry

Fix #10537

changelog: Now `declare_interior_mutable_const` and `borrow_interior_mutable_const` respect the `ignore-interior-mutability` configuration entry
2023-10-20 16:50:39 +00:00
bors
e230f19e18 Auto merge of #11521 - y21:issue9122, r=llogiq
[`map_identity`]: allow closure with type annotations

Fixes #9122

`.map(|a: u32| a)` can help type inference, so we should probably allow this and not warn about "unnecessary map of the identity function"

changelog: [`map_identity`]: allow closure with type annotations
2023-10-20 13:28:30 +00:00
bors
214b4d91bd Auto merge of #115214 - Urgau:rfc-3127-trim-paths, r=compiler-errors
Implement rustc part of RFC 3127 trim-paths

This PR implements (or at least tries to) [RFC 3127 trim-paths](https://github.com/rust-lang/rust/issues/111540), the rustc part. That is `-Zremap-path-scope` with all of it's components/scopes.

`@rustbot` label: +F-trim-paths
2023-10-19 19:09:29 +00:00
bors
cd477d4b0c Auto merge of #11621 - GuillaumeGomez:needless_pass_by_ref_mut-closure-non-async-fn, r=blyxyas
Needless pass by ref mut closure non async fn

Fixes https://github.com/rust-lang/rust-clippy/issues/11620.
Fixes https://github.com/rust-lang/rust-clippy/issues/11561.

changelog: [`needless_pass_by_ref_mut`]: Correctly handle arguments moved into closure in non-async functions.

r? `@Centri3`
2023-10-19 12:04:07 +00:00
bors
9574d28cb6 Auto merge of #11683 - Alexendoo:msrv-config, r=Manishearth,flip1995
Deserialize `Msrv` directly in `Conf`

Gives the error a span pointing to the invalid config value

Also puts `Conf` itself in the `OnceLock` rather than just the `Msrv` for [the `register_late_mod_pass` work](https://github.com/rust-lang/rust/pull/116731) since it will be used from two different callbacks

changelog: none
2023-10-19 11:51:08 +00:00
Alex Macleod
1528c1db47 Deserialize Msrv directly in Conf 2023-10-18 20:35:09 +00:00
Guillaume Gomez
ec2b8ab83a Fix invalid warning for closure in non-async function for needless_pass_by_ref_mut lint 2023-10-18 21:17:02 +02:00
bors
fe21991520 Auto merge of #11496 - jonboh:prefix_postfix_struct, r=y21
add lint for struct field names

changelog: [`struct_field_names`]: lint structs with the same pre/postfix in all fields or with fields that are pre/postfixed with the name of the struct.

fixes #2555

I've followed general structure and naming from the code in [enum_variants](b788addfcc/clippy_lints/src/enum_variants.rs) lint, which implements the same logic for enum variants.
2023-10-18 18:47:27 +00:00
jonboh
8b02dac542 add lint for struct field names
side effect for `enum_variants`:
use .first() instead of .get(0) in enum_variants lint
move to_camel_case to str_util module
move module, enum and struct name repetitions check to a single file `item_name_repetitions`
rename enum_variants threshold config option
2023-10-18 19:20:08 +02:00
Guillaume Gomez
bc97f7d0c9 Don't emit needless_pass_by_ref_mut if the variable is used in an unsafe block or function 2023-10-17 15:34:19 +02:00
Urgau
09535a5d30 [RFC 3127 - Trim Paths]: Fix building tools (rustdoc, clippy, ...) 2023-10-17 10:11:31 +02:00
Arthur Lafrance
9ee26d078d fix lint failures in clippy 2023-10-16 19:50:31 -07:00
lengyijun
536114c857 [ignored_unit_patterns]: check &(), &&(), ... 2023-10-17 10:41:15 +08:00
bors
2cf708d04f Auto merge of #11646 - Nilstrieb:compiler-does-not-comply-with-the-lints!!, r=giraffate
Make `multiple_unsafe_ops_per_block` ignore await desugaring

The await desugaring contains two calls (`Poll::new_unchecked` and `get_context`) inside a single unsafe block. That violates the lint.

fixes #11312

changelog: [`multiple_unsafe_ops_per_block`]: fix false positives in `.await`
2023-10-17 00:35:50 +00:00
bors
9f27b1562c Auto merge of #11673 - y21:issue11672, r=Manishearth
[`unnecessary_lazy_eval`]: reduce applicability if closure has return type annotation

Fixes #11672

We already check if closure parameters don't have type annotations and reduce the applicability to `MaybeIncorrect` if they do, since those help type inference and removing them breaks code. We didn't do this for return type annotations however. This PR adds it. This doesn't change it to produce a fix that will compile, but it will prevent rustfix from auto-applying it.

(In general I'm not sure if we can suggest a fix that will compile. In this specific example, it might be possible to suggest `&[] as &[u8]`, but as-casts won't always work, e.g. `Default::default() as &[u8]` is a compile error, so just reducing applicability should be a safe fix in any case for now)

changelog: [`unnecessary_lazy_eval`]: reduce applicability to `MaybeIncorrect` if closure has return type annotation
2023-10-16 16:27:01 +00:00
Francesco Guardiani
3960bc024c Now declare_interior_mutable_const and borrow_interior_mutable_const respect the ignore-interior-mutability configuration entry
changelog: Now `declare_interior_mutable_const` and `borrow_interior_mutable_const` respect the `ignore-interior-mutability` configuration entry
Signed-off-by: slinkydeveloper <francescoguard@gmail.com>
2023-10-16 17:08:13 +02:00
bors
ef95be517c Auto merge of #11609 - y21:get_first_non_primitives, r=giraffate
[`get_first`]: lint on non-primitive slices

Fixes #11594

I left the issue open for a couple days before making the PR to see if anyone has something to say, but it looks like there aren't any objections to removing this check that prevented linting on non-primitive slices, so here's the PR now.
There's a couple of instances in clippy itself where we now emit the lint. The actual relevant change is in the first commit and fixing the `.get(0)` instances in clippy itself is in the 2nd commit.

changelog: [`get_first`]: lint on non-primitive slices
2023-10-15 23:53:22 +00:00
y21
bb6516ace0 [unnecessary_lazy_eval]: don't emit autofix suggestion if closure has return type 2023-10-16 00:47:13 +02:00
Nilstrieb
6ed04af81c Make multiple_unsafe_ops_per_block ignore await desugaring
The await desugaring contains two calls (`Poll::new_unchecked` and
`get_context`) inside a single unsafe block. That violates the lint.
2023-10-14 23:15:00 +02:00
bors
c40359d97a Auto merge of #11664 - koka831:fix/11134, r=blyxyas
Fix/11134

Fix #11134

Hir of `qpath` will be `TypeRelative(Ty { kind: Path(LangItem...` when a closure contains macro (e.g. https://github.com/rust-lang/rust-clippy/issues/11651) and #11134, it causes panic.
This PR avoids panicking and emitting incomplete path string when `qpath` contains `LangItem`.

changelog: none
2023-10-13 10:18:49 +00:00
koka
eb6fb18a99
Avoid panic!, omit instead 2023-10-13 17:07:29 +09:00
Alona Enraght-Moony
b5488f9850 [manual_is_ascii_check]: Also check for is_ascii_hexdigt 2023-10-12 19:12:42 +00:00
Nicholas Nethercote
359fa9822b Rejig some top-level rustc_hir_pretty functions.
There are several that are unused and can be removed.

And there are some calls to `to_string`, which can be expressed more
nicely as a `foo_to_string` call, and then `to_string` need not be
`pub`. (This requires adding `pat_to_string`).
2023-10-10 14:08:12 +11:00
y21
bba155ea9d move changed logic to into its own util function 2023-10-09 21:57:44 +02:00
bors
bde04824cc Auto merge of #11550 - blyxyas:fix-impl_trait_in_params-for_assocfn, r=dswij
`impl_trait_in_params` now supports impls and traits

Before this PR, the lint `impl_trait_in_params`. This PR gives the lint support for functions in impls and traits. (Also, some pretty heavy refactor)

fixes #11548
changelog:[`impl_trait_in_params`] now supports `impl` blocks and functions in traits
2023-10-08 21:57:56 +00:00
blyxyas
775573768e
Fix tests, only lint for public tests 2023-10-08 23:49:32 +02:00
blyxyas
5ed338dff9
impl_trait_in_params now supports impls and traits 2023-10-08 23:49:32 +02:00
bors
33f49f33d6 Auto merge of #11638 - samueltardieu:into-iter, r=Manishearth
Fix two typos in lint description

Fix #11636

changelog: none
2023-10-07 21:33:53 +00:00
bors
56400a0650 Auto merge of #116437 - nnethercote:rustc_features, r=Nilstrieb
Clean up `rustc_features`

Plenty more to be done, but this is a decent start.

r? `@Nilstrieb`
2023-10-07 19:11:17 +00:00
y21
1c6fa2989d [into_iter_without_iter]: look for iter method in deref chains 2023-10-07 16:33:06 +02:00
Samuel Tardieu
bffba76b52 Fix two typos in lint description 2023-10-07 10:58:52 +02:00
Matthias Krüger
0ed398eaa4 Rollup merge of #116423 - eltociear:patch-22, r=flip1995
Fix typo in attrs.rs

documenation -> documentation
2023-10-06 21:17:49 +02:00
koka
68d2082d69
Fix ice 2023-10-07 01:28:06 +09:00
Philipp Krones
8ebed4cc1a Merge commit 'b105fb4c39bc1a010807a6c076193cef8d93c109' into clippyup 2023-10-06 17:35:45 +02:00
Philipp Krones
b8677e54d4
Bump Clippy version -> 0.1.75 2023-10-06 17:32:44 +02:00
Philipp Krones
82c3064c47
Merge remote-tracking branch 'upstream/master' into rustup 2023-10-06 17:31:44 +02:00
bors
7217c0f3ac Auto merge of #11628 - koka831:fix/11625, r=blyxyas
Improve `redundant_locals` help message

Fixes #11625

AFAIK, `span_lint_and_help` points the beginning of spans when we pass multiple spans to the second argument, so This PR I also modified its help span and its message.

lint result of the given example in the issue will be:

```console
error: redundant redefinition of a binding `apple`
 --> src/main.rs:5:5
  |
5 |     let apple = apple;
  |     ^^^^^^^^^^^^^^^^^^
  |
help: `apple` is initially defined here
 --> src/main.rs:4:9
  |
4 |     let apple = 42;
  |         ^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_locals
```

I hope that this change might help reduce user confusion, but I'd appreciate alternative suggestions:)

changelog: [`redundant_locals`]: Now points at the rebinding of the variable
2023-10-06 15:06:00 +00:00
bors
279127ce2e Auto merge of #11611 - Alexendoo:items-after-test-module-check-crate, r=blyxyas
Fix `items_after_test_module` for non root modules, add applicable suggestion

Fixes #11050
Fixes #11153

changelog: [`items_after_test_module`]: Now suggests a machine-applicable suggestion.
changelog: [`items:after_test_module`]: Also lints for non root modules
2023-10-06 14:19:45 +00:00
koka
48d2770e52
Improve redundant_locals help message 2023-10-06 22:18:11 +09:00
Alex Macleod
dcc400191e Fix items_after_test_module for non root modules, add applicable suggestion 2023-10-06 12:46:04 +00:00
Jason Newcomb
9de3e6c928 Add more diagnostic items for clippy 2023-10-05 18:21:47 -04:00
Nicholas Nethercote
010a9b1e60 Rename Features::active_features.
The word "active" is currently used in two different and confusing ways:
- `ACTIVE_FEATURES` actually means "available unstable features"
- `Features::active_features` actually means "features declared in the
  crate's code", which can include feature within `ACTIVE_FEATURES` but
  also others.

(This is also distinct from "enabled" features which includes declared
features but also some edition-specific features automatically enabled
depending on the edition in use.)

This commit changes the `Features::active_features` to
`Features::declared_features` which actually matches its meaning.
Likewise, `Features::active` becomes `Features::declared`.
2023-10-05 18:01:11 +11:00
Michael Goulet
56794fa5f1 Fix clippy 2023-10-04 21:09:54 +00:00
y21
e6f29f1900 dogfood 2023-10-04 18:08:30 +02:00
y21
31fd282732 [get_first]: lint on non-primitive types 2023-10-04 18:07:54 +02:00
Ikko Eltociear Ashimine
faacd55741 Fix typo in attrs.rs
documenation -> documentation
2023-10-05 00:03:04 +09:00
xFrednet
eab0a75ff9
Update version attribute for 1.73 lints 2023-10-04 01:08:45 +02:00
bors
b437069f59 Auto merge of #11603 - koka831:fix/11599, r=y21
Fix: avoid changing drop order

Fixes https://github.com/rust-lang/rust-clippy/issues/11599

changelog: [`redundant_locals`] No longer lints which implements Drop trait to avoid reordering
2023-10-03 15:49:28 +00:00
koka
c7152679ef
Apply review suggestions from @y21 2023-10-04 00:13:53 +09:00
koka
1a56f90ee5
Fix: avoid changing drop order 2023-10-03 21:28:01 +09:00
koka
e465264d47
Avoid invoking ignored_unit_patterns in macro definition 2023-10-03 20:36:35 +09:00
bors
81400e2db8 Auto merge of #11589 - koka831:fix/10198, r=giraffate
std_instead_of_core: avoid lint inside of proc-macro

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

note: The lint for the reported `thiserror::Error` has been suppressed by [Don't lint unstable moves in std_instead_of_core](https://github.com/rust-lang/rust-clippy/pull/9545/files#diff-2cb8a24429cf9d9898de901450d640115503a10454d692dddc6a073a299fbb7eR29) because `thiserror::Error`  internally implements `std::error::Error for (derived struct)`.

changelog: [`std_intead_of_core`]: avoid linting inside proc-macro

I confirmed this change fixes the problem:
<details>
<summary>test result without the change</summary>

```console
error: used import from `std` instead of `core`
  --> tests/ui/std_instead_of_core.rs:65:14
   |
LL |     #[derive(ImplStructWithStdDisplay)]
   |              ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the derive macro `ImplStructWithStdDisplay` (in Nightly builds, run with -Z macro-backtrace for more info)
```
</details>
2023-10-03 01:26:29 +00:00
bors
08c429f241 Auto merge of #11596 - blyxyas:fix-fp-needless_pass_by_ref_mut, r=Jarcho
Move `needless_pass_by_ref_mut`: `suspicious` -> `nursery`

[Related to [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/needless_pass_by_ref_mut.20isn't.20ready.20for.20stable)]

`needless_pass_by_ref_mut` has been released with some important bugs (notably having a lot of reported false positives and an ICE). So it may not be really ready for being in stable until these problems are solved. This PR changes the lint's category from `suspicious` to `nursery`, just that.
changelog: none
2023-10-02 18:40:32 +00:00
blyxyas
3f0da4dda2
Move needless_pass_by_ref_mut: suspicious -> nursery 2023-10-02 13:28:45 +02:00
bors
331d01e2bf Auto merge of #11265 - Alexendoo:print-literal-unicode-escapes, r=llogiq
Don't escape unicode escape braces in `print_literal`

Fixes #11264

changelog: none
2023-10-01 22:17:18 +00:00
Alex Macleod
258b9a8562 Don't escape unicode escape braces in print_literal 2023-10-01 21:43:09 +00:00
bors
aee3daf90b Auto merge of #11593 - koka831:fix/10511, r=xFrednet
Use Span#from_expansion instead of in_external_macro

- fixes #10511

I checked [the reported repository](https://github.com/rust-lang/rust-clippy/issues/10511#issuecomment-1474271205) and found that clippy hangs at [py_sync.rs#L85](842094068e/crates/python/src/py_sync.rs (L85)), where a macro(`py_function_sync_async`) defines type parameters. this macro is used in the same crate, so `in_external_macro` wouldn't catch them.

This PR fixes the problem by using `Span#from_expansion`.

---

changelog: ICE: [`implicit_hasher`]: No longer lints inside macros, which could cause ICEs
[#11593](https://github.com/rust-lang/rust-clippy/pull/11593)
2023-10-01 16:33:04 +00:00
koka
6f1a78ffa8
Use Span#from_expansion instead of in_external_macro 2023-10-02 00:38:01 +09:00
Victor Song
9dfd60cf4f Remove extraneous #[non_exhaustive] check in lint 2023-10-01 09:54:45 -05:00
bors
3169423ce9 Auto merge of #115670 - Zoxc:outline-panic-macro-1, r=Mark-Simulacrum
Partially outline code inside the panic! macro

This outlines code inside the panic! macro in some cases. This is split out from https://github.com/rust-lang/rust/pull/115562 to exclude changes to rustc.
2023-10-01 05:56:47 +00:00
Victor Song
e683e3eeac Don't lint manual_non_exhaustive when enum explicitly marked as non_exhaustive
There are cases where users create a unit variant for the purposes
of tracking the number of variants for an nonexhaustive enum.
We should check if an enum is explicitly marked as nonexhaustive
before reporting `manual_non_exhaustive` in these cases. Fixes #11583
2023-09-30 22:57:54 -05:00
bors
0e43a04fab Auto merge of #11587 - y21:into_iter_without_iter, r=Jarcho
new lint: `into_iter_without_iter`

Closes #9736 (part 2)

This implements the other lint that my earlier PR missed: given an `IntoIterator for &Type` impl, check that there exists an inherent `fn iter(&self)` method.

changelog: new lint: `into_iter_without_iter`

r? `@Jarcho` since you reviewed #11527 I figured it makes sense for you to review this as well?
2023-09-30 18:43:37 +00:00
y21
8eb586d154 new lint: into_iter_without_iter 2023-09-30 19:38:16 +02:00
koka
44b6aca96b
Avoid linting in external/proc macro 2023-09-30 23:56:11 +09:00
bors
b00236d7f0 Auto merge of #11580 - y21:issue11579, r=Jarcho
[`manual_let_else`]: only omit block if span is from same ctxt

Fixes #11579.

The lint already had logic for omitting a block in `else` if a block is already present, however this didn't handle the case where the block is from a different expansion/syntax context. E.g.
```rs
macro_rules! panic_in_block {
  () => { { panic!() } }
}

let _ = match Some(1) {
  Some(v) => v,
  _ => panic_in_block!()
};
```
It would see this in its expanded form as `_ => { panic!() }` and think it doesn't have to include a block in its suggestion because it is already there, however that's not true if it's from a different expansion like in this case.

changelog: [`manual_let_else`]: only omit block in suggestion if the block is from the same expansion
2023-09-29 18:49:57 +00:00
y21
2d2017942a [manual_let_else]: only omit block if span is from same ctxt 2023-09-29 16:54:50 +02:00
koka
f4a8b12ed5
Wrap with parenthesis if necessary 2023-09-29 23:17:49 +09:00
bors
67a83ff057 Auto merge of #11582 - DaniPopes:missing-headers, r=xFrednet
Add missing lint description headers

Discovered in https://github.com/rust-lang/rust-analyzer/pull/15680/files#diff-7cb229b5139c72b6c230e3c195be375724c92226421fd57d5cf08872503e8c27L214-R226

changelog: none
2023-09-29 09:09:52 +00:00
Matthias Krüger
1a82ca0a61 Rollup merge of #116245 - flip1995:clippy-backport, r=Manishearth
Clippy backport: Move needless_raw_string_hashes to pedantic

Really small backport this time. Context: https://github.com/rust-lang/rust-clippy/pull/11415#issuecomment-1739880932

I'd rather get this in 1.74 than waiting another release cycle.

r? `@Manishearth`

cc `@Mark-Simulacrum` This should be merged before beta is branched tomorrow.
2023-09-29 10:11:14 +02:00
DaniPopes
ad5653b296
Add missing lint description headers 2023-09-29 03:08:34 +02:00
DaniPopes
38fd80a112 Remove rustc_lint_defs::lint_array 2023-09-28 23:01:25 +02:00
y21
330ebbb9f9 new lint: iter_without_into_iter 2023-09-28 22:22:36 +02:00
Alex Macleod
82207f4ff4 Move needless_raw_string_hashes to pedantic 2023-09-28 21:24:42 +02:00
bors
91997a4df4 Auto merge of #11565 - RalfJung:mir_to_const, r=Jarcho
mir_to_const improvements

This simplifies some code and also fixes the float array handling to properly take into account the `offset`, and to work with little-endian targets.

Fixes https://github.com/rust-lang/rust-clippy/issues/11488
changelog: none
2023-09-28 17:59:05 +00:00
bors
d18d01a8b1 Auto merge of #11576 - koka831:fix/10128, r=llogiq
write_literal: Fix index of the remaining positional arguments

- fixes https://github.com/rust-lang/rust-clippy/issues/10128
- `clippy --fix` replaces multiple warnings at once
   e.g.)
   ```rust
   writeln!(v, "{0} {1}", "hello", "world");
   // before: `writeln!(v, "hello {1}", "world");`
   // now: `writeln!(v, "hello world");`
   ```

changelog: [`print_literal`], [`write_literal`]: Now handles positional argument properly
2023-09-28 13:40:05 +00:00
bors
29ed6fa119 Auto merge of #11415 - Alexendoo:needless-raw-string-hashes-pedantic, r=flip1995
Move `needless_raw_string_hashes` to `pedantic`

IMO it doesn't improve code enough to be warn by default. [It seems to be unclear to some also](https://github.com/rust-lang/rust-clippy/issues/11402), but that can probably be remedied separately

changelog: Moved [`needless_raw_string_hashes`] to `pedantic` (Now allow-by-default)
[#11415](https://github.com/rust-lang/rust-clippy/pull/11415)

r? `@flip1995`
2023-09-28 10:34:33 +00:00
koka
b413bf6c4e
Fix index of the remaining positional arguments 2023-09-28 17:34:02 +09:00
unexge
62b8ef304a Mention that missing_assert_message lint ignores test functions 2023-09-27 22:06:01 +01:00
bors
3b75db7aa6 Auto merge of #116163 - compiler-errors:lazyness, r=oli-obk
Don't store lazyness in `DefKind::TyAlias`

1. Don't store lazyness of a type alias in its `DefKind`, but instead via a query.
2. This allows us to treat type aliases as lazy if `#[feature(lazy_type_alias)]` *OR* if the alias contains a TAIT, rather than having checks for both in separate parts of the codebase.

r? `@oli-obk` cc `@fmease`
2023-09-27 01:48:53 +00:00
bors
7f132e8e3a Auto merge of #116144 - lcnr:subst-less, r=oli-obk
subst -> instantiate

continues #110793, there are still quite a few uses of `subst` and `substitute`, but changing them all in the same PR was a bit too much, so I've stopped here for now.
2023-09-26 21:32:44 +00:00
bors
4494b6947f Auto merge of #11569 - Alexendoo:needless-raw-string-descr, r=llogiq
Describe the type of string in raw_strings lints

changelog: none
2023-09-26 21:16:33 +00:00
Alex Macleod
ec2f62677f Add manual_hash_one lint 2023-09-26 13:49:15 +00:00
Alex Macleod
6cdff10778 Describe the type of string in raw_strings lints 2023-09-26 11:49:44 +00:00
lcnr
f2efdba6e2 subst -> instantiate 2023-09-26 09:37:55 +02:00
koka
fab90003b8
Do not lint when imported item contains underscore 2023-09-26 12:58:48 +09:00
Michael Goulet
55074827b5 Don't store lazyness in DefKind 2023-09-26 02:53:59 +00:00
Ralf Jung
84d6894f26 it's not Miri but MIR constants 2023-09-25 16:19:02 +02:00
Alex Macleod
1972cc89c4 Test that each config value exists in a test clippy.toml 2023-09-25 12:38:23 +00:00
Philipp Krones
772296c50e Merge commit '7671c283a50b5d1168841f3014b14000f01dd204' into clippyup 2023-09-25 11:28:58 +02:00
Philipp Krones
903add0c11
Fix dogfood fallout 2023-09-25 10:31:51 +02:00
Philipp Krones
81fe8dc084
Merge remote-tracking branch 'upstream/master' into rustup 2023-09-25 10:26:11 +02:00
bors
aa137a7e57 Auto merge of #11552 - jonboh:ice_threshold_0_enum_variants, r=y21
prevent ice when threshold is 0 and enum has no variants

changelog: [`enum_variant_names`]: prevent ice when threshold is 0 and enum has no variants

r? `@y21`

Fixes the same ice issue raised during review of https://github.com/rust-lang/rust-clippy/pull/11496
2023-09-24 20:58:58 +00:00
Jon
0433e458da
use first instead of get(0)
Co-authored-by: Timo <30553356+y21@users.noreply.github.com>
2023-09-24 21:37:56 +02:00
Camille GILLOT
e2669b27f3 Remove GeneratorWitness and rename GeneratorWitnessMIR. 2023-09-23 13:47:30 +00:00
Camille GILLOT
0a2d39de2e Enable drop_tracking_mir by default. 2023-09-23 13:34:09 +00:00
bors
d732cce0d3 Auto merge of #11553 - mickvangelderen:fix-large-futures-example, r=xFrednet
Fix large_futures example

The value used in the large_futures example was not large enough to trigger the lint given the default threshold. The example also contained more code than necessary. This PR changes the value size from 1kB to 16kB and reduces the example in size.

changelog: [`large_futures`]: Fix and simplify example
2023-09-22 21:19:28 +00:00
bors
50139e6ad2 Auto merge of #11551 - Meczka:fix-fp-needless-pass-by-ref-mut, r=xFrednet
fixed fp caused by moving &mut reference inside of a closure

changelog: [`needless_pass_by_ref mut`]: fixes false positive caused by not covering mutable references passed to a closure inside of a fuction
fixes #11545
2023-09-22 21:07:46 +00:00
Mick van Gelderen
7e46fb9a65
Fix large_futures example
The value used in the large_futures example was not large enough to
trigger the lint given the default threshold.

The example also contained more code than necessary.

This PR changes the value size from 1kB to 16kB and reduces the example
in size.
2023-09-22 19:41:00 +02:00
jonboh
f3a27d20f6 prevent ice when threshold is 0 and enum has no variants 2023-09-22 17:18:49 +02:00
pc-linux
85801f55ef fixed fp caused by moving &mut reference inside of a closure 2023-09-22 16:54:21 +02:00
Michael Goulet
823bcb478b Record asyncness span in HIR 2023-09-21 19:18:14 +00:00
bors
33f084ef78 Auto merge of #11544 - Alexendoo:hir-ty-to-ty, r=Jarcho
Remove most usage of `hir_ty_to_ty`

Removes the usages where there's a suitable query or the type was already available elsewhere. The remaining cases would all require more involved changes

changelog: none

r? `@Jarcho`
2023-09-21 15:25:36 +00:00
bors
4d143d7e16 Auto merge of #11518 - mojave2:issue-11420, r=Alexendoo
fix FP with needless_raw_string_hashes

changelog: Fix [`needless_raw_string_hashes`]: Continue the lint checking of raw string when `needless_raw_strings` is allowed.

fix #11420
2023-09-21 12:27:24 +00:00
Guillaume Gomez
12815e95f9 Rollup merge of #115972 - RalfJung:const-consistency, r=oli-obk
rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const

Also, be more consistent with the `to/eval_bits` methods... we had some that take a type and some that take a size, and then sometimes the one that takes a type is called `bits_for_ty`.

Turns out that `ty::Const`/`mir::ConstKind` carry their type with them, so we don't need to even pass the type to those `eval_bits` functions at all.

However this is not properly consistent yet: in `ty` we have most of the methods on `ty::Const`, but in `mir` we have them on `mir::ConstKind`. And indeed those two types are the ones that correspond to each other. So `mir::ConstantKind` should actually be renamed to `mir::Const`. But what to do with `mir::Constant`? It carries around a span, that's really more like a constant operand that appears as a MIR operand... it's more suited for `syntax.rs` than `consts.rs`, but the bigger question is, which name should it get if we want to align the `mir` and `ty` types? `ConstOperand`? `ConstOp`? `Literal`? It's not a literal but it has a field called `literal` so it would at least be consistently wrong-ish...

``@oli-obk`` any ideas?
2023-09-21 13:25:39 +02:00
Oli Scherer
238dc2828e Prevent promotion of const fn calls in inline consts 2023-09-21 09:00:22 +00:00
Ralf Jung
2ea6ac5673 rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const 2023-09-21 08:12:30 +02:00
bors
c55669513a Auto merge of #11522 - y21:redundant_guards_pat_lhs, r=giraffate
[`redundant_guards`]: lint if the pattern is on the left side

A tiny improvement to the `redundant_guards` lint. There's no associated issue for this, just noticed it while going through the code.
Right now it warns on `Some(x) if x == 2` and suggests `Some(2)`, but it didn't do that for `Some(x) if 2 == x` (i.e. when the local is on the right side and the pattern on the left side).

changelog: [`redundant_guards`]: also lint if the pattern is on the left side
2023-09-20 23:57:25 +00:00
Alex Macleod
01c25a8eb6 Remove most usage of hir_ty_to_ty 2023-09-20 14:05:00 +00:00
Taiki Endo
77c121e817 Warn missing_enforced_import_renames by default 2023-09-20 19:05:51 +09:00
bors
ddbe110081 Auto merge of #11170 - tgross35:undocumented-unsafe-blocks-defaults, r=Centri3
Change defaults of `accept-comment-above-statement` and `accept-comment-above-attributes`

This patch sets the two configuration options for `undocumented_unsafe_blocks` to `true` by default: these are `accept-comment-above-statement` and `accept-comment-above-attributes`. Having these values `false` by default prevents what many users would consider clean code, e.g. placing the `// SAFETY:` comment above a single-line functino call, rather than directly next to the argument.

This was originally discussed in https://github.com/rust-lang/rust-clippy/issues/11162

changelog: [`undocumented_unsafe_blocks`]: set
`accept-comment-above-statement` and `accept-comment-above-attributes` to `true` by default.
2023-09-20 08:06:54 +00:00
bors
ece3878c8c Auto merge of #11492 - GuillaumeGomez:async-fn-returned-closure, r=Centri3
Fix mutaby used async function argument in closure for `needless_pass_by_ref_mut`

Fixes https://github.com/rust-lang/rust-clippy/issues/11380.

The problem was that it needed to go through closures as well in async functions to correctly find the mutable usage of async function arguments.

changelog: Correctly handle mutable usage of async function arguments in closures.

r? `@Centri3`
2023-09-20 07:48:54 +00:00
Trevor Gross
1b3e5dd0fc Change default configuration of undocumented_unsafe_blocks
This patch sets the two configuration options for
`undocumented_unsafe_blocks` to `true` by default: these are
`accept-comment-above-statement` and `accept-comment-above-attributes`.
Having these values `false` by default prevents what many users would
consider clean code, e.g. placing the `// SAFETY:` comment above a
single-line functino call, rather than directly next to the argument.

changelog: [`undocumented_unsafe_blocks`]: set
`accept-comment-above-statement` and `accept-comment-above-attributes`
to `true` by default.
2023-09-20 03:41:33 -04:00
bors
f464149b8f Auto merge of #11516 - mojave2:issue-11458, r=giraffate
fix cast_lossless with macro call

changelog: fix [`cast_lossless`] in the case when the cast operand is a macro call

fix #11458
2023-09-20 00:00:06 +00:00
bors
889e1b99bd Auto merge of #11530 - Alexendoo:zero-ptr-file-location, r=blyxyas
Move zero_ptr to the casts module

Also a bit of a touch up to the code while I was there

changelog: none
2023-09-18 22:19:59 +00:00
bors
5cba09c576 Auto merge of #11526 - Dev380:redundant-as-str, r=Manishearth
Add redundant_as_str lint

This lint checks for `as_str` on a `String` immediately followed by `as_bytes` or `is_empty` as those methods are available on `String` too. This could possibly also be extended to `&[u8]` in the future.

changelog: New lint [`redundant_as_str`] #11526
2023-09-18 21:31:48 +00:00