Commit Graph

8380 Commits

Author SHA1 Message Date
Elliot Bobrow
7747032b77 suboptimal_flops lint for multiply and subtract 2022-10-02 21:00:51 -07:00
TennyZhuang
bf18768219 let upper_case_acronyms check the enum name
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-03 10:11:57 +08:00
Jason Newcomb
38236a7135 Use for_each_expr in place of some visitors 2022-10-02 17:15:19 -04:00
Jason Newcomb
649d443646 Replace expr_visitor with for_each_expr 2022-10-02 17:04:22 -04:00
bors
bef93d3b14 Auto merge of #7962 - Jarcho:fix_match_type_on_diagnostic_items, r=llogiq
Fix and improve `match_type_on_diagnostic_item`

This extracts the fix for the lint out of #7647. There's still a couple of other functions to check, but at least this will get lint working again.

The two added util functions (`is_diagnostic_item` and `is_lang_item`) are needed to handle `DefId` for unit and tuple struct/variant constructors. The `rustc_diagnostic_item` and `lang` attributes are attached to the struct/variant `DefId`, but most of the time they are used through their constructors which have a different `DefId`. The two utility functions will check if the `DefId` is for a constructor and switch to the associated struct/variant `DefId`.

There does seem to be a bug on rustc's side where constructor `DefId`s from external crates seem to be returning `DefKind::Variant` instead of `DefKind::Ctor()`. There's a workaround put in right.

changelog: None
2022-10-02 19:46:46 +00:00
bors
0341198ba1 Auto merge of #9574 - Alexendoo:unused-fixed, r=Jarcho
Remove unused `.fixed` files, only run asm_syntax doctests on x86

Two small changes, removes some unused `.fixed` and makes `clippy_lints` doctests pass on non x86 arches

changelog: none
2022-10-02 19:06:58 +00:00
Jason Newcomb
162aa19793 Fix and improve internal lint checking for match_type usages
* Check for `const`s and `static`s from external crates
* Check for `LangItem`s
* Handle inherent functions which have the same name as a field
* Also check the following functions:
    * `match_trait_method`
    * `match_def_path`
    * `is_expr_path_def_path`
    * `is_qpath_def_path`
* Handle checking for a constructor to a diagnostic item or `LangItem`
2022-10-02 15:02:55 -04:00
Jason Newcomb
8e7af6b429 Replace is_lang_ctor with is_res_lang_ctor 2022-10-02 14:50:37 -04:00
kraktus
830fdf2b56 update rust version introduction 2022-10-02 17:45:44 +02:00
kraktus
b89ac0cefc refactor manual_filter
Move common functions to `manual_utils.rs`, better arm matching, use clippy utils `contains_unsafe_block`
2022-10-03 14:13:15 +02:00
bors
f8ba19287d Auto merge of #9576 - TennyZhuang:unnecessary_cast_for_non_literal_expr, r=llogiq
let unnecessary_cast work for trivial non_literal expressions

Signed-off-by: TennyZhuang <zty0826@gmail.com>

---

changelog: [`unnecessary_cast`]: fix for trivial non_literal expressions

Fixes #9562
2022-10-02 15:26:45 +00:00
bors
11a6d19c59 Auto merge of #9479 - kraktus:manual_assert2, r=llogiq
[`manual_assert`]: Preserve comments in the suggestion

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

changelog: [`manual_assert`]: Preserve comments in the suggestion
2022-10-02 15:13:32 +00:00
TennyZhuang
c9b93143d5 fix some logics
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-02 23:02:13 +08:00
TennyZhuang
bff811bfdf extract common codes
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-02 23:02:13 +08:00
TennyZhuang
081f73954b let unnecessary_cast work for trivial non_literal expressions
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-02 23:02:11 +08:00
bors
ac12011315 Auto merge of #9577 - kraktus:unnecessary_cast, r=llogiq
[`unnecessary_cast`] add parenthesis when negative number uses a method

fix #9563

The issue was probably introduced by 90fe3bea52

changelog: [`unnecessary_cast`] add parenthesis when negative number uses a method

r? llogiq
2022-10-02 14:18:41 +00:00
bors
d6d5ecd625 Auto merge of #9571 - rust-lang:refactor-lit-ints, r=Jarcho
use `is_integer_literal` more

I noticed that we have the `is_integer_literal` function in our `clippy_utils`, yet almost everywhere people still match int literal expressions manually. So I searched for instances to replace and shorten the code a bit.

---

changelog: none
2022-10-02 13:11:21 +00:00
kraktus
22be60b4f0 fix indentation 2022-10-02 15:03:48 +02:00
kraktus
a35734c172 revert manual_assert suggestion refactor
Because `Sugg` helper does not simplify multiple negations
2022-10-02 15:03:48 +02:00
kraktus
2c04c1a188 [manual_assert]: Preserve comments in the suggestion 2022-10-02 15:03:48 +02:00
kraktus
90b446fd38 [unnecessary_cast] add parenthesis when negative number uses a method 2022-10-02 14:35:38 +02:00
Alex Macleod
52a68dc097 lint nested patterns and slice patterns in needless_borrowed_reference 2022-10-01 22:31:10 +00:00
Alex Macleod
a834ac9800 Only run x86 asm doctests on x86 2022-10-01 22:27:38 +00:00
bors
64243c6f99 Auto merge of #9484 - Xaeroxe:clamping-without-clamp, r=Alexendoo
Implement `manual_clamp` lint

Fixes #9477
Fixes #6751

Identifies common patterns where usage of the `clamp` function would be more succinct and clear, and suggests using the `clamp` function instead.

changelog: [`manual_clamp`]: Implement manual_clamp lint
2022-10-01 20:55:20 +00:00
Jacob Kiesel
b221184572 Implement manual_clamp lint 2022-10-01 13:58:41 -06:00
Nilstrieb
2b944d0c38
Fix example 2022-10-01 20:48:52 +02:00
Nilstrieb
169ef781f9
Improve wording 2022-10-01 20:12:51 +02:00
Nilstrieb
b91dc03510
Add as_ptr_cast_mut lint
This lint detects calls to a `&self`-taking `as_ptr` method, where
the result is then immediately cast to a `*mut T`. Code like this
is probably invalid, as that pointer will not have write permissions,
and `*mut T` is usually used to write through.
2022-10-01 19:23:53 +02:00
Andre Bogus
eef5d477b5 use is_integer_literal more 2022-10-01 17:55:22 +02:00
Andre Bogus
3757a0e903 avoid doc-link-with-quotes in code blocks 2022-10-01 15:25:37 +02:00
bors
9e8f53d09a Auto merge of #101986 - WaffleLapkin:move_lint_note_to_the_bottom, r=estebank
Move lint level source explanation to the bottom

So, uhhhhh

r? `@estebank`

## User-facing change

"note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic:
```diff
-   = note: `#[warn(unsupported_calling_conventions)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
+   = note: `#[warn(unsupported_calling_conventions)]` on by default
```

Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO.

## Developer-facing change

`struct_span_lint` and similar methods have a different signature.

Before: `..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)`
After: `..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>`

The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion.

Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere.

## Subtle problem

By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings...

I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate.

## P.S.

I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
2022-10-01 10:44:25 +00:00
Maybe Waffle
0867c64a54 clippy: adopt to the new lint API 2022-10-01 10:03:06 +00:00
Caio
4876882b29 Fix #9544 2022-09-30 15:30:40 -03:00
bors
a78551bb14 Auto merge of #9556 - evantypanski:et/issue-9369, r=Alexendoo
[`redundant_closure`] Fix suggestion causes error for `impl FnMut`

Fixes #9369

changelog: [`redundant_closure`] Fix suggestion causes error with `impl FnMut` types
2022-09-30 16:42:55 +00:00
Evan Typanski
85b8ff7f38
Fix style in if let chain
Co-authored-by: Alex Macleod <alex@macleod.io>
2022-09-30 11:36:55 -04:00
Evan Typanski
416da1264c [redundant_closure] Add &mut to more cases 2022-09-29 19:35:04 -04:00
kraktus
6ec7759c3b [unnecessary_lazy_eval] Do not lint in external macros 2022-09-29 13:48:50 +02:00
bors
e43f5a17d4 Auto merge of #9516 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2022-09-29 10:04:13 +00:00
Philipp Krones
67af127f24
Fix dogfood 2022-09-29 12:02:58 +02:00
Nicholas Nethercote
8b59fe4981 Shrink hir::def::Res.
`Res::SelfTy` currently has two `Option`s. When the second one is `Some`
the first one is never consulted. So we can split it into two variants,
`Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res`
from 24 bytes to 12. This then shrinks `hir::Path` and
`hir::PathSegment`, which are the HIR types that take up the most space.
2022-09-29 08:44:52 +10:00
bors
ed9c0e3030 Auto merge of #9550 - alex-semenyuk:fix_typo, r=xFrednet
Fix typo

changelog: none
2022-09-28 21:44:52 +00:00
alex-semenyuk
8ba081c597 Fix typo 2022-09-28 23:01:11 +03:00
bors
8845f82142 Auto merge of #9490 - kraktus:needless_borrow, r=Jarcho
fix [`needless_borrow`], [`explicit_auto_deref`] FPs on unions

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

changelog: fix [`needless_borrow`] false positive on unions
changelog: fix [`explicit_auto_deref`] false positive on unions

Left a couple debug derived impls on purpose I needed to debug as I don't think it's noise
2022-09-28 14:58:07 +00:00
Philipp Krones
458e83291d
Bump Clippy version -> 0.1.66 2022-09-28 14:27:50 +02:00
Philipp Krones
bbcde66685
Merge remote-tracking branch 'upstream/master' into rustup 2022-09-28 14:27:32 +02:00
bors
0f6932a1f7 Auto merge of #9546 - kraktus:default_not_default_trait, r=xFrednet
[`should_implement_trait`] Also lint `default` method

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

changelog: FP: [`should_implement_trait`]: Now also works for `default` methods
2022-09-28 11:00:37 +00:00
kraktus
7289835542 [should_implement_trait] Also lint default method 2022-09-28 08:42:01 +02:00
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