Commit Graph

7606 Commits

Author SHA1 Message Date
bors
3e771624e1 Auto merge of #8951 - mikerite:needless-late-init-20220605, r=giraffate
Some refactoring in `needless_late_init`

changelog: none
2022-06-06 00:25:14 +00:00
bors
3e52dee646 Auto merge of #8941 - DevAccentor:for_loops_over_fallibles, r=llogiq
improve [`for_loops_over_fallibles`] to detect the usage of iter, iter_mut and into_iterator

fix #6762

detects code like
```rust
for _ in option.iter() {
    //..
}
```

changelog: Improve [`for_loops_over_fallibles`] to detect `for _ in option.iter() {}` or using `iter_mut()` or `into_iterator()`.
2022-06-05 11:16:37 +00:00
Michael Wright
a2de34720d needless_late_init refactoring
Remove the unneeded wrapping and unwrapping in suggestion creation.
Collecting to Option<Vec<_>> only returns None if one of the elements is
None and that is never the case here.
2022-06-05 07:30:59 +02:00
Michael Wright
2a1a80d80c needless_late_init refactoring
Simplify the creation of suggestions by using `flat_map` instead of
`chain`. Note that the order of the suggestions is not important.
2022-06-05 07:30:59 +02:00
Michael Wright
94e321a6ff needless_late_init refactoring
Remove duplication in creating suggestions by first mapping assignments
to spans and then suggestions.
2022-06-05 07:30:59 +02:00
bors
542d474d38 Auto merge of #8930 - kyoto7250:issue_8920, r=Alexendoo
fix(manual_find_map and manual_filter_map): check clone method

close #8920

Added conditional branching when the clone method is used.

Thank you in advance.

---

changelog: check `clone()` and other variant preserving methods in [`manual_find_map`] and [`manual_filter_map`]
2022-06-04 13:05:27 +00:00
kyoto7250
42cf98553a refactor: check copied and cloned 2022-06-04 21:28:14 +09:00
Philipp Krones
7f402b15c7
Merge remote-tracking branch 'upstream/master' into rustup 2022-06-04 12:53:27 +02:00
bors
8ef490871c Auto merge of #8843 - Serial-ATA:collect-renamed, r=xFrednet
Collect renamed lints

changelog: Display past names of renamed lints on Clippy's lint list

cc #7172

r? `@xFrednet`
2022-06-04 09:49:27 +00:00
DevAccentor
5a49918f36 improve for_loops_over_fallibles to detect the usage of iter, iter_mut and into_iterator 2022-06-04 11:11:00 +02:00
kyoto7250
990f8bf5a6 refactor: Add some methods 2022-06-04 17:15:55 +09:00
bors
b1a3e7e9c8 Auto merge of #8937 - Jarcho:merge_match_passes, r=llogiq
Merge various passes into `Matches`

changelog: None
2022-06-04 07:41:27 +00:00
Jason Newcomb
68c411ff94 Move ManualMap into Matches lint pass 2022-06-03 19:09:50 -04:00
Jason Newcomb
67cb5ec29f Move TryErr into Matches lint pass 2022-06-03 19:09:49 -04:00
Jason Newcomb
dbc7753fb2 Merge SignificantDropInScrutinee into Matches lint pass 2022-06-03 19:09:49 -04:00
Jason Newcomb
8c8a52eeeb Move MatchStrCaseMismatch into Matches lint pass 2022-06-03 19:09:49 -04:00
Jason Newcomb
3d8d734150 Move MatchOnVecItems into Matches lint pass 2022-06-03 19:09:49 -04:00
Jason Newcomb
b337f9e62e Merge ManualUnwrapOr into Matches lint pass 2022-06-03 19:09:49 -04:00
Jason Newcomb
81e44502ac Merge CollapsibleMatch into Matches lint pass 2022-06-03 12:14:24 -04:00
DevAccentor
64fe4e32db add as_underscore lint 2022-06-03 18:11:23 +02:00
Camille GILLOT
1e86cc5194 Manipulate lifetimes by LocalDefId for region resolution. 2022-06-03 12:03:20 +02:00
Ariel Uy
58cd01c2fc Add new lint mismatching_type_param_order
Add new lint for checking if type parameters are consistent between type
definitions and impl blocks.
2022-06-03 00:04:55 -07:00
bors
1194c6369e Auto merge of #8932 - dswij:pr-8879, r=giraffate
`needless_return` checks for macro expr in return stmts

closes #8879

Macro expressions in returns were not checked by `needless_return`. The test added in [this commit](6396a7a425 (diff-a869168cfafb7e6e5010feb76a16389d6c96d59e98113dee5c2b304a5160e43aR51-R55)) seems to have regressed.

changelog: [`needless_return`] checks for macro exprs in return statements
2022-06-03 00:00:23 +00:00
bors
97e5449a70 Auto merge of #8902 - PrestonFrom:add_suggestion_for_move_and_clone_when_not_ref, r=flip1995
When setting suggestion for significant_drop_in_scrutinee, add suggestion for MoveAndClone for non-ref

When trying to set the current suggestion, if the type of the expression
is not a reference and it is not trivially pure clone copy, we should still
trigger and emit a lint message. Since this fix may require cloning an
expensive-to-clone type, do not attempt to offer a suggested fix.

This change means that matches generated from TryDesugar and AwaitDesugar
would normally trigger a lint, but they are out of scope for this lint,
so we will explicitly ignore matches with sources of TryDesugar or
AwaitDesugar.

changelog: Update for ``[`significant_drop_in_scrutinee`]`` to correctly
emit lint messages for cases where the type is not a reference *and*
not trivially pure clone copy.
changelog: [`significant_drop_in_scrutinee`]: No longer lint on Try `?`
and `await` desugared expressions.
2022-06-02 17:16:43 +00:00
bors
e32b66c871 Auto merge of #8906 - rust-lang:copy-large-enum-variants, r=Jarcho
remove `large_enum_variant` suggestion for `Copy` types

Replaces the (erroneous) suggestion on `large_enum_variant` for `Copy` types by a note. This fixes #8894.

---

changelog: none
2022-06-02 16:37:09 +00:00
dswij
678dcdd2be Apply needless_return suggestions 2022-06-02 20:22:15 +08:00
dswij
b885035ef7 needless_return checks for macro expr in return stmts 2022-06-02 20:22:15 +08:00
bors
9428e2e25e Auto merge of #8905 - c410-f3r:arith, r=llogiq
[1/N] Implement Arithmetic lint

Assuming that https://github.com/rust-lang/rust-clippy/issues/8903 is OK, this PR starts the creation of the `Arithmetic` lint with configurable types.

My current struggle to get a rustc review inspired me to create smaller PRs in order to easy review and make merges as fast as possible. So the first step here only moves the `arithmetic.rs` file to `numeric_arithmetic.rs` to make room for the new lint.

--
changelog: none
2022-06-02 12:05:27 +00:00
Andre Bogus
756caf79e6 account for generics 2022-06-02 12:45:15 +02:00
Preston From
bc5a8e9537 Lint message correctly identifies match vs for loop 2022-06-02 02:38:57 -06:00
bors
0d5ace3ed2 Auto merge of #8908 - Serial-ATA:doc-comment-issues, r=xFrednet
Make docs more consistent

changelog: none

This just fixes some docs to make them more consistent. I mostly just changed `// Good`, `// Bad`, etc to `Use instead:`.
2022-06-02 07:38:01 +00:00
kyoto7250
007fae10ed fix(manual_find_map and manual_filter_map): check clone method 2022-06-02 09:54:14 +09:00
Serial
b20f95c1a1 Combine doc examples 2022-06-01 18:53:15 -04:00
bors
7572b6b757 Auto merge of #8869 - Jarcho:derive_partial_eq_without_eq, r=flip1995
Set correct `ParamEnv` for `derive_partial_eq_without_eq`

fixes #8867

changelog: Handle differing predicates applied by `#[derive(PartialEq)]` and `#[derive(Eq)]` in `derive_partial_eq_without_eq`
2022-06-01 19:27:54 +00:00
bors
c4c413b6fc Auto merge of #7930 - lengyijun:needless_deref_new, r=Jarcho
new lint: `borrow_deref_ref`

changelog: ``[`borrow_deref_ref`]``

Related pr: #6837 #7577
`@Jarcho` Could you please give a review?

`cargo lintcheck` gives no false negative (but tested crates are out-of-date).

TODO:
1. Not sure the name. `deref_on_immutable_ref` or some others?
2022-06-01 16:43:14 +00:00
Nicholas Nethercote
11d22ae7c5 Lazify SourceFile::lines.
`SourceFile::lines` is a big part of metadata. It's stored in a compressed form
(a difference list) to save disk space. Decoding it is a big fraction of
compile time for very small crates/programs.

This commit introduces a new type `SourceFileLines` which has a `Lines`
form and a `Diffs` form. The latter is used when the metadata is first
read, and it is only decoded into the `Lines` form when line data is
actually needed. This avoids the decoding cost for many files,
especially in `std`. It's a performance win of up to 15% for tiny
crates/programs where metadata decoding is a high part of compilation
costs.

A `Lock` is needed because the methods that access lines data (which can
trigger decoding) take `&self` rather than `&mut self`. To allow for this,
`SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather
than returning the lines slice.
2022-06-01 10:36:39 +10:00
Jason Newcomb
ca78e2428e Add lint swap_ptr_to_ref 2022-05-31 13:08:05 -04:00
bors
5b1a4c0d76 Auto merge of #8884 - evantypanski:manual_range_contains_multiple, r=Manishearth
Fix `manual_range_contains` false negative with chains of `&&` and `||`

Fixes #8745

Since the precedence for `&&` is the same as itself the HIR for a chain of `&&` ends up with a right skewed tree like:

```
     &&
    /  \
  &&   c2
 /  \
... c1
```

So only the leftmost `&&` was actually "fully" checked, the top level was just `c2` and `&&` so the `manual_range_contains` lint won't apply. This change makes it also check `c2` with `c1`.

There's a bit of a hacky solution in the [second commit](257f09776a) to check if the number of open/closing parens in the snippet match. This is to prevent a case like `((x % 2 == 0) || (x < 0)) || (x >= 10)` from offering a suggestion like `((x % 2 == 0) || !(0..10).contains(&x)` which now won't compile.

Any suggestions for that paren hack welcome, kinda new to working on this so not too sure about possible solutions :) it's weird because I don't know how else to check for parens in HIR considering they're removed when lowering AST.

changelog: Fix [`manual_range_contains`] false negative with chains of `&&` and `||`
2022-05-31 16:17:12 +00:00
bors
7000e758c1 Auto merge of #8564 - Jarcho:transmute_erase_regions, r=Alexendoo
Don't lint `useless_transmute` on types with erased regions

fixes #6356
fixes #3340
fixes #2906

This should get a proper fix at some point, but this at least gets the lint running on some types.

cc #5343

changelog: Don't lint `useless_transmute` on types with erased regions
2022-05-31 15:57:27 +00:00
bors
9add456618 Auto merge of #8876 - Alexendoo:cast-abs-to-different-uint, r=dswij,xFrednet
`cast_abs_to_unsigned`: do not remove cast if it's required

Fixes #8873

If `iX` is not cast to `uX` then keep the cast rather than removing it

changelog: [`cast_abs_to_unsigned`]: do not remove cast if it's required
2022-05-31 15:40:03 +00:00
Jason Newcomb
0c6ebf1c6a Move useless_transmute back to complexity 2022-05-31 10:40:40 -04:00
Jason Newcomb
9c9cca3e66 Don't lint useless_transmute on types with erased regions 2022-05-31 10:39:53 -04:00
bors
2466a0507c Auto merge of #8918 - Jarcho:almost_complete_letter_range, r=llogiq
Add lint `almost_complete_letter_range`

fixes #7269

changelog: Add lint `almost_complete_letter_range`
2022-05-31 05:10:42 +00:00
Jason Newcomb
eb2908b4ea Add lint almost_complete_letter_range 2022-05-30 23:20:04 -04:00
bors
e1607e9d31 Auto merge of #8912 - Alexendoo:needless-late-init-ice, r=giraffate
needless_late_init: fix ICE when all branches return the never type

Fixes #8911

When the assignment is done in a match guard or the if condition and all of the branches return the never type `assignment_suggestions` would return an empty `Vec` which caused the ICE. It now returns `None` in that scenario

Also moves some tests to the top of the file

changelog: ICE Fixes: [`needless_late_init`] #8911
2022-05-31 00:46:52 +00:00
bors
588e1982d3 Auto merge of #8913 - InfRandomness:ICE-#8748, r=giraffate
Fix #8748

Thank you for making Clippy better!

changelog: Fix ICE #8748 in shadow.rs
2022-05-31 00:17:52 +00:00
bors
d9f497830c Auto merge of #8899 - botahamec:use-self-tuple-struct-variants, r=Alexendoo
Fix `[use_self]` false negative with on struct and tuple struct patterns

fixes #8845

changelog: Triggered the warning for ``[`use_self`]`` on `TupleStruct` and `Struct` patterns, whereas currently it's only triggered for `Path` patterns
2022-05-30 22:05:13 +00:00
InfRandomness
0a7f19b547 Fix #8748 2022-05-30 22:46:31 +02:00
Micha White
2aa4569303
Triggered the lint on tuple struct and struct patterns 2022-05-30 13:39:18 -04:00
lyj
c5410150eb needless_deref 2022-05-30 01:46:15 +00:00