Commit graph

2352 commits

Author SHA1 Message Date
Dmitry Murzin
a427c99f3d
Handle mapping to Option in map_flatten lint 2020-07-30 23:23:33 +03:00
bors
2e0f8b6cc6 Auto merge of #5843 - dima74:iter_skip_next.add-suggestion, r=phansch
Add suggestion for `iter_skip_next` lint

changelog: Add suggestion for [`iter_skip_next`](https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next) lint
2020-07-29 06:10:55 +00:00
bors
f5d429cd76 Auto merge of #5820 - ThibsG:FixSuspiciousArithmeticImpl, r=flip1995
Fix FP for `suspicious_arithmetic_impl` from `suspicious_trait_impl` …

As discussed in #3215, the `suspicious_trait_impl` lint causes too many false positives, as it is complex to find out if binary operations are suspicious or not.

This PR restricts the number of binary operations to at most one, otherwise we don't lint.
This can be seen as very conservative, but at least FP can be reduced to bare minimum.

Fixes: #3215

changelog: limit the `suspicious_arithmetic_impl` lint to one binop, to avoid many FPs
2020-07-26 19:48:17 +00:00
Takayuki Nakata
c81bbd05b9 Fix FP useless_conversion
Fix #5833.
2020-07-25 23:58:22 +09:00
Dmitry Murzin
b375f1dd20
Add suggestion for iter_skip_next lint 2020-07-25 17:11:55 +03:00
bors
61e3d8a55c Auto merge of #5824 - tmiasko:manually-drop-clone, r=Manishearth
Ignore not really redundant clones of ManuallyDrop

"Redundant" clones of `ManuallyDrop` are sometimes used for the side effect of
invoking the clone, without running the drop implementation of the inner type.
In other words, they aren't really redundant. For example, futures-rs crate:

```rust
#[allow(clippy::redundant_clone)] // The clone here isn't actually redundant.
unsafe fn increase_refcount<T: ArcWake>(data: *const ()) {
    // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
    let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T));
    // Now increase refcount, but don't drop new refcount either
    let _arc_clone: mem::ManuallyDrop<_> = arc.clone();
}
```

changelog: Ignore redundant clone lint for ManuallyDrop.
2020-07-20 01:36:21 +00:00
Tomasz Miąsko
a5cdd4aeb1 Ignore not really redundant clones of ManuallyDrop
"Redundant" clones of `ManuallyDrop` are sometimes used for the side effect of
invoking the clone, without running the drop implementation of the inner type.
In other words, they aren't really redundant. For example, futures-rs crate:

```rust
#[allow(clippy::redundant_clone)] // The clone here isn't actually redundant.
unsafe fn increase_refcount<T: ArcWake>(data: *const ()) {
    // Retain Arc, but don't touch refcount by wrapping in ManuallyDrop
    let arc = mem::ManuallyDrop::new(Arc::<T>::from_raw(data as *const T));
    // Now increase refcount, but don't drop new refcount either
    let _arc_clone: mem::ManuallyDrop<_> = arc.clone();
}
```

Ignore redundant clone lint for ManuallyDrop.
2020-07-20 00:56:27 +02:00
Tim Nielens
1ac8b85c9f redundant_closure_call - pr review 2020-07-20 00:36:31 +02:00
Tim Nielens
9603d9652b redundant_closure_call - add support for shadowed closures 2020-07-20 00:30:43 +02:00
Tim Nielens
0fecaf1abc redundant_closure_call - extract lint from misc_early.rs, adapt to LatePass 2020-07-20 00:30:43 +02:00
Tim Nielens
c720d823e1 redundant_closure_call - don't lint when used more than once 2020-07-20 00:30:43 +02:00
ThibsG
442c8ae23b Fix FP for suspicious_arithmetic_impl from suspicious_trait_impl lint 2020-07-19 00:00:17 +02:00
JarredAllen
7c5d4a4145 Add test for correct behavior 2020-07-17 09:27:43 -07:00
bors
57678c8315 Auto merge of #5811 - JarredAllen:panic_multiple_args, r=phansch
Panic multiple args

changelog: Fixes bug with `panic` lint reported in #5767. I also did the same changes to the lints for `todo`, `unimplemented` and `unreachable`, so those lints should now also detect calls to those macros with a message.
2020-07-17 06:41:20 +00:00
Matthias Krüger
3618b97f59 fix typos (found by codespell) 2020-07-17 01:58:41 +02:00
JarredAllen
70a41a9281 Enable detecting multiple-argument panics 2020-07-16 16:51:12 -07:00
Leo Meira Vital
a0640457a9 Removing snippet from SHADOW_UNRELATED message. 2020-07-15 11:12:38 -03:00
bors
84cdce01cb Auto merge of #5798 - mikerite:fix-2277-2, r=yaahc
Add test for `needless_range_loop` issue

Closes #2277

This was fixed when we fixed #2542.

changelog: none
2020-07-14 17:23:31 +00:00
bors
128c5dec92 Auto merge of #5793 - warner:5783-nth-zero-next, r=flip1995
improve advice in iter_nth_zero

fixes #5783

*Please keep the line below*
changelog:  For iter_nth_zero, the "use .next()" replacement advice is on the last line of the code snippet, where it is vulnerable to truncation. Display that advice at the beginning instead.
2020-07-14 16:58:23 +00:00
Brian Warner
e83b3eb993 formatting nits 2020-07-14 09:20:19 -07:00
Matthias Krüger
126790999a new lint: Returning unit from closures expecting Ord
This lint catches cases where the last statement of a closure expecting
an instance of Ord has a trailing semi-colon. It compiles since the
closure ends up return () which also implements Ord but causes
unexpected results in cases such as sort_by_key.

Fixes #5080

reprise: rebase, update and address all concerns
2020-07-14 15:54:04 +02:00
bors
2ca58e7dda Auto merge of #5732 - bjorn3:patch-1, r=flip1995
Rename collapsable_if fix suggestion to "collapse nested if block"

The name "try" is confusing when shown as quick fix by rust-analyzer

changelog: Rename `collapsable_if` fix suggestion to "collapse nested if block"
2020-07-14 09:39:01 +00:00
bors
12df6384b9 Auto merge of #5773 - giraffate:repeat_once, r=flip1995
Add a lint for `.repeat(1)`

changelog: New lint `repeat_once`

fix #3028.
2020-07-14 09:13:58 +00:00
Michael Wright
d067d0352b Add test for needless_range_loop issue
Closes #2277

This was fixed when we fixed #2542.
2020-07-14 08:35:03 +02:00
Brian Warner
201999ccfd improve advice in iter_nth_zero
The "use .next()" replacement advice is on the last line of the code snippet,
where it is vulnerable to truncation. Display that advice at the beginning
instead.

closes #5783
2020-07-13 10:59:45 -07:00
bjorn3
ff796b6d70 Rename collapsable_if fix suggestion to "collapse nested if block"
The name "try" is confusing when shown as quick fix by rust-analyzer
2020-07-13 17:54:57 +02:00
bors
4b8700879c Auto merge of #5792 - flip1995:rollup-torc1we, r=flip1995
Rollup of 5 pull requests

Successful merges:

 - #5443 (Some accuracy lints for floating point operations)
 - #5752 (Move range_minus_one to pedantic)
 - #5756 (unnecessary_sort_by: avoid linting if key borrows)
 - #5784 (Fix out of bounds access by checking length equality BEFORE accessing by index.)
 - #5786 (fix phrase in new_lint issue template)

Failed merges:

r? @ghost

changelog: rollup
2020-07-13 14:21:20 +00:00
Philipp Krones
32ef448bdb
Rollup merge of #5756 - ebroto:5754_sort_by, r=flip1995
unnecessary_sort_by: avoid linting if key borrows

changelog: Avoid linting if key borrows in [`unnecessary_sort_by`]

Fixes #5754
Closes #2313
2020-07-13 15:59:44 +02:00
Philipp Krones
019e281d15
Rollup merge of #5752 - chrisduerr:pedantic_ranges, r=flip1995
Move range_minus_one to pedantic

This moves the range_minus_one lint to the pedantic category, so there
will not be any warnings emitted by default. This should work around
problems where the suggestion is impossible to resolve due to the range
consumer only accepting a specific range implementation, rather than the
`RangeBounds` trait (see #3307).

While it is possible to work around this by extracting the boundary into
a variable, I don't think clippy should encourage people to disable or
work around lints, but instead the lints should be fixable. So hopefully
this will help until a proper implementation checks what the range is
used for.

*Please keep the line below*
changelog: move [`range_minus_one`] to pedantic
2020-07-13 15:59:42 +02:00
Philipp Krones
75d43aac73
Rollup merge of #5443 - thiagoarrais:issue-2040, r=flip1995
Some accuracy lints for floating point operations

This will add some lints for accuracy on floating point operations suggested by @clarfon in #2040 (fixes #2040).

These are the remaining lints:

- [x] x.powi(2) => x * x
- [x] x.logN() / y.logN() => x.logbase(y)
- [x] x.logbase(E) => x.log()
- [x] x.logbase(10) => x.log10()
- [x] x.logbase(2) => x.log2().
- [x] x * PI / 180 => x.to_radians()
- [x] x * 180 / PI => x.to_degrees()
- [x] (x + 1).log() => x.log_1p()
- [x] sqrt(x * x + y * y) => x.hypot(y)

changelog: Included some accuracy lints for floating point operations
2020-07-13 15:59:41 +02:00
bors
fa4a737fba Auto merge of #5790 - flip1995:rustup, r=flip1995
Rustup

r? @ghost

changelog: none
2020-07-13 13:53:11 +00:00
Manish Goregaokar
b57ceb45b0 Rollup merge of #72920 - oli-obk:const_transmute, r=RalfJung
Stabilize `transmute` in constants and statics but not const fn

cc #53605 (leaving issue open so we can add `transmute` to `const fn` later)

Previous attempt: #64011

r? @RalfJung

cc @rust-lang/wg-const-eval
2020-07-11 08:53:06 -07:00
Oliver Scherer
1eb0053dcd Stabilize transmute in constants and statics but not const fn 2020-07-11 09:22:17 +02:00
bors
7d611d9224 Auto merge of #5769 - robojumper:match_like_matches_macro, r=phansch
new lint: match_like_matches_macro

Suggests using the `matches!` macro from `std` where appropriate.

`redundant_pattern_matching` has been moved into the `matches` pass to allow suppressing the suggestion where `is_some` and friends are a better replacement.

changelog: new lint: `match_like_matches_macro`
2020-07-10 18:10:08 +00:00
Christian Duerr
afa4148cc6
Fix tests a bit more 2020-07-10 17:53:01 +02:00
Christian Duerr
b3c719608d
Fix test failures 2020-07-10 17:23:03 +02:00
Tamir Duberstein
cf91c54cc6 Avoid "whitelist"
Other terms are more inclusive and precise.
2020-07-10 07:39:28 -04:00
bors
45eea9a822 Auto merge of #5771 - montrivo:bugfix/single-match-else, r=matthiaskrgr
single_match_else - single expr/stmt else block corner case

One approach to fix #3489.
See discussion in the issue.

changelog: single_match_else - single expr/stmt else block corner case fix
2020-07-09 12:03:14 +00:00
Tim Nielens
dac19e3afc single_match_else - single expr/stmt else block corner case 2020-07-09 12:04:27 +02:00
Eduardo Broto
db1c946aaa unnecessary_sort_by: avoid linting if key borrows 2020-07-08 21:31:59 +02:00
robojumper
37d75da266 make match_like_matches_macro only apply to matches with a wildcard 2020-07-08 18:37:20 +02:00
Takayuki Nakata
5307cb5614 Add a lint for .repeat(1)
fix #3028.
2020-07-07 23:13:39 +09:00
Thiago Arrais
6be9491eac Reclassify powi(2) lint under suboptimal_flops 2020-07-06 13:45:43 -03:00
Thiago Arrais
6dc066fdb9 Includes TODO comment for hypot lint 2020-07-06 13:45:43 -03:00
Thiago Arrais
db7bc6b3bd Place radian lints under suboptimal_flops 2020-07-06 13:45:43 -03:00
Thiago Arrais
f5596826fa Better copy for lint message
Since x.log(y) is actually implemented as x.ln() / y.ln()
2020-07-06 13:45:43 -03:00
Thiago Arrais
076ec872ce Lint for to_radians and to_degrees 2020-07-06 13:45:39 -03:00
Thiago Arrais
0c8afa39ce Lint x.log(b) / y.log(b) => x.log(y) 2020-07-06 13:32:31 -03:00
robojumper
2e8a1be444 new lint: match_like_matches_macro 2020-07-06 18:25:20 +02:00
Thiago Arrais
f62798454c Lint (x * x + y * y).sqrt() => x.hypot(y) 2020-07-06 13:23:17 -03:00