Commit graph

7830 commits

Author SHA1 Message Date
y21
c9d2961100 teach eager_or_lazy that arithmetic ops can panic 2023-11-02 23:53:00 +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
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
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
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
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
Andre Bogus
1ed1001440 Fix missing parenthesis in suboptimal floating point help 2023-10-27 16:28:10 +02: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
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
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
Benoît du Garreau
ebf6667b57 Apply suggestions 2023-10-25 15:15:29 +02:00
Oli Scherer
ffc741965e Work around the fact that check_mod_type_wf may spuriously return ErrorGuaranteed, even if that error is only emitted by check_modwitem_types 2023-10-25 12:04:54 +00:00
bors
cd6ec97f0d Auto merge of #116773 - dtolnay:validatestable, r=compiler-errors
Validate `feature` and `since` values inside `#[stable(…)]`

Previously the string passed to `#[unstable(feature = "...")]` would be validated as an identifier, but not `#[stable(feature = "...")]`. In the standard library there were `stable` attributes containing the empty string, and kebab-case string, neither of which should be allowed.

Pre-existing validation of `unstable`:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![unstable(feature = "kebab-case", issue = "none")]

#[unstable(feature = "kebab-case", issue = "none")]
pub struct Struct;
```

```console
error[E0546]: 'feature' is not an identifier
 --> src/lib.rs:5:1
  |
5 | #![unstable(feature = "kebab-case", issue = "none")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

For an `unstable` attribute, the need for an identifier is obvious because the downstream code needs to write a `#![feature(...)]` attribute containing that identifier. `#![feature(kebab-case)]` is not valid syntax and `#![feature(kebab_case)]` would not work if that is not the name of the feature.

Having a valid identifier even in `stable` is less essential but still useful because it allows for informative diagnostic about the stabilization of a feature. Compare:

```rust
// src/lib.rs

#![allow(internal_features)]
#![feature(staged_api)]
#![stable(feature = "kebab-case", since = "1.0.0")]

#[stable(feature = "kebab-case", since = "1.0.0")]
pub struct Struct;
```

```rust
// src/main.rs

#![feature(kebab_case)]

use repro::Struct;

fn main() {}
```

```console
error[E0635]: unknown feature `kebab_case`
 --> src/main.rs:3:12
  |
3 | #![feature(kebab_case)]
  |            ^^^^^^^^^^
```

vs the situation if we correctly use `feature = "snake_case"` and `#![feature(snake_case)]`, as enforced by this PR:

```console
warning: the feature `snake_case` has been stable since 1.0.0 and no longer requires an attribute to enable
 --> src/main.rs:3:12
  |
3 | #![feature(snake_case)]
  |            ^^^^^^^^^^
  |
  = note: `#[warn(stable_features)]` on by default
```
2023-10-24 15:06:20 +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
bors
330d7fafb8 Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkov
report `unused_import` for empty reexports even it is pub

Fixes #116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing #115993.)
2023-10-23 20:24:09 +00:00
Alex Macleod
4622203c9b Move configuration to new clippy_config crate 2023-10-23 20:05:10 +00:00
David Tolnay
7ade24e824 Fix stable feature names in tests 2023-10-23 13:03:11 -07: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
350a6827a8 Auto merge of #116849 - oli-obk:error_shenanigans, r=cjgillot
Avoid a `track_errors` by bubbling up most errors from `check_well_formed`

I believe `track_errors` is mostly papering over issues that a sufficiently convoluted query graph can hit. I made this change, while the actual change I want to do is to stop bailing out early on errors, and instead use this new `ErrorGuaranteed` to invoke `check_well_formed` for individual items before doing all the `typeck` logic on them.

This works towards resolving https://github.com/rust-lang/rust/issues/97477 and various other ICEs, as well as allowing us to use parallel rustc more (which is currently rather limited/bottlenecked due to the very sequential nature in which we do `rustc_hir_analysis::check_crate`)

cc `@SparrowLii` `@Zoxc` for the new `try_par_for_each_in` function
2023-10-23 09:59:40 +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
bohan
87d0ace9ac use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
y21
d6fc606259 [map_identity]: recognize tuples 2023-10-21 15:40:34 +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
Oli Scherer
d9259fdedd s/generator/coroutine/ 2023-10-20 21:14:01 +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
Oli Scherer
4fc503ee37 Avoid a track_errors by bubbling up most errors from check_well_formed 2023-10-20 08:46:27 +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
Esteban Küber
a07c032e96 Tweak wording of type errors involving type params
Fix #78206.
2023-10-18 23:53:18 +00:00
Alex Macleod
1528c1db47 Deserialize Msrv directly in Conf 2023-10-18 20:35:09 +00:00
Guillaume Gomez
3e6db95e30 Add regression test for #11561 2023-10-18 21:17:32 +02:00
Guillaume Gomez
3b4b07c5f8 Add test for closure in non-async function for needless_pass_by_ref_mut lint 2023-10-18 21:17:31 +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
80a092c6df Add test for needless_pass_by_ref_mut to ensure that the lint is not emitted if variable is used in an unsafe block or function 2023-10-17 15:36:38 +02:00
bors
2640d5cc85 Auto merge of #11622 - GuillaumeGomez:needless_pass_by_ref_mut-regression-test-11610, r=blyxyas
Add regression test for #11610 about mutable usage of argument in async function for the `needless_pass_by_ref_mut` lint

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

This was already fixed. I simply added a regression test.

changelog: Add regression test for #11610 about mutable usage of argument in async function for the `needless_pass_by_ref_mut` lint
2023-10-17 12:20:03 +00:00
lengyijun
536114c857 [ignored_unit_patterns]: check &(), &&(), ... 2023-10-17 10:41:15 +08:00