Commit Graph

8330 Commits

Author SHA1 Message Date
bors
35b7ce5ca9 Auto merge of #9545 - Alexendoo:std-instead-of-core-unstable, r=Manishearth
Don't lint unstable moves in `std_instead_of_core`

Fixes #9515

changelog: [`std_instead_of_core`]: No longer suggests unstable modules such as `core::error`
2022-09-27 20:11:34 +00:00
kraktus
14ba4fba11 fix [needless_borrow] and [explicit_auto_deref] false positive on unions 2022-09-27 21:30:32 +02:00
bors
672fb8e42e Auto merge of #9491 - kraktus:drop_copy, r=Jarcho
[`drop_copy`]: Do not lint idiomatic in match arm

close https://github.com/rust-lang/rust-clippy/issues/9482

changelog: [`drop_copy`]: Do not lint idiomatic in match arm
2022-09-27 19:18:29 +00:00
kraktus
187c27e6b0 rename and_only_expr_in_arm -> is_single_call_in_arm 2022-09-27 21:01:23 +02:00
Alex Macleod
5b0f46a9d9 Don't lint unstable moves in std_instead_of_core
Such as the currently unstable `core::error`
2022-09-27 18:21:14 +00:00
bors
9aa85dc35b Auto merge of #9511 - rust-lang:box-default, r=Alexendoo
add `box-default` lint

This adds a `box-default` lint to suggest using `Box::default()` instead of `Box::new(Default::default())`, which offers less moving parts and potentially better performance according to [the perf book](https://nnethercote.github.io/perf-book/standard-library-types.html#box).

---

changelog: add [`box_default`] lint
2022-09-27 18:14:24 +00:00
bors
257fb4b458 Auto merge of #9543 - philipcraig:fix-saturing-typo, r=giraffate
fix typo "Saturing" -> "Saturating"

---

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

changelog: fix typo "Saturing" -> "Saturating"
2022-09-27 14:38:12 +00:00
bors
47c9145bd0 Auto merge of #9497 - kraktus:needless_return2, r=llogiq
[`needless_return`] Recursively remove unneeded semicolons

fix #8336,
fix #8156,
fix https://github.com/rust-lang/rust-clippy/issues/7358,
fix #9192,
fix https://github.com/rust-lang/rust-clippy/issues/9503

changelog: [`needless_return`] Recursively remove unneeded semicolons

For now the suggestion about removing the semicolons are hidden because they would be very noisy and should be obvious if the user wants to apply the lint manually instead of using `--fix`. This could be an issue for beginner, but haven't found better way to display it.
2022-09-27 14:23:53 +00:00
bors
d31db02e47 Auto merge of #9507 - c410-f3r:arith, r=Alexendoo
[arithmetic-side-effects] Consider references

Takes into consideration integer references like `&i32::MAX` because currently things like `let _ = &1 + 0` trigger the lint.

changelog: FP: [`arithmetic_side_effects`]: Now ignores references
  [9507](https://github.com/rust-lang/rust-clippy/pull/9507)
2022-09-27 14:09:25 +00:00
bors
c153bd6237 Auto merge of #9539 - Jarcho:ice_9445, r=flip1995
Don't lint `*_interior_mutable_const` on unions due to potential ICE.

fixes #9445
cc rust-lang/rust#101113

This started ICE'ing sometime last month due to stricter UB checks. I'm not sure how we could check the value of a union as MIRI doesn't seem to store which field is currently active.

changelog: Don't ICE on const unions containing a `!Freeze` type.
2022-09-27 12:58:41 +00:00
Andre Bogus
63f441ec85 add box-default lint 2022-09-27 13:26:23 +02:00
lcnr
e5ce6d18df rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00
Philip Craig
14abb8395c fix typo "Saturing" -> "Saturating" 2022-09-27 09:32:55 +01:00
bors
78dc616a7a Auto merge of #9487 - kraktus:question_mark, r=Jarcho
Silence [`question_mark`] in const context

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

When `const_try` is stabilised can be turned into a MSRV

changelog: Silence [`question_mark`] in const context
2022-09-27 01:12:54 +00:00
Pietro Albini
06568fd6c7 remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Yuri Astrakhan
5a71bbdf3f new uninlined_format_args lint to inline explicit arguments
Implement https://github.com/rust-lang/rust-clippy/issues/8368 - a new
lint to inline format arguments such as `print!("{}", var)` into
`print!("{var}")`.

code | suggestion | comment
---|---|---
`print!("{}", var)` | `print!("{var}")` |  simple variables
`print!("{0}", var)` | `print!("{var}")` |  positional variables
`print!("{v}", v=var)` | `print!("{var}")` |  named variables
`print!("{0} {0}", var)` | `print!("{var} {var}")` |  aliased variables
`print!("{0:1$}", var, width)` | `print!("{var:width$}")` |  width
support
`print!("{0:.1$}", var, prec)` | `print!("{var:.prec$}")` |  precision
support
`print!("{:.*}", prec, var)` | `print!("{var:.prec$}")` |  asterisk
support

code | suggestion | comment
---|---|---
`print!("{0}={1}", var, 1+2)` | `print!("{var}={0}", 1+2)` | Format
string uses an indexed argument that cannot be inlined.  Supporting this
case requires re-indexing of the format string.

changelog: [`uninlined_format_args`]: A new lint to inline format
arguments, i.e. `print!("{}", var)` into `print!("{var}")`
2022-09-25 19:53:03 -04:00
Jason Newcomb
b180d954d6 Don't lint *_interior_mutable_const on unions due to potential ICE. 2022-09-25 17:37:56 -04:00
bors
00ebd8eb48 Auto merge of #9535 - alex-semenyuk:move_derive_partial_eq_without_eq_to_nursery, r=xFrednet
Moved derive_partial_eq_without_eq to nursery

changelog: Moves: Move `derive_partial_eq_without_eq` to `nursery` (now allow-by-default)
  [#9536](https://github.com/rust-lang/rust-clippy/pull/9536)

Closes: https://github.com/rust-lang/rust-clippy/issues/9530
2022-09-25 10:38:02 +00:00
alex-semenyuk
93945a54a1 Please move derive_partial_eq_without_eq to nursery 2022-09-25 13:21:25 +03:00
Jason Newcomb
1141c553d8 Fix ICE in needless_pass_by_value with unsized dyn Fn 2022-09-24 17:38:09 -04:00
Takayuki Maeda
ea75178219 separate definitions and HIR owners
fix a ui test

use `into`

fix clippy ui test

fix a run-make-fulldeps test

implement `IntoQueryParam<DefId>` for `OwnerId`

use `OwnerId` for more queries

change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
2022-09-24 23:21:19 +09:00
Yuri Astrakhan
cc6b375cd3 fallout2: rework clippy_dev & _lints fmt inlining
* Inline format args where possible
* simplify a few complex macros into format str
* use formatdoc!() instead format!(indoc!(...))
2022-09-23 23:08:12 -04:00
Yuri Astrakhan
e67b2bf732 Apply uninlined_format-args to clippy_lints
This change is needed for the uninlined_format-args lint to be merged.
See https://github.com/rust-lang/rust-clippy/pull/9233
2022-09-23 13:42:59 -04:00
bors
ff65eec801 Auto merge of #9496 - yotamofek:never_loop_let_else, r=Jarcho
[`never_loop`]: Fix FP with let..else statements.

Fixes #9356

This has been bugging me for a while, so I thought I'd take a stab at it! I'm completely uncertain about the quality of my code, but I think it's an alright start, so opening this PR to get some feedback from more experienced clippy people :)

changelog: [`never_loop`]: Fix FP with let..else statements
2022-09-23 16:06:49 +00:00
bors
d9277c6aa8 Auto merge of #102056 - b-naber:unevaluated, r=lcnr
Introduce mir::Unevaluated

Previously the distinction between unevaluated constants in the type-system and in mir was not explicit and a little confusing. Probably better to introduce its own type for that.

r? `@lcnr`
2022-09-23 13:39:11 +00:00
b-naber
26861fbd7f rename Unevaluated to UnevaluatedConst 2022-09-23 14:27:34 +02:00
Alessandro Decina
49319b4206 uninit_vec: special case set_len(0)
set_len(0) does not create uninitialized elements. Fixes a false positive with
the following pattern:

    fn copy_slice_into_vec(dst: &mut Vec<u8>, src: &[u8]) {
        dst.reserve(src.len().saturating_sub(dst.len()));
        unsafe {
            dst.set_len(0);
            std::ptr::copy_nonoverlapping(src.as_ptr(), dst.as_mut_ptr(), src.len());
            dst.set_len(src.len());
        }
    }
2022-09-23 09:35:47 +01:00
Matthias Krüger
2063b8f137 Rollup merge of #102123 - schteve:clippy-note, r=Manishearth
Add note to clippy::non_expressive_names doc

Addresses confusion in rust-lang/rust-clippy#9514 by updating the lint docs.
2022-09-22 21:34:51 +02:00
kraktus
cda7547394 Make semicolon_span code more refactor-tolerant 2022-09-22 16:33:14 +02:00
kraktus
a390115c6f [nonstandard_macro_braces] Do not modify macro arguments
Also simplify the lint by not caring about code format which should be `rustfmt` job, and turn the lint into machine Applicable
2022-09-22 16:24:23 +02:00
bors
c2c170adbe Auto merge of #9501 - xFrednet:changelog-1.64, r=llogiq
Changelog for Rust 1.64 🍎

The normal release preparation dance. I've written the changelog like the version has already been released. The PR can be approved and then merged by anyone after the release of Rust 1.64 🙃

---

changelog: none
2022-09-22 12:10:53 +00:00
b-naber
adc7e3e679 introduce mir::Unevaluated 2022-09-22 12:35:28 +02:00
Steve Heindel
09b1e8ff34 Add note to clippy::non_expressive_names doc 2022-09-21 19:45:57 -04:00
Caio
4c5f23082a [arithmetic-side-effects] Consider references 2022-09-21 15:02:37 -03:00
David Koloski
4d015293d1 Merge commit '7248d06384c6a90de58c04c1f46be88821278d8b' into sync-from-clippy 2022-09-21 13:13:27 -04:00
bors
7248d06384 Auto merge of #9471 - jplatte:patch-1, r=xFrednet
Add matches! checking to nonstandard_macro_braces

changelog: Enhancement: [`nonstandard_macro_braces`]: Now includes `matches!()` in the default lint config
  [#9471](https://github.com/rust-lang/rust-clippy/pull/9471)
2022-09-21 12:56:19 +00:00
Michael Wright
a783d54207 Fix ICE in unnecessary_to_owned
Fixes #9504

Compiler generated call `into_iter` nodes return empty substs
which we need when checking it's predicates. Handle this by
simply exitting when we encounter one. This change introduces
false negatives in place of the ICEs.
2022-09-21 07:14:04 +02:00
xFrednet
e279f22a91
Changelog for Rust 1.64 🍎 2022-09-20 15:23:48 +02:00
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
Jonas Platte
25584c0c67
Add matches! checking to nonstandard_macro_braces 2022-09-19 14:16:59 +02:00
Yotam Ofek
d63aeceaa1 [never_loop]: Fix FP with let..else statements. 2022-09-19 10:57:29 +00:00
kraktus
5c0cb0deaa [needless_return] Recursively remove unneeded semicolons 2022-09-19 12:33:42 +02:00
lcnr
70f4c712c5 remove the Subst trait, always use EarlyBinder 2022-09-19 11:37:27 +02:00
kraktus
23d1d07861 small refactor 2022-09-19 07:43:16 +02:00
kraktus
15ec5d2608 further refactor 2022-09-18 21:26:23 +02:00
kraktus
bf8870eead further refactor of needless_return 2022-09-18 21:06:06 +02:00
kraktus
d1dbdcf332 refactor needless_return 2022-09-18 20:41:41 +02:00
kraktus
88a57963da [drop_copy]: Do not lint idiomatic in match arm 2022-09-17 15:37:38 +02:00
kraktus
3ca6b9d031 Silence [question_mark] in const context 2022-09-16 22:02:09 +02:00
Caio
b7bef4c8a4 Change method's name 2022-09-16 17:01:29 -03: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
est31
2be8b73328 Fix clippy 2022-09-15 21:21:18 +02:00
Caio
8bfe3db531 Typo 2022-09-15 13:40:49 -03:00
Caio
dba5adae6e [arithmetic-side-effects] Finish non-overflowing ops 2022-09-15 13:28:18 -03:00
bors
dcc6153919 Auto merge of #101811 - flip1995:clippyup, r=flip1995
Clippy pre beta branch fix

Before beta is branched on Friday, I want to move the `unused_peekable` lint  that was added in this release cycle (1.65) to `nursery`. This lint was already reported twice (https://github.com/rust-lang/rust-clippy/issues/9456, https://github.com/rust-lang/rust-clippy/issues/9462) in a short time, so it is probably a good idea to fix it before it hits beta and then stable.

r? `@Manishearth`
2022-09-15 08:53:51 +00:00
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
Philipp Krones
525e0c86bc Temporarily move clippy::unused_peekable to nursery 2022-09-14 20:13:30 +02:00
bors
f6a07d1d36 Auto merge of #101212 - eholk:dyn-star, r=compiler-errors
Initial implementation of dyn*

This PR adds extremely basic and incomplete support for [dyn*](https://smallcultfollowing.com/babysteps//blog/2022/03/29/dyn-can-we-make-dyn-sized/). The goal is to get something in tree behind a flag to make collaboration easier, and also to make sure the implementation so far is not unreasonable. This PR does quite a few things:

* Introduce `dyn_star` feature flag
* Adds parsing for `dyn* Trait` types
* Defines `dyn* Trait` as a sized type
* Adds support for explicit casts, like `42usize as dyn* Debug`
  * Including const evaluation of such casts
* Adds codegen for drop glue so things are cleaned up properly when a `dyn* Trait` object goes out of scope
* Adds codegen for method calls, at least for methods that take `&self`

Quite a bit is still missing, but this gives us a starting point. Note that this is never intended to become stable surface syntax for Rust, but rather `dyn*` is planned to be used as an implementation detail for async functions in dyn traits.

Joint work with `@nikomatsakis` and `@compiler-errors.`

r? `@bjorn3`
2022-09-14 18:10:51 +00: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
cf043f6a16 Auto merge of #101709 - nnethercote:simplify-visitors-more, r=cjgillot
Simplify visitors more

A successor to #100392.

r? `@cjgillot`
2022-09-14 05:21:14 +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
Eric Holk
27e91b65d5 Address code review comments 2022-09-13 14:50:12 -07: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
985afe07f7 Auto merge of #100640 - reitermarkus:socket-display-buffer, r=thomcc
Use `DisplayBuffer` for socket addresses.

Continuation of https://github.com/rust-lang/rust/pull/100625 for socket addresses.

Renames `net::addr` to `net::addr::socket`, `net::ip` to `net::addr::ip` and `net::ip::display_buffer::IpDisplayBuffer` to `net::addr::display_buffer::DisplayBuffer`.
2022-09-13 06:41:37 +00:00
Eric Holk
b95b285ef4 Make x.py check work 2022-09-12 17:29:11 -07:00
Markus Reiter
64a42db51a Simplify clippy fix. 2022-09-12 19:46:51 +02:00
Markus Reiter
c0e249ce67 Fix clippy. 2022-09-12 19:04:17 +02:00
bors
4e313a50b2 Auto merge of #99334 - NiklasJonsson:84447/error-privacy, r=oli-obk
rustc_error, rustc_private: Switch to stable hash containers

Relates https://github.com/rust-lang/rust/issues/84447
2022-09-12 15:57:37 +00:00
Nicholas Nethercote
0d1469ad34 Remove unused argument from visit_poly_trait_ref. 2022-09-12 13:51:10 +10:00
Nicholas Nethercote
f6005c6b89 Remove unused span argument from walk_fn. 2022-09-12 13:24:27 +10:00
S. van Dijk
178f502970
Stop lint from checking code expanded from macros. 2022-09-11 20:15:35 +02: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
bors
42361da5d9 Auto merge of #98559 - jackh726:remove-reempty, r=oli-obk
Remove ReEmpty

r? rust-lang/types
2022-09-10 20:54:01 +00:00
kraktus
d50f366612 Do not expand macro in nonminimal_bool suggestions 2022-09-10 19:48:14 +02:00
Niklas Jonsson
41b3084391 rustc_error, rustc_private, rustc_ast: Switch to stable hash containers 2022-09-10 11:49:12 +02:00
kraktus
59ee6a89a3 Remove duplicate context check 2022-09-10 11:47:07 +02:00
kraktus
c433d542cf Do not lint use_self in proc macro expansion 2022-09-10 11:42:37 +02:00
kraktus
0958f9486b Add manual_filter lint for Option
Share much of its implementation with `manual_map` and should greatly benefit from its previous feedback.
2022-09-10 10:41:55 +02:00
kraktus
bdb13cd887 refactor: move has_debug_impl to clippy_utils::ty 2022-09-10 10:39:51 +02:00
kraktus
cd69d86c89 assertions_on_result_states fix suggestion when assert! not in a statement 2022-09-10 10:30:19 +02:00
Philipp Krones
98bf99e2f8 Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup 2022-09-09 13:36:26 +02:00
Michael Goulet
854f751b26 Appease clippy again 2022-09-09 01:31:46 +00:00
Michael Goulet
ac1c68a5e6 Make clippy happy 2022-09-09 01:31:45 +00:00
Jack Huey
b640eaa71d Remove ReEmpty 2022-09-08 20:55:55 -04: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
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
bors
f47a1e24c7 Auto merge of #101577 - Dylan-DPC:rollup-l9xw7i7, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #98933 (Opaque types' generic params do not imply anything about their hidden type's lifetimes)
 - #101041 (translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2)
 - #101424 (Adjust and slightly generalize operator error suggestion)
 - #101496 (Allow lower_lifetime_binder receive a closure)
 - #101501 (Allow lint passes to be bound by `TyCtxt`)
 - #101515 (Recover from typo where == is used in place of =)
 - #101545 (Remove unnecessary `PartialOrd` and `Ord`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-08 15:53:14 +00:00
Dylan DPC
9faa588446 Rollup merge of #101501 - Jarcho:tcx_lint_passes, r=davidtwco
Allow lint passes to be bound by `TyCtxt`

This will allow storing things like `Ty<'tcx>` inside late lint passes. It's already possible to store various id types so they're already implicitly bound to a specific `TyCtxt`.

r? rust-lang/compiler
2022-09-08 20:48:36 +05:30
Caio
51d8b6c664 Rename the arithmetic lint 2022-09-08 12:04:55 -03:00
bors
30a5815505 Auto merge of #101467 - nnethercote:shrink-hir-Ty-Pat, r=spastorino
Shrink `hir::Ty` and `hir::Pat`

r? `@ghost`
2022-09-08 13:11:57 +00:00
Dylan DPC
c3db185c52 Rollup merge of #101498 - petrochenkov:visparam, r=cjgillot
rustc: Parameterize `ty::Visibility` over used ID

It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility<DefIndex>` into metadata.
2022-09-08 11:55:09 +05:30
Nicholas Nethercote
c86a9c077c Introduce DotDotPos.
This shrinks `hir::Pat` from 88 to 72 bytes.
2022-09-08 15:25:50 +10: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
bors
567e1bbca7 Auto merge of #101432 - nnethercote:shrink-PredicateS, r=lcnr
Shrink `PredicateS`

r? `@ghost`
2022-09-07 13:49:58 +00:00
Caio
0d078c9fd6 [Arithmetic] Consider literals 2022-09-07 10:00:45 -03:00
Vadim Petrochenkov
9136096629 rustc: Parameterize ty::Visibility over used ID
It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility<DefIndex>` into metadata.
2022-09-07 13:35:41 +04: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
Jason Newcomb
abd3e7eabb Allow lint passes to be bound by TyCtxt 2022-09-06 14:23:03 -04: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
bors
2ccf843471 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`
2022-09-05 16:21:40 +00:00
Takayuki Maeda
8931da40e3 use propagate_through_exprs instead of propagate_through_expr
fix `ExprKind` static_assert_size

fix hir-stats
2022-09-05 23:11:34 +09:00
bors
5ea99770d8 Auto merge of #101228 - nnethercote:simplify-hir-PathSegment, r=petrochenkov
Simplify `hir::PathSegment`

r? `@petrochenkov`
2022-09-05 13:36:54 +00:00
Takayuki Maeda
097ef517fe refactor: remove unnecessary variables 2022-09-05 22:31:02 +09:00
Takayuki Maeda
4bcaddeeb2 separate the receiver from arguments in HIR under /clippy 2022-09-05 22:25:57 +09:00
Dylan DPC
9ae329232b 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`
2022-09-05 14:15:51 +05:30
Nicholas Nethercote
2d4349c22d Pack Term in the same way as GenericArg.
This shrinks the `PredicateS` type, which is instanted frequently.
2022-09-05 15:08:52 +10:00
Nicholas Nethercote
25f6f18834 Make hir::PathSegment::res non-optional. 2022-09-05 14:20:25 +10: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
bors
90804d35fe 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
2022-09-04 15:32:09 +00:00
kraktus
2cc20e3245 fix wording for derivable_impls 2022-09-04 17:20:54 +02: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
Cameron Steffen
e5f30f4dfa clippy: BindingAnnotation change 2022-09-02 13:03:11 -05:00
Jason Newcomb
bd70ccf915 Don't use hir_ty_to_ty in result_large_err as it sometimes leaves late-bound lifetimes. 2022-09-02 13:40:35 -04:00
Dmitrii Lavrov
b1f86a49ea
New lint bool_to_int_with_if 2022-09-01 23:23:56 +02:00
bors
a80e278036 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
2022-09-01 13:18:17 +00:00
Lukas Lueg
6e14e60af4 Fix {subopt,imprec}_float not lint const.*(const)
Fixes #9402
Fixes #9201
2022-09-01 12:51:13 +02:00
Jason Newcomb
d4a0785464 Correctly handle unescape warnings 2022-09-01 00:00:37 -04:00
Jason Newcomb
7bd5b012c7 Use CountIsStart in clippy 2022-08-31 09:45:51 -04:00
Jason Newcomb
fb41bfa774 Merge commit 'f51aade56f93175dde89177a92e3669ebd8e7592' into clippyup 2022-08-31 09:24:45 -04:00
Tim Siegel
28a055dcea
match_wild_err_arm: Fix typo in note text 2022-08-31 09:09:11 -04:00
bors
f51aade56f 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
2022-08-31 08:07:33 +00:00
Lukas Lueg
66a97055b2 Initial implementation of result_large_err 2022-08-30 17:39:40 +02:00
Jason Newcomb
19ef04ff5d 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
2022-08-30 00:33:56 -04:00
bors
4df6032100 Auto merge of #9394 - lukaslueg:issue9391, r=Jarcho
Fix missing parens in `suboptimal_flops` suggestion

Fixes #9391. The problem is simple enough, I didn't check if the same problem occurs elsewhere, though.

changelog: fix missing parenthesis in `suboptimal_flops` suggestion
2022-08-30 00:37:45 +00:00
Lukas Lueg
9ffc5a5c8d Fix more parens for suboptimal_flops suggs 2022-08-29 22:36:11 +02:00
Nilstrieb
ce847beb47 Revert let_chains stabilization
This reverts commit 3266460749.

This is the revert against master, the beta revert was already done in #100538.
2022-08-29 19:34:11 +02:00
clubby789
cc9f203543
Update clippy_lints/src/casts/mod.rs
Co-authored-by: Alex Macleod <alex@macleod.io>
2022-08-29 15:17:23 +01:00
clubby789
30979bfe83 Add lint cast_slice_from_raw_parts 2022-08-29 14:10:17 +01:00
Lukas Lueg
26a6891925 Fix missing parens in suboptimal_flops sugg
Fixes #9391
2022-08-29 13:56:03 +02:00
bors
58bbb1a95d Auto merge of #9385 - rust-lang:unnecessary-cast-remove-parens, r=Alexendoo
remove parenthesis from `unnecessary_cast` suggestion

This fixes #9380.

---

changelog: none
2022-08-29 11:49:08 +00:00
bors
28ec27b33a Auto merge of #9388 - Jarcho:rustup, r=Jarcho
Rustup

Hopefully this is done right.

changelog: None
2022-08-29 01:51:23 +00:00
Nicholas Nethercote
3ce109e12d Use &'hir Ty everywhere.
For consistency, and because it makes HIR measurement simpler and more
accurate.
2022-08-29 06:35:14 +10:00