Commit Graph

6125 Commits

Author SHA1 Message Date
bors
5c3c6a2de6 Auto merge of #9483 - c410-f3r:arith, r=Jarcho
[arithmetic-side-effects] Finish non-overflowing ops

Extends https://github.com/rust-lang/rust-clippy/pull/9474 to also take into consideration "raw" binary operations. For example, `let a = b / 2` and `let a = 1 * b` won't trigger the lint.

changelog: [arithmetic-side-effects] Finish non-overflowing ops
2022-09-19 14:35:14 +00:00
bors
481dc2e81c Auto merge of #9409 - DesmondWillowbrook:iter_kv_map, r=xFrednet
Add `iter_kv_map` lint

fixes #9376

| before | after |
| -------------- | ------------------------- |
| `hmap.iter().map(\|(key, _)\| key)` | `hmap.keys()` |
| `hmap.iter().map(\|(_, v)\| v + 2)` | `hmap.values().map(\|v\| v + 2)` |
| `hmap.into_iter().map(\|(key, _)\| key)` | `hmap.into_keys()` |

Is `MachineApplicable`

changelog: [`iter_kv_map`]: added lint
2022-09-16 08:44:58 +00:00
Kartavya Vashishtha
c6219b2ece
remove identity function tests 2022-09-16 13:59:51 +05:30
Caio
dba5adae6e [arithmetic-side-effects] Finish non-overflowing ops 2022-09-15 13:28:18 -03:00
Kartavya Vashishtha
5004f04ecc
added identity block test
added binding annotations for all lines
2022-09-15 09:46:01 +05:30
Kartavya Vashishtha
5afc261c66
Add iter_kv_map lint 2022-09-15 09:41:06 +05:30
bors
e585b71d9e 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.
2022-09-14 20:09:49 +00:00
Jacob Kiesel
4ffdce09b6 refactor: use clippy_utils::Sugg instead of direct string ops 2022-09-14 13:35:35 -06:00
Jacob Kiesel
9925600870 dogfood inverse bool_to_int_with_if 2022-09-14 13:35:32 -06:00
Jacob Kiesel
1eb41804a2 bool_to_int_with_if inverse case patch 2022-09-14 13:33:13 -06:00
bors
2ddbc86bef 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
2022-09-14 15:58:21 +00:00
bors
9c9aa92898 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
2022-09-14 15:03:39 +00:00
bors
826a8930e6 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
2022-09-13 23:45:29 +00:00
Wim Looman
e9722feef3
Make module-style lints resilient to --remap-path-prefix 2022-09-13 21:38:56 +02:00
Caio
611c905482 [arithmetic-side-effects] More non-overflowing ops 2022-09-13 15:50:24 -03:00
kraktus
6f13203b2d Make derivable_impls machine applicable 2022-09-13 17:00:19 +02:00
bors
2e55b42dd7 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
2022-09-13 12:44:16 +00:00
S. van Dijk
69c7d2cca2
Only ignore external macros. 2022-09-13 10:35:59 +02:00
bors
7b8c4a9e83 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
2022-09-12 16:56:53 +00:00
bors
cdf26de6b5 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
2022-09-12 16:35:30 +00:00
bors
5e0663e25c 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
2022-09-12 13:58:53 +00:00
Alex Macleod
bd9d375c6b Fix FormatArgsExpn parsing of FormatSpec positions 2022-09-12 11:39:54 +00:00
S. van Dijk
4a6f7abeeb
Add test. 2022-09-12 10:46:29 +02:00
bors
69f6009f85 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.
2022-09-11 15:10:00 +00:00
Lukas Lueg
6f41a44c3e Dont lint large_stack_array inside static items
Fixes #9460
2022-09-11 16:24:33 +02:00
Alex Macleod
86d18b50ed Fix unused_peekable closure and f(&mut peekable) false positives 2022-09-11 12:40:52 +00:00
Lukas Lueg
1e23c65d5e Don't panic on invalid shift while constfolding
Fixes #9463
2022-09-11 12:26:13 +02:00
kraktus
d50f366612 Do not expand macro in nonminimal_bool suggestions 2022-09-10 19:48:14 +02:00
kraktus
c433d542cf Do not lint use_self in proc macro expansion 2022-09-10 11:42:37 +02:00
kraktus
cd69d86c89 assertions_on_result_states fix suggestion when assert! not in a statement 2022-09-10 10:30:19 +02:00
bors
5652ccbc0f 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
2022-09-09 17:21:53 +00:00
bors
b52fb5234c 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
2022-09-08 23:48:08 +00:00
Alex Macleod
8b25e53d50 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
2022-09-08 20:44:32 +00:00
Alex Macleod
6fc6d87fd0 Migrate write.rs to a late pass 2022-09-08 20:18:02 +00:00
Philipp Krones
4ee55c5528
Merge remote-tracking branch 'upstream/auto' into rustup 2022-09-08 21:27:09 +02:00
Michael Wright
a6d8afd958 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.
2022-09-08 20:04:43 +02:00
Caio
51d8b6c664 Rename the arithmetic lint 2022-09-08 12:04:55 -03:00
bors
617417e9ad 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
2022-09-07 19:55:34 +00:00
Jason Newcomb
15859323ea Fix hang in vec_init_then_push 2022-09-07 15:26:44 -04:00
Caio
0d078c9fd6 [Arithmetic] Consider literals 2022-09-07 10:00:45 -03:00
bors
7babd1b099 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`.
2022-09-06 23:44:38 +00:00
xphoniex
b21d9d307b
Suggest unwrap_or_default when closure returns "".to_string
Signed-off-by: xphoniex <xphoniex@users.noreply.github.com>
2022-09-06 04:38:29 +00:00
bors
ce339b219a 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.
2022-09-06 03:16:29 +00:00
Takayuki Maeda
4bcaddeeb2 separate the receiver from arguments in HIR under /clippy 2022-09-05 22:25:57 +09:00
relrelb
f0e586c251 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.
2022-09-04 23:43:17 +03:00
Michael Wright
750a2d57bd 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.
2022-09-03 17:00:44 +02:00
Lukas Lueg
584000a792 Use approx_ty_size for large_enum_variant 2022-09-03 00:16:28 +02:00
bors
c36696ac02 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
2022-09-02 18:54:06 +00:00
Lukas Lueg
ffc75af4cd Fix mut_mutex_lock for Mutex behind imm deref
Fixes #9415
2022-09-02 20:39:47 +02:00
bors
958a9cf297 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
2022-09-02 18:07:38 +00:00