]> git.lizzy.rs Git - rust.git/log
rust.git
21 months agoAuto merge of #9475 - Nemo157:mod-files-remap, r=xFrednet
bors [Wed, 14 Sep 2022 20:09:49 +0000 (20:09 +0000)]
Auto merge of #9475 - Nemo157:mod-files-remap, r=xFrednet

Make module-style lints resilient to --remap-path-prefix

changelog: [`self_named_module_files`], [`mod_module_files`]: Make module-style lints resilient to `--remap-path-prefix`

Without this if a user has configured `--remap-path-prefix` to be used for a prefix containing the current source directory the lints would silently fail to generate a warning.

21 months agoAuto merge of #9476 - Xaeroxe:bool-to-int-inverted, r=xFrednet
bors [Wed, 14 Sep 2022 19:56:12 +0000 (19:56 +0000)]
Auto merge of #9476 - Xaeroxe:bool-to-int-inverted, r=xFrednet

`bool_to_int_with_if` inverse case patch

Enhances `bool_to_int_with_if` such that it can also catch an inverse bool int conversion scenario, and makes the right suggestion for converting to int with a prefixed negation operator.

changelog: [`bool_to_int_with_if`]: Now correctly detects the inverse case, `if bool { 0 } else { 1 }`

21 months agofix: clippy_utils::Sugg should treat hir::ExprKind::DropTemps as transparent
Jacob Kiesel [Wed, 14 Sep 2022 19:29:32 +0000 (13:29 -0600)]
fix: clippy_utils::Sugg should treat hir::ExprKind::DropTemps as transparent

21 months agorefactor: use clippy_utils::Sugg instead of direct string ops
Jacob Kiesel [Wed, 14 Sep 2022 19:28:54 +0000 (13:28 -0600)]
refactor: use clippy_utils::Sugg instead of direct string ops

21 months agodogfood inverse bool_to_int_with_if
Jacob Kiesel [Wed, 14 Sep 2022 06:27:56 +0000 (00:27 -0600)]
dogfood inverse bool_to_int_with_if

21 months ago`bool_to_int_with_if` inverse case patch
Jacob Kiesel [Wed, 14 Sep 2022 05:50:47 +0000 (23:50 -0600)]
`bool_to_int_with_if` inverse case patch

21 months agoAuto merge of #8518 - Alexendoo:write-late-pass, r=flip1995
bors [Wed, 14 Sep 2022 15:58:21 +0000 (15:58 +0000)]
Auto merge of #8518 - Alexendoo:write-late-pass, r=flip1995

Migrate write.rs to a late pass

changelog: Migrates write.rs from a pre expansion pass to a late pass
changelog: [`positional_named_format_parameters`] is renamed in favour of the rustc lint `named_arguments_used_positionally`

- Macros are now identified by diagnostic items, so will no longer lint user defined macros named, e.g. a custom `print!`
- `print_literal`/`write_literal` no longer lint no longer lint literals that come from macro expansions, e.g. `env!("FOO")`
- `print_with_newline`/`write_with_newline` no longer lint strings with any internal `\r` or `\n`s

~~A false negative, `print_literal`/`write_literal` don't lint format strings that produce `FormatSpec`s, e.g. ones containing pretty print/width/align specifiers~~

Suggestion changes:
- ~~`print_literal`/`write_literal` no longer have suggestions, as the spans for the `{}`s were not easily obtainable~~
-  `print_with_newline`/`write_with_newline` has a better suggestion for a sole literal newline, but no longer has suggestions for len > 1 strings that end in a literal newline
- ~~`use_debug` spans are less precise, now point to the whole format string~~

The diff for write.rs is pretty unwieldy, other than for the `declare_clippy_lint!`s I think you'd be better off viewing it as a brand new file rather than looking at the diff, as it's mostly written from scratch

cc #6610, fixes #5721, fixes #7195, fixes #8615

21 months agoAuto merge of #9465 - Alexendoo:peekable-fp, r=flip1995
bors [Wed, 14 Sep 2022 15:03:39 +0000 (15:03 +0000)]
Auto merge of #9465 - Alexendoo:peekable-fp, r=flip1995

Fix `unused_peekable` closure and `f(&mut peekable)` false positives

changelog: Fix [`unused_peekable`] false positive when peeked in a closure or called as `f(&mut peekable)`

The `return`/`break` changes aren't part of the fix, they allow an earlier return in some cases. `break` is replaced with `return` for style purposes as they do the same thing in this case

Fixes #9456
Fixes #9462

21 months agoAuto merge of #9467 - pyhrr0:macro_expansion, r=giraffate
bors [Tue, 13 Sep 2022 23:45:29 +0000 (23:45 +0000)]
Auto merge of #9467 - pyhrr0:macro_expansion, r=giraffate

Fix `almost_complete_letter_range` false positive.

changelog: Fix [`almost_complete_letter_range`] false positive in an external macro

21 months agoMake module-style lints resilient to --remap-path-prefix
Wim Looman [Tue, 13 Sep 2022 19:27:01 +0000 (21:27 +0200)]
Make module-style lints resilient to --remap-path-prefix

21 months agoAuto merge of #9474 - c410-f3r:arith, r=llogiq
bors [Tue, 13 Sep 2022 19:00:24 +0000 (19:00 +0000)]
Auto merge of #9474 - c410-f3r:arith, r=llogiq

[arithmetic-side-effects] More non-overflowing ops

* Adding or Subtracting 0
* Division and Module of anything other than 0
* Multiplying 1 or 0

changelog: [arithmetic-side-effects] More non-overflowing operations

21 months ago[arithmetic-side-effects] More non-overflowing ops
Caio [Tue, 13 Sep 2022 18:50:24 +0000 (15:50 -0300)]
[arithmetic-side-effects] More non-overflowing ops

21 months agoAuto merge of #9429 - kraktus:deriv_ma, r=xFrednet
bors [Tue, 13 Sep 2022 16:43:04 +0000 (16:43 +0000)]
Auto merge of #9429 - kraktus:deriv_ma, r=xFrednet

Make `derivable_impls` machine applicable

changelog: [`derivable_impls`]: Now machine applicable

21 months agoMake `derivable_impls` machine applicable
kraktus [Mon, 5 Sep 2022 10:04:54 +0000 (12:04 +0200)]
Make `derivable_impls` machine applicable

21 months agoAuto merge of #9454 - kraktus:use_self, r=flip1995
bors [Tue, 13 Sep 2022 12:44:16 +0000 (12:44 +0000)]
Auto merge of #9454 - kraktus:use_self, r=flip1995

Do not lint `use_self` in proc macro expansion

fix https://github.com/rust-lang/rust-clippy/issues/9440
fix https://github.com/rust-lang/rust-clippy/issues/8910
fix https://github.com/rust-lang/rust-clippy/issues/6902

changelog: [`use_self`]: Do not lint in proc macro expansion

21 months agoAuto merge of #9452 - kraktus:doc, r=flip1995
bors [Tue, 13 Sep 2022 12:29:26 +0000 (12:29 +0000)]
Auto merge of #9452 - kraktus:doc, r=flip1995

Fix dev book

fix `implements_trait` and `in_external_macro` import path

Remove example using `match_trait_method` since its deprecated.

changelog: none

21 months agoOnly ignore external macros.
S. van Dijk [Tue, 13 Sep 2022 07:51:32 +0000 (09:51 +0200)]
Only ignore external macros.

21 months agoAuto merge of #9464 - lukaslueg:issue9463, r=dswij
bors [Mon, 12 Sep 2022 16:56:53 +0000 (16:56 +0000)]
Auto merge of #9464 - lukaslueg:issue9463, r=dswij

Don't panic on invalid shift while constfolding

Instead of panicking on invalid shifts while folding constants we simply give up. Fixes #9463

Notice the "attempt to shift right by `1316134912_u32`", which seems weird. AFAICS it comes from rustc itself.

changelog: none

21 months agoAuto merge of #9466 - lukaslueg:issue9460, r=dswij
bors [Mon, 12 Sep 2022 16:35:30 +0000 (16:35 +0000)]
Auto merge of #9466 - lukaslueg:issue9460, r=dswij

Don't lint `large_stack_array` inside static items

We now check if the linted `Expr` is inside an `ItemKind::Static`, which can't take the suggested `Box<[...]`. I _think_ this is the correct fix for #9460

I removed `if_chain` while I was at it.

changelog: Don't lint `large_stack_array` inside static items

21 months agoAuto merge of #9469 - Alexendoo:expr-field-visitor, r=giraffate
bors [Mon, 12 Sep 2022 13:58:53 +0000 (13:58 +0000)]
Auto merge of #9469 - Alexendoo:expr-field-visitor, r=giraffate

Fix FormatArgsExpn parsing of FormatSpec positions

Woops, forgot visitors don't walk themselves

Fixes #9468

r? `@giraffate`

changelog: none

21 months agoFix FormatArgsExpn parsing of FormatSpec positions
Alex Macleod [Mon, 12 Sep 2022 11:34:09 +0000 (11:34 +0000)]
Fix FormatArgsExpn parsing of FormatSpec positions

21 months agoAdd test.
S. van Dijk [Mon, 12 Sep 2022 08:44:44 +0000 (10:44 +0200)]
Add test.

21 months agoAuto merge of #9458 - Alexendoo:expr-field-visitor, r=giraffate
bors [Mon, 12 Sep 2022 00:21:28 +0000 (00:21 +0000)]
Auto merge of #9458 - Alexendoo:expr-field-visitor, r=giraffate

Use `visit_expr_field` for `ParamPosition`

A small change to make it a little simpler

changelog: none

21 months agoStop lint from checking code expanded from macros.
S. van Dijk [Sun, 11 Sep 2022 18:15:35 +0000 (20:15 +0200)]
Stop lint from checking code expanded from macros.

21 months agoAuto merge of #9410 - dswij:issue-9375, r=xFrednet
bors [Sun, 11 Sep 2022 15:10:00 +0000 (15:10 +0000)]
Auto merge of #9410 - dswij:issue-9375, r=xFrednet

Use macro callsite when creating `Sugg` helper

Closes #9375

changelog: Improvement: [`collapsible_if`]: Suggestions now work with macros, by taking the call site into account.

21 months agoDont lint `large_stack_array` inside static items
Lukas Lueg [Sun, 11 Sep 2022 14:24:33 +0000 (16:24 +0200)]
Dont lint `large_stack_array` inside static items

Fixes #9460

21 months agoFix `unused_peekable` closure and `f(&mut peekable)` false positives
Alex Macleod [Sun, 11 Sep 2022 12:17:51 +0000 (12:17 +0000)]
Fix `unused_peekable` closure and `f(&mut peekable)` false positives

21 months agoDon't panic on invalid shift while constfolding
Lukas Lueg [Sun, 11 Sep 2022 10:26:13 +0000 (12:26 +0200)]
Don't panic on invalid shift while constfolding

Fixes #9463

21 months agoAuto merge of #9457 - kraktus:nonminimal_bool, r=Manishearth
bors [Sat, 10 Sep 2022 19:11:08 +0000 (19:11 +0000)]
Auto merge of #9457 - kraktus:nonminimal_bool, r=Manishearth

Do not expand macro in `nonminimal_bool` suggestions

fix https://github.com/rust-lang/rust-clippy/issues/9428

changelog: Do not expand macros in [`nonminimal_bool`] suggestions

21 months agoUse visit_expr_field for ParamPosition
Alex Macleod [Sat, 10 Sep 2022 18:32:05 +0000 (18:32 +0000)]
Use visit_expr_field for ParamPosition

21 months agoDo not expand macro in `nonminimal_bool` suggestions
kraktus [Sat, 10 Sep 2022 17:48:14 +0000 (19:48 +0200)]
Do not expand macro in `nonminimal_bool` suggestions

21 months agoAuto merge of #9453 - kraktus:a_on_re_state, r=Jarcho
bors [Sat, 10 Sep 2022 13:18:06 +0000 (13:18 +0000)]
Auto merge of #9453 - kraktus:a_on_re_state, r=Jarcho

[`assertions_on_result_states`]: Fix suggestion when `assert!` is not in a statement.

fix https://github.com/rust-lang/rust-clippy/issues/9450

changelog: [`assertions_on_result_states`]: Fix suggestion when `assert!` is not in a statement.

21 months agoRemove duplicate context check
kraktus [Sat, 10 Sep 2022 09:47:07 +0000 (11:47 +0200)]
Remove duplicate context check

21 months agoDo not lint `use_self` in proc macro expansion
kraktus [Sat, 10 Sep 2022 09:36:31 +0000 (11:36 +0200)]
Do not lint `use_self` in proc macro expansion

21 months agorefactor: move `has_debug_impl` to `clippy_utils::ty`
kraktus [Sat, 10 Sep 2022 08:39:51 +0000 (10:39 +0200)]
refactor: move `has_debug_impl` to `clippy_utils::ty`

21 months ago`assertions_on_result_states` fix suggestion when `assert!` not in a statement
kraktus [Sat, 10 Sep 2022 08:30:19 +0000 (10:30 +0200)]
`assertions_on_result_states` fix suggestion when `assert!` not in a statement

21 months agoFix dev book
kraktus [Fri, 9 Sep 2022 20:43:19 +0000 (22:43 +0200)]
Fix dev book

fix `implements_trait` and `in_external_macro` import path

Remove example using `match_trait_method` since its deprecated

21 months agoAuto merge of #9448 - Alexendoo:large-enum-variant-u128, r=Manishearth
bors [Fri, 9 Sep 2022 17:21:53 +0000 (17:21 +0000)]
Auto merge of #9448 - Alexendoo:large-enum-variant-u128, r=Manishearth

Replace u128 with u64 in large_enum_variant uitest

A u128 has [an 8 byte alignment on x86](https://github.com/rust-lang/rust/issues/54341), but a 16 byte alignment on aarch64 which changes the size of the enums due to extra padding. This means the test fails on aarch64

changelog: none

21 months agoAuto merge of #9446 - mikerite:fix-9431-2, r=giraffate
bors [Thu, 8 Sep 2022 23:48:08 +0000 (23:48 +0000)]
Auto merge of #9446 - mikerite:fix-9431-2, r=giraffate

Fix `range_{plus,minus}_one` bad suggestions

Fixes #9431.

The current `range_plus_one` and `range_minus_one` suggestions are completely incorrect when macros are involved.

This commit resolves this by disabling the lints for any range expression that is expanded from a macro. The reasons for this are that it is very difficult to create a correct suggestion in this case and that false negatives are less important for pedantic lints.

changelog: Fix `range_{plus,minus}_one` bad suggestions

21 months agoReplace u128 with u64 in large_enum_variant uitest
Alex Macleod [Thu, 8 Sep 2022 20:42:03 +0000 (20:42 +0000)]
Replace u128 with u64 in large_enum_variant uitest

A u128 has an 8 byte alignment on x86, but a 16 byte alignment on
aarch64 which changes the size of the enums due to extra padding

21 months agoMigrate write.rs to a late pass
Alex Macleod [Tue, 30 Aug 2022 12:20:49 +0000 (12:20 +0000)]
Migrate write.rs to a late pass

21 months agoAuto merge of #9447 - flip1995:rustup, r=flip1995
bors [Thu, 8 Sep 2022 19:42:33 +0000 (19:42 +0000)]
Auto merge of #9447 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none

21 months agoBump nightly version -> 2022-09-08
Philipp Krones [Thu, 8 Sep 2022 19:27:37 +0000 (21:27 +0200)]
Bump nightly version -> 2022-09-08

21 months agoMerge remote-tracking branch 'upstream/auto' into rustup
Philipp Krones [Thu, 8 Sep 2022 19:27:09 +0000 (21:27 +0200)]
Merge remote-tracking branch 'upstream/auto' into rustup

21 months agoFix `range_{plus,minus}_one` bad suggestions
Michael Wright [Thu, 8 Sep 2022 18:04:43 +0000 (20:04 +0200)]
Fix `range_{plus,minus}_one` bad suggestions

Fixes #9431.

The current `range_plus_one` and `range_minus_one` suggestions
are completely incorrect when macros are involved.

This commit resolves this by disabling the lints for any range
expression that is expanded from a macro. The reasons for this
are that it is very difficult to create a correct suggestion in
this case and that false negatives are less important for
pedantic lints.

21 months agoAuto merge of #9443 - c410-f3r:arith, r=flip1995
bors [Thu, 8 Sep 2022 17:58:57 +0000 (17:58 +0000)]
Auto merge of #9443 - c410-f3r:arith, r=flip1995

Rename the arithmetic lint

changelog: Rename the `arithmetic` lint

21 months agoAuto merge of #9444 - Alexendoo:lintcheck-cargo, r=matthiaskrgr
bors [Thu, 8 Sep 2022 16:50:52 +0000 (16:50 +0000)]
Auto merge of #9444 - Alexendoo:lintcheck-cargo, r=matthiaskrgr

Update cargo in lintcheck_crates.toml

0.49.0 depends on a version of socket2 that no longer builds due to

```
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
   --> /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.3.11/src/sockaddr.rs:156:9
    |
156 |         mem::transmute::<SocketAddrV4, sockaddr_in>(v4);
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: source type: `SocketAddrV4` (48 bits)
    = note: target type: `sockaddr_in` (128 bits)
```

changelog: none

21 months agoUpdate cargo in lintcheck_crates.toml
Alex Macleod [Thu, 8 Sep 2022 15:29:26 +0000 (15:29 +0000)]
Update cargo in lintcheck_crates.toml

21 months agoRename the `arithmetic` lint
Caio [Thu, 8 Sep 2022 15:04:55 +0000 (12:04 -0300)]
Rename the `arithmetic` lint

22 months agoAuto merge of #9365 - c410-f3r:arith, r=Alexendoo
bors [Wed, 7 Sep 2022 19:55:34 +0000 (19:55 +0000)]
Auto merge of #9365 - c410-f3r:arith, r=Alexendoo

[Arithmetic] Consider literals

Fixes https://github.com/rust-lang/rust-clippy/issues/9307 and makes the `arithmetic` lint behave like `integer_arithmetic`.

It is worth noting that literal integers of a binary operation (`1 + 1`, `i32::MAX + 1`), **regardless if they are in a constant environment**, won't trigger the lint. Assign operations also have similar reasoning.

changelog: Consider literals in the arithmetic lint

22 months agoAuto merge of #9441 - Jarcho:hang_9433, r=Alexendoo
bors [Wed, 7 Sep 2022 19:43:00 +0000 (19:43 +0000)]
Auto merge of #9441 - Jarcho:hang_9433, r=Alexendoo

Fix hang in `vec_init_then_push`

fixes #9433
changelog: Fix infinite loop in `vec_init_then_push`

22 months agoFix hang in `vec_init_then_push`
Jason Newcomb [Wed, 7 Sep 2022 19:26:44 +0000 (15:26 -0400)]
Fix hang in `vec_init_then_push`

22 months agoAuto merge of #101432 - nnethercote:shrink-PredicateS, r=lcnr
bors [Wed, 7 Sep 2022 13:49:58 +0000 (13:49 +0000)]
Auto merge of #101432 - nnethercote:shrink-PredicateS, r=lcnr

Shrink `PredicateS`

r? `@ghost`

22 months ago[Arithmetic] Consider literals
Caio [Wed, 7 Sep 2022 13:00:45 +0000 (10:00 -0300)]
[Arithmetic] Consider literals

22 months agoAuto merge of #9421 - xphoniex:fix-#9420, r=giraffate
bors [Tue, 6 Sep 2022 23:44:38 +0000 (23:44 +0000)]
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate

Suggest `unwrap_or_default` when closure returns `"".to_string`

Closes https://github.com/rust-lang/rust-clippy/issues/9420

changelog: [`unwrap_or_else_default`]: suggest `unwrap_or_default()` instead of `unwrap_or_else` with a closure that returns an empty `to_string`.

22 months agoGeneralize the Assume intrinsic statement to a general Intrinsic statement
Oli Scherer [Tue, 12 Jul 2022 10:05:00 +0000 (10:05 +0000)]
Generalize the Assume intrinsic statement to a general Intrinsic statement

22 months agoLower the assume intrinsic to a MIR statement
Oli Scherer [Thu, 30 Jun 2022 08:16:05 +0000 (08:16 +0000)]
Lower the assume intrinsic to a MIR statement

22 months agoSuggest `unwrap_or_default` when closure returns `"".to_string`
xphoniex [Tue, 6 Sep 2022 04:38:29 +0000 (04:38 +0000)]
Suggest `unwrap_or_default` when closure returns `"".to_string`

Signed-off-by: xphoniex <xphoniex@users.noreply.github.com>
22 months agoAuto merge of #101241 - camsteffen:refactor-binding-annotations, r=cjgillot
bors [Tue, 6 Sep 2022 03:16:29 +0000 (03:16 +0000)]
Auto merge of #101241 - camsteffen:refactor-binding-annotations, r=cjgillot

`BindingAnnotation` refactor

* `ast::BindingMode` is deleted and replaced with `hir::BindingAnnotation` (which is moved to `ast`)
* `BindingAnnotation` is changed from an enum to a tuple struct e.g. `BindingAnnotation(ByRef::No, Mutability::Mut)`
* Associated constants added for convenience `BindingAnnotation::{NONE, REF, MUT, REF_MUT}`

One goal is to make it more clear that `BindingAnnotation` merely represents syntax `ref mut` and not the actual binding mode. This was especially confusing since we had `ast::BindingMode`->`hir::BindingAnnotation`->`thir::BindingMode`.

I wish there were more symmetry between `ByRef` and `Mutability` (variant) naming (maybe `Mutable::Yes`?), and I also don't love how long the name `BindingAnnotation` is, but this seems like the best compromise. Ideas welcome.

22 months agoAuto merge of #101261 - TaKO8Ki:separate-receiver-from-arguments-in-hir, r=cjgillot
bors [Mon, 5 Sep 2022 16:21:40 +0000 (16:21 +0000)]
Auto merge of #101261 - TaKO8Ki:separate-receiver-from-arguments-in-hir, r=cjgillot

Separate the receiver from arguments in HIR

Related to #100232

cc `@cjgillot`

22 months agouse `propagate_through_exprs` instead of `propagate_through_expr`
Takayuki Maeda [Mon, 5 Sep 2022 05:26:00 +0000 (14:26 +0900)]
use `propagate_through_exprs` instead of `propagate_through_expr`

fix `ExprKind` static_assert_size

fix hir-stats

22 months agoAuto merge of #101228 - nnethercote:simplify-hir-PathSegment, r=petrochenkov
bors [Mon, 5 Sep 2022 13:36:54 +0000 (13:36 +0000)]
Auto merge of #101228 - nnethercote:simplify-hir-PathSegment, r=petrochenkov

Simplify `hir::PathSegment`

r? `@petrochenkov`

22 months agorefactor: remove unnecessary variables
Takayuki Maeda [Fri, 2 Sep 2022 13:48:14 +0000 (22:48 +0900)]
refactor: remove unnecessary variables

22 months agoseparate the receiver from arguments in HIR under /clippy
Takayuki Maeda [Thu, 1 Sep 2022 09:43:35 +0000 (18:43 +0900)]
separate the receiver from arguments in HIR under /clippy

22 months agoRollup merge of #101142 - nnethercote:improve-hir-stats, r=davidtwco
Dylan DPC [Mon, 5 Sep 2022 08:45:51 +0000 (14:15 +0530)]
Rollup merge of #101142 - nnethercote:improve-hir-stats, r=davidtwco

Improve HIR stats

#100398 improve the AST stats collection done by `-Zhir-stats`. This PR does the same for HIR stats collection.

r? `@davidtwco`

22 months agoPack `Term` in the same way as `GenericArg`.
Nicholas Nethercote [Mon, 5 Sep 2022 04:03:53 +0000 (14:03 +1000)]
Pack `Term` in the same way as `GenericArg`.

This shrinks the `PredicateS` type, which is instanted frequently.

22 months agoAuto merge of #9342 - relrelb:or_default, r=dswij
bors [Mon, 5 Sep 2022 04:54:31 +0000 (04:54 +0000)]
Auto merge of #9342 - relrelb:or_default, r=dswij

Suggest `Entry::or_default` for `Entry::or_insert(Default::default())`

Unlike past similar work done in #6228, expand the existing `or_fun_call`
lint to detect `or_insert` calls with a `T::new()` or `T::default()`
argument, much like currently done for `unwrap_or` calls. In that case,
suggest the use of `or_default`, which is more idiomatic.

Note that even with this change, `or_insert_with(T::default)` calls
aren't detected as candidates for `or_default()`, in the same manner
that currently `unwrap_or_else(T::default)` calls aren't detected as
candidates for `unwrap_or_default()`.

Also, as a nearby cleanup, change `KNOW_TYPES` from `static` to `const`,
since as far as I understand it's preferred (should Clippy have a lint
for that?).

Addresses #3812.

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`or_fun_call`]: Suggest `Entry::or_default` for `Entry::or_insert(Default::default())`

22 months agoMake `hir::PathSegment::res` non-optional.
Nicholas Nethercote [Tue, 30 Aug 2022 05:10:28 +0000 (15:10 +1000)]
Make `hir::PathSegment::res` non-optional.

22 months agoSuggest `Entry::or_default` for `Entry::or_insert(Default::default())`
relrelb [Tue, 16 Aug 2022 20:26:03 +0000 (23:26 +0300)]
Suggest `Entry::or_default` for `Entry::or_insert(Default::default())`

Unlike past similar work done in #6228, expand the existing `or_fun_call`
lint to detect `or_insert` calls with a `T::new()` or `T::default()`
argument, much like currently done for `unwrap_or` calls. In that case,
suggest the use of `or_default`, which is more idiomatic.

Note that even with this change, `or_insert_with(T::default)` calls
aren't detected as candidates for `or_default()`, in the same manner
that currently `unwrap_or_else(T::default)` calls aren't detected as
candidates for `unwrap_or_default()`.

Also, as a nearby cleanup, change `KNOW_TYPES` from `static` to `const`,
since as far as I understand it's preferred (should Clippy have a lint
for that?).

Fixes #3812.

22 months agoAuto merge of #9425 - kraktus:patch-1, r=xFrednet
bors [Sun, 4 Sep 2022 15:32:09 +0000 (15:32 +0000)]
Auto merge of #9425 - kraktus:patch-1, r=xFrednet

fix wording for `derivable_impls`

While looking at the explanation as to why this lint was not automatically applicable, found the explanation a bit clunky grammatically.

 Feel free to close if you consider the wording was correct in the first place.

changelog: none

22 months agofix wording for `derivable_impls`
kraktus [Sun, 4 Sep 2022 14:29:30 +0000 (16:29 +0200)]
fix wording for `derivable_impls`

22 months agoAuto merge of #9424 - mikerite:fix-9351-4, r=xFrednet
bors [Sun, 4 Sep 2022 15:14:58 +0000 (15:14 +0000)]
Auto merge of #9424 - mikerite:fix-9351-4, r=xFrednet

Fix `unnecessary_to_owned` false positive

Fixes #9351.

Note that this commit reworks that fix for #9317. The change
is to check that the type implements `AsRef<str>` before regarding
`to_string` as an equivalent of `to_owned`. This was suggested
by Jarcho in the #9317 issue comments.

The benefit of this is that it moves some complexity out of
`check_other_call_arg` and simplifies the module as a whole.

changelog: FP: [`unnecessary_to_owned`]: No longer lints, if type change would cause errors in the caller function

22 months agoFix `unnecessary_to_owned` false positive
Michael Wright [Sat, 3 Sep 2022 15:00:44 +0000 (17:00 +0200)]
Fix `unnecessary_to_owned` false positive

Fixes #9351.

Note that this commit reworks that fix for #9317. The change
is to check that the type implements `AsRef<str>` before regarding
`to_string` as an equivalent of `to_owned`. This was suggested
by Jarcho in the #9317 issue comments.

The benefit of this is that it moves some complexity out of
`check_other_call_arg` and simplifies the module as a whole.

22 months agoAuto merge of #9400 - lukaslueg:approx_large_enum, r=llogiq
bors [Sat, 3 Sep 2022 07:34:42 +0000 (07:34 +0000)]
Auto merge of #9400 - lukaslueg:approx_large_enum, r=llogiq

Use `approx_ty_size` for `large_enum_variant`

This builds upon #9373 to use the approximate size of each variant for `large_enum_variant`. This allows us to lint in situations where an `enum` contains generics but is still guaranteed to have a large variant on an at-least basis, e.g. with `(T, [u8; 512])`.

* I've changed the wording from "is ... bytes" to "contains at least" because
  * the size is now an approximate lower bound (e.g. `512` in the example above). The actual size is larger due to `T`, including due to `T`'s memory layout.
  * the discriminant is not taken into account in the message. This comes up with variants like `A(T)`, which are "is at least 0 bytes" otherwise, which may be misleading.
* If the second-largest variant has no fields, there is a special case "carries no data" instead of "is at least 0 bytes".
* A variant like `A(T)` is "at least 0 bytes", which is technically true, yet we don't distinguish between "indeterminate" and truly "ZST".
* The generics-tests that were there before now lint while they didn't lint before. AFAICS this is correct.

I guess the above is correct-ish. However, I use the `SubstsRef` that I got via `cx.tcx.type_of(item.def_id)` to solve for generics in the variants. Is this even applicable, since we start from an - [ ] `ItemKind`?

changelog: none

22 months agoUse `approx_ty_size` for `large_enum_variant`
Lukas Lueg [Tue, 30 Aug 2022 20:27:21 +0000 (22:27 +0200)]
Use `approx_ty_size` for `large_enum_variant`

22 months agoAuto merge of #8952 - rust-lang:explain, r=xFredNet
bors [Fri, 2 Sep 2022 20:27:42 +0000 (20:27 +0000)]
Auto merge of #8952 - rust-lang:explain, r=xFredNet

add `--explain` subcommand

This closes #8291.

---

changelog: add `cargo clippy -- --explain <lintname>` subcommand

22 months agoadd `--explain` subcommand
Andre Bogus [Sun, 5 Jun 2022 08:44:14 +0000 (10:44 +0200)]
add `--explain` subcommand

22 months agoAuto merge of #9418 - lukaslueg:issue9415, r=llogiq
bors [Fri, 2 Sep 2022 18:54:06 +0000 (18:54 +0000)]
Auto merge of #9418 - lukaslueg:issue9415, r=llogiq

Fix `mut_mutex_lock` when Mutex is behind immutable deref

I *think* the problem here is the `if let ty::Ref(_, _, Mutability::Mut) = cx.typeck_results().expr_ty(recv).kind()` line tries to check if the `Mutex` can be mutably borrowed (there already is a test for `Arc<Mutex<_>>`), but gets bamboozled by the `&mut Arc` indirection. And I *think* checking the deref-adjustment to filter immutable-adjust (the deref through the `Arc`, starting from `&mut Arc`) is the correct fix.

Fixes #9415

changelog: Fix `mut_mutex_lock` when Mutex is behind immutable deref

22 months agoFix `mut_mutex_lock` for Mutex behind imm deref
Lukas Lueg [Fri, 2 Sep 2022 18:28:00 +0000 (20:28 +0200)]
Fix `mut_mutex_lock` for Mutex behind imm deref

Fixes #9415

22 months agoAuto merge of #9417 - Jarcho:ice_9414, r=Alexendoo
bors [Fri, 2 Sep 2022 18:07:38 +0000 (18:07 +0000)]
Auto merge of #9417 - Jarcho:ice_9414, r=Alexendoo

Don't use `hir_ty_to_ty` in `result_large_err`

fixes #9414

This occurs starting with 2022-09-01. I checked that this does fix the ICE on rust-lang/rust@9353538. Not sure which pr caused the late-bound region to leak through `hir_ty_to_ty`.

changelog: None

22 months agoclippy: BindingAnnotation change
Cameron Steffen [Tue, 30 Aug 2022 22:36:53 +0000 (17:36 -0500)]
clippy: BindingAnnotation change

22 months agoDon't use `hir_ty_to_ty` in `result_large_err` as it sometimes leaves late-bound...
Jason Newcomb [Fri, 2 Sep 2022 17:40:35 +0000 (13:40 -0400)]
Don't use `hir_ty_to_ty` in `result_large_err` as it sometimes leaves late-bound lifetimes.

22 months agoAuto merge of #9412 - xFrednet:jst-r-bool-to-int-lint, r=xFrednet
bors [Thu, 1 Sep 2022 21:39:06 +0000 (21:39 +0000)]
Auto merge of #9412 - xFrednet:jst-r-bool-to-int-lint, r=xFrednet

New lint `bool_to_int_with_if`

This is a rebased version of https://github.com/rust-lang/rust-clippy/pull/9086 I could sadly not push directly push to the PR branch as it's protected.

The lint implementation comes from `@jst-r.` Thank you for the work you put into this :)

---

Closes: https://github.com/rust-lang/rust-clippy/issues/8131
Closes: https://github.com/rust-lang/rust-clippy/pull/9086
changelog: Add lint [`bool_to_int_with_if`]

r? `@ghost`

22 months agoNew lint `bool_to_int_with_if`
Dmitrii Lavrov [Thu, 30 Jun 2022 13:57:15 +0000 (16:57 +0300)]
New lint `bool_to_int_with_if`

22 months agoAuto merge of #9404 - lukaslueg:issue9402, r=giraffate
bors [Thu, 1 Sep 2022 13:18:17 +0000 (13:18 +0000)]
Auto merge of #9404 - lukaslueg:issue9402, r=giraffate

Fix `suboptimal_float` not linting on `{const}.powf({const})`

There used to be an early return if the receiver was an effective const but the method was not linted, not taking into account later cases where the receiver and the arguments are both effective consts for different methods. Removed the early return.

Fixes #9402
Fixes #9201

changelog: Fix `suboptimal_flops`, `imprecise_flops` not linting on `{const}.powf({const})` et al

22 months agoFix {subopt,imprec}_float not lint const.*(const)
Lukas Lueg [Wed, 31 Aug 2022 19:08:33 +0000 (21:08 +0200)]
Fix {subopt,imprec}_float not lint const.*(const)

Fixes #9402
Fixes #9201

22 months agoUse macro source when creating `Sugg` helper
dswij [Wed, 31 Aug 2022 16:47:56 +0000 (00:47 +0800)]
Use macro source when creating `Sugg` helper

22 months agoAuto merge of #9406 - Jarcho:unescape_ice, r=Manishearth
bors [Thu, 1 Sep 2022 04:12:00 +0000 (04:12 +0000)]
Auto merge of #9406 - Jarcho:unescape_ice, r=Manishearth

Correctly handle unescape warnings

fixes #9405

changelog: Fix ICE when format literals raise compiler warnings

22 months agoCorrectly handle unescape warnings
Jason Newcomb [Thu, 1 Sep 2022 03:24:29 +0000 (23:24 -0400)]
Correctly handle unescape warnings

22 months agoAuto merge of #101249 - matthiaskrgr:rollup-wahnoz8, r=matthiaskrgr
bors [Wed, 31 Aug 2022 21:45:18 +0000 (21:45 +0000)]
Auto merge of #101249 - matthiaskrgr:rollup-wahnoz8, r=matthiaskrgr

Rollup of 10 pull requests

Successful merges:

 - #100787 (Pretty printing give proper error message without panic)
 - #100838 (Suggest moving redundant generic args of an assoc fn to its trait)
 - #100844 (migrate rustc_query_system to use SessionDiagnostic)
 - #101140 (Update Clippy)
 - #101161 (Fix uintended diagnostic caused by `drain(..)`)
 - #101165 (Use more `into_iter` rather than `drain(..)`)
 - #101229 (Link “? operator” to relevant chapter in The Book)
 - #101230 (lint: avoid linting diag functions with diag lints)
 - #101236 (Avoid needless buffer zeroing in `std::sys::windows::fs`)
 - #101240 (Fix a typo on `wasm64-unknown-unknown` doc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

22 months agoAuto merge of #9403 - softmoth:wild_err_expect, r=Alexendoo
bors [Wed, 31 Aug 2022 13:53:39 +0000 (13:53 +0000)]
Auto merge of #9403 - softmoth:wild_err_expect, r=Alexendoo

match_wild_err_arm: Fix typo in note text

changelog: [`match_wild_err_arm`]: fix typo in note text

22 months agoUse `CountIsStart` in clippy
Jason Newcomb [Wed, 31 Aug 2022 13:33:32 +0000 (09:33 -0400)]
Use `CountIsStart` in clippy

22 months agoMerge commit 'f51aade56f93175dde89177a92e3669ebd8e7592' into clippyup
Jason Newcomb [Wed, 31 Aug 2022 13:24:45 +0000 (09:24 -0400)]
Merge commit 'f51aade56f93175dde89177a92e3669ebd8e7592' into clippyup

22 months agofix a clippy test
Ralf Jung [Wed, 31 Aug 2022 13:24:40 +0000 (15:24 +0200)]
fix a clippy test

22 months agomatch_wild_err_arm: Fix typo in note text
Tim Siegel [Wed, 31 Aug 2022 13:09:11 +0000 (09:09 -0400)]
match_wild_err_arm: Fix typo in note text

22 months agoAuto merge of #9397 - Jarcho:trait_dup_order, r=dswij
bors [Wed, 31 Aug 2022 08:07:33 +0000 (08:07 +0000)]
Auto merge of #9397 - Jarcho:trait_dup_order, r=dswij

Fix the emission order of `trait_duplication_in_bounds`

Makes the lint emit in source order rather than whatever order the hash map happens to be in. This is currently blocking the sync into rustc.

changelog: None

22 months agoAuto merge of #98919 - 5225225:stricter-invalid-value, r=RalfJung
bors [Tue, 30 Aug 2022 20:39:01 +0000 (20:39 +0000)]
Auto merge of #98919 - 5225225:stricter-invalid-value, r=RalfJung

Strengthen invalid_value lint to forbid uninit primitives, adjust docs to say that's UB

For context: https://github.com/rust-lang/rust/issues/66151#issuecomment-1174477404=

This does not make it a FCW, but it does explicitly state in the docs that uninit integers are UB.

This also doesn't affect any runtime behavior, uninit u32's will still successfully be created through mem::uninitialized.

22 months agoAuto merge of #9373 - lukaslueg:result_large_err, r=Alexendoo
bors [Tue, 30 Aug 2022 18:20:45 +0000 (18:20 +0000)]
Auto merge of #9373 - lukaslueg:result_large_err, r=Alexendoo

Initial implementation `result_large_err`

This is a shot at #6560, #4652, and #3884. The lint checks for `Result` being returned from functions/methods where the `Err` variant is larger than a configurable threshold (the default of which is 128 bytes). There has been some discussion around this, which I'll try to quickly summarize:

* A large `Err`-variant may force an equally large `Result` if `Err` is actually bigger than `Ok`.
* There is a cost involved in large `Result`, as LLVM may choose to `memcpy` them around above a certain size.
* We usually expect the `Err` variant to be seldomly used, but pay the cost every time.
* `Result` returned from library code has a high chance of bubbling up the call stack, getting stuffed into `MyLibError { IoError(std::io::Error), ParseError(parselib::Error), ...}`, exacerbating the problem.

This PR deliberately does not take into account comparing the `Ok` to the `Err` variant (e.g. a ratio, or one being larger than the other). Rather we choose an absolute threshold for `Err`'s size, above which we warn. The reason for this is that `Err`s probably get `map_err`'ed further up the call stack, and we can't draw conclusions from the ratio at the point where the `Result` is returned. A relative threshold would also be less predictable, while not accounting for the cost of LLVM being forced to generate less efficient code if the `Err`-variant is _large_ in absolute terms.

We lint private functions as well as public functions, as the perf-cost applies to in-crate code as well.

In order to account for type-parameters, I conjured up `fn approx_ty_size`. The function relies on `LateContext::layout_of` to compute the actual size, and in case of failure (e.g. due to generics) tries to come up with an "at least size". In the latter case, the size of obviously wrong, but the inspected size certainly can't be smaller than that. Please give the approach a heavy dose of review, as I'm not actually familiar with the type-system at all (read: I have no idea what I'm doing).

The approach does, however flimsy it is, allow us to successfully lint situations like

```rust
pub union UnionError<T: Copy> {
    _maybe: T,
    _or_perhaps_even: (T, [u8; 512]),
}

// We know `UnionError<T>` will be at least 512 bytes, no matter what `T` is
pub fn param_large_union<T: Copy>() -> Result<(), UnionError<T>> {
    Ok(())
}
```

I've given some refactoring to `functions/result_unit_err.rs` to re-use some bits. This is also the groundwork for #6409

The default threshold is 128 because of https://github.com/rust-lang/rust-clippy/issues/4652#issue-505670554

`lintcheck` does not trigger this lint for a threshold of 128. It does warn for 64, though.

The suggestion currently is the following, which is just a placeholder for discussion to be had. I did have the computed size in a `span_label`. However, that might cause both ui-tests here and lints elsewhere to become flaky wrt to their output (as the size is platform dependent).

```
error: the `Err`-variant returned via this `Result` is very large
  --> $DIR/result_large_err.rs:36:34
   |
LL | pub fn param_large_error<R>() -> Result<(), (u128, R, FullyDefinedLargeError)> {
   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The `Err` variant is unusually large, at least 128 bytes
```

changelog: Add [`result_large_err`] lint

22 months agoInitial implementation of `result_large_err`
Lukas Lueg [Wed, 24 Aug 2022 21:11:19 +0000 (23:11 +0200)]
Initial implementation of `result_large_err`

22 months agoFix the order of `trait_duplication_in_bounds`
Jason Newcomb [Tue, 30 Aug 2022 04:33:56 +0000 (00:33 -0400)]
Fix the order of `trait_duplication_in_bounds`
* Emit the lint in source order
* Make suggestions with multiple traits be in source order rather than alphabetical