Commit graph

3738 commits

Author SHA1 Message Date
Michael Wright
9102832692 Fix incorrect comment 2020-08-25 05:53:28 +02:00
bors
64b53f3877 Auto merge of #5920 - giraffate:fix_fp_for_redundant_closure_call, r=mikerite
Fix FP for `redundant_closure_call`

Fix #5916

changelog: Fix FP for `redundant_closure_call` when called in function body
2020-08-25 03:29:59 +00:00
Scott McMurray
48b4aeabf8 Unbreak the clippy test 2020-08-24 16:29:03 -07:00
Matthias Krüger
e9964f2e8a stable_sort_primitive: print the type that is being sorted in the lint message 2020-08-24 20:06:43 +02:00
Bastian
680c68153b Added a lint which corrects expressions like (a - b) < f32::EPSILON 2020-08-24 16:31:51 +02:00
ThibsG
3d820f71fe Fix incorrect suggestion when clone_on_ref_ptr is triggered in macros 2020-08-24 14:05:49 +02:00
rail-rain
ce8915c85c
typo
Co-authored-by: Thibaud <ThibsG@users.noreply.github.com>
2020-08-24 19:08:38 +12:00
Takayuki Nakata
9fe0ac36a5 Avoid period in lint message according to convention 2020-08-24 10:11:53 +09:00
Takayuki Nakata
b2c2266792 Fix FP for redundant_closure_call
Visit the nested things like function body when checking closure call.
2020-08-24 09:43:16 +09:00
rail
91b200c62b Fix fp in borrow_interior_mutable_const
Fix false positive when referencing a field behind a pointer.
2020-08-23 22:49:08 +12:00
Eduardo Broto
8776db9f6d Fix ICE in repeat_once lint 2020-08-23 12:05:34 +02:00
Michael Wright
e8d33d73dc Fix let_and_return bad suggestion
Add a cast to the suggestion when the return expression has adjustments.
These adjustments are lost when the suggestion is applied.

This is similar to the problem in issue #4437.

Closes #5729
2020-08-23 07:50:59 +02:00
bors
dd07860b83 Auto merge of #5941 - ThibsG:InlineInCopyPassByRef, r=yaahc
Don't lint if it has always inline attribute

Don't trigger the lint `trivially_copy_pass_by_ref` if it has `#[inline(always)]` attribute.

Note: I am not particularly familiar with `inline` impacts, so I implemented this the way that if only `#[inline]` attribute is here (without `always`), the lint will still trigger. Also, it will still trigger if it has `#[inline(never)]`.
Just tell me if it sounds too much conservative.

Fixes: #5876

changelog: none
2020-08-22 18:30:39 +00:00
Christian Stefanescu
53508aeb65 Run sh tests/ui/update-all-references.sh 2020-08-22 14:22:02 +02:00
Christian Stefanescu
5b07b9ed61 Widen understanding of prelude import
Prelude imports are exempt from wildcard import warnings. Until now only
imports of the form

```
use ...::prelude::*;
```

were considered. This change makes it so that the segment `prelude` can
show up anywhere, for instance:

```
use ...::prelude::v1::*;
```

Fixes #5917
2020-08-22 14:22:02 +02:00
ThibsG
191b6c798f Don't lint if it has always inline attribute 2020-08-22 12:58:35 +02:00
ThibsG
03bc7aed44 Add async test case for wrong_self_convention lint 2020-08-22 08:14:42 +02:00
bors
b57ef14290 Auto merge of #5926 - giraffate:improve_lint_message_in_to_string_in_display, r=yaahc
Improve lint message in `to_string_in_display`

This is a follow-up of https://github.com/rust-lang/rust-clippy/pull/5831.

changelog: none
2020-08-22 04:51:38 +00:00
Michael Wright
11efd75aeb Fix false negative in option_as_ref_deref 2020-08-21 07:23:04 +02:00
Tim Nielens
2ecc2ac864 unit-arg - improve suggestion 2020-08-21 00:42:11 +02:00
bors
4104611913 Auto merge of #5928 - mikerite:fix-5924, r=ebroto
Fix false positive in `PRECEDENCE` lint

Extend the lint to handle chains of methods combined with unary negation.

Closes #5924

changelog: Fix false negative in `PRECEDENCE` lint
2020-08-20 22:09:27 +00:00
Michael Wright
c236c0fb56 Fix false positive in PRECEDENCE lint
Extend the lint to handle chains of methods combined with unary negation.

Closes #5924
2020-08-20 06:34:48 +02:00
Takayuki Nakata
902b28275e Improve lint message in to_string_in_display 2020-08-19 22:31:34 +09:00
Eduardo Broto
6a12bae194 no from/to bits in const: add tests cases for f64 2020-08-18 22:19:30 +02:00
Eduardo Broto
df4d42fc2d transmute: avoid suggesting from/to bits in const 2020-08-18 21:55:56 +02:00
flip1995
c680602005
Merge remote-tracking branch 'upstream/master' into rustup 2020-08-18 19:50:23 +02:00
bors
9360ca6dc2 Auto merge of #5908 - giraffate:fix_fp_for_same_item_push, r=flip1995
Fix FP for `same_item_push`

Fixes https://github.com/rust-lang/rust-clippy/issues/5902

changelog: Fix FP for `same_item_push` where the pushed variable is mutated.
2020-08-17 16:49:03 +00:00
David Wood
f13d2bfd9b clippy: support QPath::LangItem
This commit updates clippy with the introduction of `QPath::LangItem` so
that it still compiles.

Signed-off-by: David Wood <david@davidtw.co>
2020-08-17 13:55:05 +01:00
Tomasz Miąsko
4f4abf4e06 Warn about explicit self-assignment
Warn about assignments where left-hand side place expression is the same
as right-hand side value expression. For example, warn about assignment in:

```rust
pub struct Event {
    id: usize,
    x: i32,
    y: i32,
}

pub fn copy_position(a: &mut Event, b: &Event) {
    a.x = b.x;
    a.y = a.y;
}
```
2020-08-16 23:31:36 +02:00
Dániel Buga
fc1e07e0c1 Rename lint to use plural form 2020-08-16 22:16:39 +02:00
Dániel Buga
b175642a85 Fix missed rename 2020-08-16 21:33:29 +02:00
Dániel Buga
75637c1eda Catch function calls in argument lists, add tests that tuples don't get linted 2020-08-16 20:27:54 +02:00
Dániel Buga
a7cc5d4068 Also simplify if the closure body is an index expression 2020-08-16 20:27:54 +02:00
Dániel Buga
a3ea65c2d9 Implement new lint 2020-08-16 20:27:22 +02:00
bors
3bd98895f1 Auto merge of #5725 - montrivo:should-impl-trait, r=flip1995
should_impl_trait - ignore methods with lifetime params

Fixes: #5617

changelog: don't lint should_implement_trait when an `Iterator::next` case has explicit parameters
2020-08-16 17:51:18 +00:00
bors
78857cc9d3 Auto merge of #5907 - wiomoc:feature/useless-vec-max-size, r=flip1995
appreciative too_large_for_stack in useless `vec!`

Fixes: #5847
changelog: Add `too_large_for_stack ` configuration option for `USELESS_VEC`
2020-08-16 17:30:12 +00:00
bors
dff7e74b27 Auto merge of #5903 - jrqc:needless_return, r=ebroto,flip1995
Needless return

Fixes #5858
changelog: fix false positive [`needless_return`]
2020-08-16 17:08:45 +00:00
bors
c8e05fc1c6 Auto merge of #5881 - wiomoc:feature/single-char-push_str, r=ebroto,flip1995
Lint `push_str` with a single-character string literal

Fixes #5875
changelog:  `* [single_char_push_str]`
2020-08-16 16:41:57 +00:00
bors
e522ca3c8d Auto merge of #5831 - chansuke:to_string_in_display, r=flip1995
Don't use `to_string` in impl Display

fixes #3876

this PR is derived from [Toxyxer's implementation](https://github.com/rust-lang/rust-clippy/pull/5574).
changelog: add [`to_string_in_display`] lint
2020-08-16 16:21:37 +00:00
Eduardo Broto
1a140dcc1c Improve needless_doctest_main by using the parser 2020-08-16 00:25:54 +02:00
jrqc
baa4cb1cdd early return removed 2020-08-16 00:24:27 +03:00
jrqc
a7d5c2f967 Modifications according to the code review 2020-08-16 00:24:27 +03:00
jrqc
65d10c7abf Borrow checker added 2020-08-16 00:24:27 +03:00
Christoph Walcher
ae56e988a2
Merge lint with single_char_pattern 2020-08-15 01:40:55 +02:00
Christoph Walcher
72d2c2eab4
Lint push_str with a single-character string literal
Fixes #5875
2020-08-15 01:40:55 +02:00
Takayuki Nakata
f98ffa271d Fix FP for same_item_push
Don't emit a lint when `pushed_item` was declared as mutable variable.
2020-08-14 22:54:12 +09:00
chansuke
8e549978e5 Don't use to_string in impl Display 2020-08-14 21:38:11 +09:00
Christoph Walcher
8514b8407a
appreciative too_large_for_stack in useless vec!
Fixes: #5847
2020-08-14 14:29:16 +02:00
bors
d5f5487252 Auto merge of #5899 - JarredAllen:rc-box-suggestion, r=yaahc
Change Rc<Box<T>> recommendation to be Rc<T> instead of Box<T>

Fixes #5722

changelog: Suggest `Rc<Box<T>>` -> `Rc<T>` in [`redundant_allocation`] lint
2020-08-13 13:31:55 +00:00
bors
fc4fd91914 Auto merge of #5900 - ThibsG:ParensUselessConversion4750, r=phansch
Fix: keep parenthesis for suggestion in `useless_conversion` lint

Note: this lint was previously named `identity_conversion`.

fixes: #4750

changelog: fix parenthesis for `useless_conversion` lint suggestion
2020-08-13 05:27:29 +00:00
ThibsG
5634c8da02 Fix: keep parenthesis for suggestion in useless_conversion lint 2020-08-12 21:44:02 +02:00
JarredAllen
480ccc3dbe Change Rc<Box<T>> recommendation to be Rc<T> instead of Box<T> 2020-08-12 10:35:08 -07:00
bors
439bae62a4 Auto merge of #5884 - Ryan1729:patch-1, r=flip1995
Add the other overloadable operations to suspicious_arithmetic_impl

In #2268 I idly mused that the other user-overloadable operations could be added to this lint. Knowing that the lint was arguably incomplete was gnawing at the back of my mind, so I figured that I might as well make this PR, particularly given the change needed was so small.

changelog: Start warning on suspicious implementations of the `BitAnd`, `BitOr`, `BitXor`, `Rem`, `Shl`, and `Shr` traits.
2020-08-12 17:00:48 +00:00
Ryan1729
7bd7a46331 run tests/ui/update-references.sh to update 'suspicious_arithmetic_impl.rs' 2020-08-12 10:52:20 -06:00
Ryan1729
f4eeff99b6 add tests for Rem, BitAnd, BitOr, BitXor, Shl, and Shr 2020-08-12 10:33:16 -06:00
flip1995
027780ca2c Merge commit '09bd400243ed6f7059fedc0c1623aae3792521d6' into clippyup 2020-08-11 17:50:45 +02:00
Matthias Krüger
be3e695b60 if_not_else: make lint adhere to lint message convention 2020-08-11 16:43:53 +02:00
Matthias Krüger
605e027fda if_let_some_result: make lint adhere to lint message convention 2020-08-11 16:40:45 +02:00
Matthias Krüger
89591a78b8 enum-variant-names: make lint adhere to lint message convention 2020-08-11 16:38:20 +02:00
Matthias Krüger
db390f5e6a enum-clike-unportable-variant: tweak message a bit (Clike -> C-like) 2020-08-11 16:35:09 +02:00
Matthias Krüger
2de290d5c5 duration-subsec: make lint adhere to lint message convention 2020-08-11 16:31:02 +02:00
Matthias Krüger
423615693b pub-enum-variant-names: make lint adhere to lint message convention 2020-08-11 16:28:05 +02:00
Matthias Krüger
1f17c3b02b multiple_inherent_impl: make lint adhere to lint message convention 2020-08-11 15:28:51 +02:00
Matthias Krüger
bdf4dc3abd implicit-saturating-sub: make lint adhere to lint message convention 2020-08-11 15:22:59 +02:00
Matthias Krüger
f171f89aed int_plus_one: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
Matthias Krüger
6af297f80e iter-next-slice: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
Matthias Krüger
04867e004e mutex-atomic: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
Matthias Krüger
ac194cafc1 map_clone: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
Matthias Krüger
c0a9d64818 stable-sort-primitive: make lint adhere to lint message convention 2020-08-11 15:15:26 +02:00
bors
3337f7956c Auto merge of #5892 - matthiaskrgr:redundant_mut, r=flip1995
unnecessary-mut-passed: make lint message say if fn is a function or a method

changelog: refine "unnecessary-mut-passed" lint message
2020-08-11 12:52:41 +00:00
bors
09bd400243 Auto merge of #5891 - flip1995:rustup, r=flip1995
Rustup

r? @ghost

Sync back rust-lang/rust#75098

changelog: none
2020-08-11 12:32:10 +00:00
flip1995
9311c11d7c
Fix sync fallout 2020-08-11 14:21:27 +02:00
Matthias Krüger
b8713e3854 unnecessary-mut-passed: make lint message say if fn is a function or a method. 2020-08-11 14:16:56 +02:00
Dylan DPC
9e73d33680 Rollup merge of #75098 - Ryan1729:clippy-pointer-cast-lint-experiment, r=oli-obk
Clippy pointer cast lint experiment

This PR is an experiment about exposing more parts of `rustc_typeck` for use in `clippy`. In particular, the code that checks where a cast is valid or not was exposed, which necessitated exposing [`FnCtxt`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/check/struct.FnCtxt.html), and figuring out how to create an instance of that type inside `clippy`.

This was prompted by [this clippy issue](https://github.com/rust-lang/rust-clippy/issues/2064).

r? @oli-obk
2020-08-11 01:56:30 +02:00
bors
cc5bfd473c Auto merge of #5888 - matthiaskrgr:lints, r=yaahc
make a bunch of lints texts adhere to rustc dev guide

According to the rustc-dev guide: "The text should be matter of fact and avoid capitalization and periods, unless multiple sentences are needed"

changelog: make some lint output adhere to the rustc-dev guide
2020-08-10 22:40:42 +00:00
Matthias Krüger
6d0b5e24df update test stderr 2020-08-11 00:27:55 +02:00
Matthias Krüger
dabf989195 neg-cmp-op-on-partial-ord: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
178da9b2ef neg-multiply: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
e519bb3c85 overflow-check-conditional: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
9178363574 path-buf-push-overwrite: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
81f77a411e range-zip-with-len: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
3e1e0c9bdb redundant-static-lifetimes: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
5d69ca5e11 also change "deprecated-attribute" message 2020-08-10 23:49:06 +02:00
Matthias Krüger
fe37ddbd11 suspicious-arithmetic-impl: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
7954c22a99 unknown: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
b36a6c9594 ref_in_deref: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
4418ff122f unneeded-field-pattern: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
2792260636 empty-liner-after-outer-attr: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
0db5cb1393 drop_bounds: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
590b91d8d4 double-parens: make lint adhere to lint message convention and do minor refactoring 2020-08-10 23:49:06 +02:00
Matthias Krüger
ba7a01a6a8 double-comparisons: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
6b0a6a70f8 default-trait-access: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
3d592b5154 cmp_null: make lint adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
8679dd375b unnecessary_unwrap, panicking_unwrap: make lints adhere to lint message convention 2020-08-10 23:49:06 +02:00
Matthias Krüger
9b7ab1d38b checked-conversions: make lint adhere to lint message convention 2020-08-10 23:48:57 +02:00
Eduardo Broto
5d66bd7bb3 Avoid or_fun_call for const_fn with no args 2020-08-10 23:38:58 +02:00
Matthias Krüger
40416c0fa8 naive_bytecount: make lint adhere to lint message convention 2020-08-10 20:55:23 +02:00
Matthias Krüger
fd379a889e builtin-type-shadow: make lint adhere to lint message convention 2020-08-10 20:55:23 +02:00
Matthias Krüger
0876f17d77 bool-comparison: make lint adhere to lint message convention 2020-08-10 20:55:23 +02:00
Matthias Krüger
e57aafe33f too-many-lines: make lint adhere to lint message convention 2020-08-10 20:55:23 +02:00
Philipp Krones
ee8db50e13
Rollup merge of #5871 - wiomoc:feature/methodcall-minmax, r=flip1995
Lint .min(x).max(y) with x < y

Fixes  #5854

changelog: Also lint `ord.min(a).max(b)`, where `a < b` in [`min_max`] lint
2020-08-10 14:56:29 +02:00
Philipp Krones
08ab29bed1
Rollup merge of #5870 - ebroto:5789_allow_unsafe_derive_deserialize, r=flip1995
enable #[allow(clippy::unsafe_derive_deserialize)]

Before this change this lint could not be allowed as the code we are checking is automatically generated.

changelog: Enable using the `allow` attribute on top of an ADT linted by [`unsafe_derive_deserialize`].

Fixes: #5789
2020-08-10 14:56:27 +02:00
Philipp Krones
8ee57eed79
Rollup merge of #5869 - wiomoc:feature/implicit-self, r=ebroto,flip1995
New lint against `Self` as an arbitrary self type

Fixes #5861

changelog: * [`needless_arbitrary_self_type`] [#5869](https://github.com/rust-lang/rust-clippy/pull/5869)
2020-08-10 14:56:26 +02:00
Philipp Krones
9da5b6d1d0
Rollup merge of #5825 - giraffate:same_item_push, r=Manishearth
Add the new lint `same_item_push`

changelog: Add the new lint `same_item_push`

Fixed #4078. As I said in https://github.com/rust-lang/rust-clippy/issues/4078#issuecomment-658184195, I referrerd to https://github.com/rust-lang/rust-clippy/pull/4647.
2020-08-10 14:56:25 +02:00
Tim Nielens
166c520e9a should_impl_trait - pr comments 2020-08-09 15:10:00 +02:00
Tim Nielens
2bc0ecd44b should_implement_trait - add test cases for every checked trait method 2020-08-09 15:10:00 +02:00
Tim Nielens
a77e881ec9 should_impl_trait - ignore methods with lifetime params 2020-08-09 15:10:00 +02:00
Ryan1729
873e5f5c19 add allow unused_unsafe and allow dead_code 2020-08-09 00:39:14 -06:00
Ryan1729
bc8d32d36b fix unary minus on usize and unused variable errors in .fixed file 2020-08-09 00:28:56 -06:00
Ryan1729
84db238fa1 add a test example of where transmutes_expressible_as_ptr_casts should not suggest anything 2020-08-09 00:15:56 -06:00
Ryan1729
a1ca12581a update stderr for transmutes_expressible_as_ptr_casts 2020-08-08 21:03:41 -06:00
bors
70c46de012 Auto merge of #5877 - ebroto:5872_loops_ice, r=Manishearth
Fix ICE in `loops` module

changelog: Fix ICE related to `needless_collect` when a call to `iter()` was not present.

I went for restoring the old suggestion of `next().is_some()` over `get(0).is_some()` given that `iter()` is not necessarily present (could be e.g. `into_iter()` or `iter_mut()`)  and that the old suggestion could change semantics, e.g. a call to `filter()` could be present between `iter()` and the collect part.

Fixes #5872
2020-08-08 18:44:48 +00:00
bors
3899d6001c Auto merge of #5878 - flip1995:rustup, r=flip1995
Rustup

r? @ghost

changelog: none
2020-08-08 17:28:34 +00:00
Eduardo Broto
888657e09a Fix ICE in loops module 2020-08-08 18:13:43 +02:00
Christoph Walcher
87e740921a
check impl Ord / is_float 2020-08-07 18:30:20 +02:00
Christoph Walcher
bfe610cc8d
ignore mutable self reference parameters 2020-08-07 18:08:51 +02:00
Christoph Walcher
e03f73e627
fix nits 2020-08-07 18:08:51 +02:00
Christoph Walcher
c87d999fa2
fix ui tests 2020-08-07 18:08:51 +02:00
Christoph Walcher
d635b76eaf
adopt comments from review 2020-08-07 18:08:51 +02:00
Christoph Walcher
e0a4988fcc
Lint against Self as an arbitrary self type
Fixes #5861
2020-08-07 18:08:51 +02:00
bors
a7fa264ae7 Auto merge of #74821 - oli-obk:const_eval_read_uninit_fast_path, r=wesleywiser
Check whether locals are too large instead of whether accesses into them are too large

Essentially this stops const prop from attempting to optimize

```rust
let mut x = [0_u8; 5000];
x[42] = 3;
```

I don't expect this to be a perf improvement without #73656 (which is also where the lack of this PR will be a perf regression).

r? @wesleywiser
2020-08-07 15:28:07 +00:00
Ryan1729
fe9ad57e98 copy over *.fixed file 2020-08-06 20:28:29 -06:00
Ryan Wiedemann
49c7e39d03 Apply suggestions from code review
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-08-06 07:57:31 -06:00
Ryan1729
b0c8c7af16 add newline to transmutes_expressible_as_ptr_casts.rs 2020-08-06 04:49:06 -06:00
Ryan1729
ded2d6c233 add extra error message to the expected stderr for transmutes_expressible_as_ptr_casts test 2020-08-06 04:24:25 -06:00
Ryan1729
94340d6e17 add documentation to functions that call do_check and add a test against lint ordering changing 2020-08-06 04:24:25 -06:00
Ryan1729
ccc4747f46 get the expected number of errors by acknowledging that other lints are covering the same ground 2020-08-06 04:24:25 -06:00
Ryan1729
de05212987 try putting the can_be_expressed_as_pointer_cast at the top and find that we still get an ICE 2020-08-06 04:24:24 -06:00
Ryan1729
46ef4e8651 write currently failing test for transmutes_expressible_as_ptr_casts
There are 5 errors, when there should be 7.
2020-08-06 04:24:24 -06:00
Ryan1729
5e84b8c2fb run cargo dev new_lint then move transmutes_expressible_as_ptr_casts into transmute module 2020-08-06 04:24:24 -06:00
Christoph Walcher
0abc4833e5
Lint .min(x).max(y) with x < y
Fixes #5854
2020-08-06 02:56:07 +02:00
Eduardo Broto
50a86d4927 enable #[allow(clippy::unsafe_derive_deserialize)] 2020-08-06 00:45:30 +02:00
bors
2d4c3379d3 Auto merge of #5809 - JarredAllen:stable_sort_primitive, r=Manishearth
Stable sort primitive

changelog: Implements #5762
2020-08-05 20:41:21 +00:00
bors
2eab060ab7 Auto merge of #5859 - ebroto:5765_manual_async_fn_fp, r=yaahc
manual_async_fn: take input lifetimes into account

The anonymous future returned from an `async fn` captures all input
lifetimes. This was not being taken into account.

See https://github.com/rust-lang/rfcs/blob/master/text/2394-async_await.md#lifetime-capture-in-the-anonymous-future

changelog: Take input lifetimes into account in [`manual_async_fn`].

Fixes #5765
2020-08-05 17:52:28 +00:00
Takayuki Nakata
b7ceb4d3d7 rustfmt 2020-08-05 23:00:03 +09:00
Takayuki Nakata
14a4e3bcc8 Fix a lint message 2020-08-05 22:59:12 +09:00
Takayuki Nakata
161f475100 Add test case for same_item_push 2020-08-05 22:51:38 +09:00
Takayuki Nakata
1e8ada3cab Add lint same_item_push 2020-08-05 22:51:38 +09:00
bors
3d7e3fdffd Auto merge of #5857 - tmiasko:try-err-poll, r=matthiaskrgr
try_err: Consider Try impl for Poll when generating suggestions

There are two different implementation of `Try` trait for `Poll` type:
`Poll<Result<T, E>>` and `Poll<Option<Result<T, E>>>`. Take them into
account when generating suggestions.

For example, for `Err(e)?` suggest either `return Poll::Ready(Err(e))` or
`return Poll::Ready(Some(Err(e)))` as appropriate.

Fixes #5855

changelog: try_err: Consider Try impl for Poll when generating suggestions
2020-08-05 08:43:37 +00:00
Philipp Krones
84455b211f
Rollup merge of #5852 - wiomoc:feature/lint-duplicate-trait, r=Manishearth
Add lint for duplicate methods of trait bounds

rel: #5777

changelog: Add [`trait_duplication_in_bounds`] lint
2020-08-04 12:06:41 +02:00
Philipp Krones
888067c623
Rollup merge of #5848 - Ryan1729:add-derive_ord_xor_partial_ord-lint, r=matthiaskrgr
Add derive_ord_xor_partial_ord lint

Fix #1621

Some remarks:
This PR follows the example of the analogous derive_hash_xor_partial_eq lint where possible.
I initially tried using the `match_path` function to identify `Ord` implementation like the derive_hash_xor_partial_eq lint currently does, for `Hash` implementations but that didn't work.

Specifically, the structs at the top level were getting paths that matched `&["$crate", "cmp", "Ord"]` instead of `&["std", "cmp", "Ord"]`. While trying to figure out what to do instead I saw the comment at the top of [clippy_lints/src/utils/paths.rs](f5d429cd76/clippy_lints/src/utils/paths.rs (L5)) that mentioned [this issue](https://github.com/rust-lang/rust-clippy/issues/5393) and suggested to use diagnostic items instead of hardcoded paths whenever possible. I looked for a way to identify `Ord` implementations with diagnostic items, but (possibly because this was the first time I had heard of diagnostic items,) I was unable to find one.

Eventually I tried using `get_trait_def_id` and comparing `DefId` values directly and that seems to work as expected. Maybe there's a better approach however?

changelog: new lint: derive_ord_xor_partial_ord
2020-08-04 12:06:40 +02:00
Philipp Krones
378ba2e03e
Rollup merge of #5846 - dima74:map_flatten.map_to_option, r=flip1995
Handle mapping to Option in `map_flatten` lint

Fixes #4496

The existing [`map_flatten`](https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten) lint suggests changing `expr.map(...).flatten()` to `expr.flat_map(...)` when `expr` is `Iterator`. This PR changes suggestion to `filter_map` instead of `flat_map` when mapping to `Option`, because it is more natural

Also here are some questions:
* If expression has type which implements `Iterator` trait (`match_trait_method(cx, expr, &paths::ITERATOR) == true`), how can I get type of iterator elements? Currently I use return type of closure inside `map`, but probably it is not good way
* I would like to change suggestion range to cover only `.map(...).flatten()`, that is from:
```
    let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `flat_map` instead: `vec![5_i8; 6].into_iter().flat_map
```
to
```
    let _: Vec<_> = vec![5_i8; 6].into_iter().map(|x| 0..x).flatten().collect();
                                             ^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `flat_map` instead: `.flat_map(|x| 0..x)`
```
Is it ok?
* Is `map_flatten` lint intentionally in `pedantic` category, or could it be moved to `complexity`?

changelog: Handle mapping to Option in [`map_flatten`](https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten) lint
2020-08-04 12:06:39 +02:00
Philipp Krones
ca2a25d966
Rollup merge of #5837 - JarredAllen:needless_collect, r=phansch
needless_collect: catch x: Vec<_> = iter.collect(); x.into_iter() ...

changelog: Expand the needless_collect lint as suggested in #5627 (WIP).

This PR is WIP because I can't figure out how to make the multi-part suggestion include its changes in the source code (the fixed is identical to the source, despite the lint making suggestions). Aside from that one issue, I think this should be good.
2020-08-04 12:06:38 +02:00
bors
1968aede0f Auto merge of #5867 - flip1995:rustup, r=flip1995
Rustup

r? @ghost

changelog: none
2020-08-04 09:25:05 +00:00
Tomasz Miąsko
e9677105bf try_err: Consider Try impl for Poll when generating suggestions
There are two different implementation of Try trait for Poll type;
Poll<Result<T, E>> and Poll<Option<Result<T, E>>>. Take them into
account when generating suggestions.

For example, for Err(e)? suggest either return Poll::Ready(Err(e)) or
return Poll::Ready(Some(Err(e))) as appropriate.
2020-08-03 20:48:18 +02:00
JarredAllen
25abd7ae76 Create stable_sort_primitive lint 2020-08-03 11:17:43 -07:00
flip1995
0e44ed5ca9
Fix ui-cargo tests in CI 2020-08-03 18:18:11 +02:00
JarredAllen
5e10b039a3 Implement review suggestions 2020-08-02 21:46:18 -07:00
JarredAllen
a849483294 Fix formatting and dogfood fallout 2020-08-02 21:34:17 -07:00
JarredAllen
c86f4109fd Split indirect collects into their own test case 2020-08-02 21:34:17 -07:00
JarredAllen
3ee61373fe Write the lint and write tests 2020-08-02 21:34:17 -07:00
JarredAllen
05bb6e6bdb Create test for wanted behavior 2020-08-02 21:34:17 -07:00
Eduardo Broto
e336fe80d2 manual_async_fn: take input lifetimes into account
The anonymous future returned from an `async fn` captures all input
lifetimes. This was not being taken into account.

See https://github.com/rust-lang/rfcs/blob/master/text/2394-async_await.md#lifetime-capture-in-the-anonymous-future
2020-08-03 00:36:28 +02:00
liuzhenyu
24a6130da2 fix typos 2020-08-02 23:20:00 +08:00
Dmitry Murzin
d4ba561aaf
Review fixes 2020-07-31 00:28:21 +03:00
Dmitry Murzin
a427c99f3d
Handle mapping to Option in map_flatten lint 2020-07-30 23:23:33 +03:00
Oliver Scherer
98f3c79385 Update clippy ui test.
The reason we do not trigger these lints anymore is that clippy sets the mir-opt-level to 0, and the recent changes subtly changed how the const propagator works.
2020-07-29 22:14:19 +02: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
Christoph Walcher
94c50bc8c9
Lint duplicate methods of trait bounds
Fixes #5777
2020-07-28 16:42:26 +02:00
Ryan1729
668b7474b4 run cargo dev fmt and fix overly long line 2020-07-26 23:30:00 -06:00
Ryan1729
6c3e4591b8 update reference since we see the expected four errors 2020-07-26 23:04:25 -06:00
Ryan1729
0722991b62 add test for derive_ord_xor_partial_ord based on test for derive_hash_xor_partial_eq 2020-07-26 21:36:50 -06:00
Ryan1729
5a644964fc run cargo dev new_lint
specifically:
cargo dev new_lint --name derive_ord_xor_partial_ord --category correctness --pass late
2020-07-26 20:40:57 -06: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
flip1995
d164ab65f7 Merge commit 'da5a6fb1b65ec6581a67e942a3850f6bc15a552c' into clippyup 2020-07-26 21:07:07 +02: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
flip1995
6f25adbd5a Merge commit '2ca58e7dda4a9eb142599638c59dc04d15961175' into clippyup 2020-07-14 14:59:59 +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
Thiago Arrais
a6f1af75d7 Lint for x.powi(2) => x * x 2020-07-06 13:23:17 -03:00
JarredAllen
6e2d55c8db Update compile-test to follow new lint 2020-07-03 16:51:44 -07:00
JarredAllen
f73b455b99 Refactoring 2020-07-03 16:47:38 -07:00
JarredAllen
88c8afdddf Handle ref, mut, &, and &mut on the option 2020-07-03 16:47:38 -07:00
JarredAllen
b85796fe36 Properly parenthesize to avoid operator precedence errors 2020-07-03 16:47:38 -07:00
JarredAllen
82f8d4d6f1 Stop linting on macros and correctly use braces for constructs 2020-07-03 16:47:38 -07:00
JarredAllen
bf48a2d50d Lint for if let Some(x) = ... instead of Option::map_or 2020-07-03 16:47:38 -07:00
bors
57cdf2dc16 Auto merge of #4841 - phaylon:pattern-type-mismatch, r=flip1995
Added restriction lint: pattern-type-mismatch

changelog: Added a new restriction lint `pattern-type-mismatch`. This lint is especially helpful for beginners learning about the magic behind pattern matching. (This explanation might be worth to include in the next changelog.)
2020-07-03 16:41:26 +00:00
Robert Sedlacek
346ee968bb Adjusted expected STDERR 2020-07-03 18:12:29 +02:00
Robert Sedlacek
c3c402783f Added restriction lint: pattern-type-mismatch 2020-07-03 18:12:29 +02:00
ThibsG
2d5930a3da Don't lint for predicates generated in macros 2020-07-03 17:29:54 +02:00
ThibsG
d5a8f03a35 Take generic args into account for bounded type 2020-07-03 17:29:54 +02:00
ThibsG
754bfb1dc8 Add configurable threshold for type_repetition_in_bounds lint 2020-07-03 17:29:54 +02:00
flip1995
a7c58e66d4
Merge remote-tracking branch 'upstream/master' into rustup 2020-07-03 12:50:41 +02:00
Eduard-Mihai Burtescu
30c046ede4 Use 'tcx for references to AccessLevels wherever possible. 2020-07-03 00:04:48 +03:00
Philipp Hansch
d347d0cf59
Deprecate regex_macro lint 2020-07-01 13:05:41 +02:00
Michael Wright
5b9c2ff9cc Fix multiple_crate_versions error
Fix the versions of packages in the multiple_crate_versions ui test by
checking in the Cargo.lock for the test package. `ansi_term 0.11`
depends on `winapi ^0.3.4`. This means means that the expected stderr for
this test would have to be updated whenever `winapi 0.3` is updated
otherwise.
2020-07-01 07:35:18 +02:00
bors
36b7983580 Auto merge of #5758 - ebroto:5704_unnested_or_pats, r=flip1995
Require `or_patterns` to suggest nesting them

changelog: Require `#![feature(or_patterns)]` to trigger [`unnested_or_patterns`]

Fixes #5704
2020-06-30 22:23:23 +00:00
Eduardo Broto
bff6c435ef Require or_patterns to suggest nesting them 2020-07-01 00:15:21 +02:00
Eduardo Broto
c5d8f530e0 Move blanket_clippy_restriction_lints to "style" 2020-06-30 21:56:19 +02:00
Eduardo Broto
814349f941 Lint enabling the whole restriction group 2020-06-30 21:56:19 +02:00
flip1995
1e861a2663
Merge remote-tracking branch 'upstream/master' into rustup2 2020-06-30 15:40:22 +02:00
Dylan MacKenzie
3c5ee3300f Update tests 2020-06-28 10:08:12 -07:00
bors
46d33043d5 Auto merge of #5701 - ebroto:4874_cmp_owned_fp, r=flip1995
cmp_owned: handle when PartialEq is not implemented symmetrically

changelog: Handle asymmetrical implementations of PartialEq in [`cmp_owned`].

Fixes #4874
2020-06-24 12:48:24 +00:00
bors
a14eab389f Auto merge of #5745 - montrivo:copy_on_clone, r=phansch
clone_on_copy - add machine applicability

Fix #4826.
Change the applicability of the lint clone_on_copy. Split a test file and run rustfix on the clone_on_copy part.

changelog: clone_on_copy - add machine applicability
2020-06-24 07:11:07 +00:00
Tim Nielens
6bf5434e19 copy_on_clone - add machine applicability 2020-06-24 01:01:44 +02:00
Eduardo Broto
b498e1d715 cmp_owned: reverse operands if necessary 2020-06-23 22:14:45 +02:00
Eduardo Broto
5987c7d404 cmp_owned: avoid FP when PartialEq is not implemented symmetrically 2020-06-23 22:14:45 +02:00
bors
583d644934 Auto merge of #5694 - wangtheo:issue-5626, r=matthiaskrgr
#5626: lint iterator.map(|x| x)

changelog: adds a new lint for iterator.map(|x| x) (see https://github.com/rust-lang/rust-clippy/issues/5626)

The code also lints for result.map(|x| x) and option.map(|x| x). Also, I'm not sure if I'm checking for type adjustments correctly and I can't think of an example where .map(|x| x) would apply type adjustments.
2020-06-23 15:59:27 +00:00
flip1995
80bcbf521c Merge commit 'c2c07fa9d095931eb5684a42942a7b573a0c5238' into clippyup 2020-06-23 17:05:22 +02:00
Philipp Krones
f562117788
Rollup merge of #5724 - ebroto:5697_const_result_option, r=Manishearth
redundant_pattern_matching: avoid non-`const fn` calls in const contexts

changelog: Avoid suggesting non-`const fn` calls in const contexts in [`redundant_pattern_matching`]

Fixes #5697
2020-06-23 14:39:49 +02:00
Philipp Krones
0799be7156
Rollup merge of #5712 - ijijn:master, r=flip1995
Remove `bar` from blacklisted names

changelog: Remove `bar` from blacklisted names
fixes #5225
2020-06-23 14:39:45 +02:00
Philipp Krones
9505919be5
Rollup merge of #5709 - ebroto:5389_ice, r=Manishearth
Fix ICE in consts::binop

changelog: Fix ICE in `consts::binop`

Fixes #5389
2020-06-23 14:39:43 +02:00
bors
c56c7e2d02 Auto merge of #5695 - esamudera:lint_mem_uninitialized, r=phansch,oli-obk
New lint: suggest `ptr::read` instead of `mem::replace(..., uninitialized())`

resolves: #5575

changelog: improvements to `MEM_REPLACE_WITH_UNINIT`:
- add a new test case in `tests/ui/repl_uninit.rs` to cover the case of replacing with `mem::MaybeUninit::uninit().assume_init()`.
- modify the existing `MEM_REPLACE_WITH_UNINIT` when replacing with `mem::uninitialized` to suggest using `ptr::read` instead.
- lint with `MEM_REPLACE_WITH_UNINIT` when replacing with `mem::MaybeUninit::uninit().assume_init()`
2020-06-23 05:14:21 +00:00
flip1995
018440c11e
Merge remote-tracking branch 'upstream/master' into rustup 2020-06-23 02:18:17 +02:00
Aaron Hill
e11b873c70 Stop using old version of syn in rustc-workspace-hack
None of the tools seem to need syn 0.15.35, so we can just build syn
1.0.

This was causing an issue with clippy's `compile-test` program: since
multiple versions of `syn` would exist in the build directory, we would
non-deterministically pick one based on filesystem iteration order. If
the pre-1.0 version of `syn` was picked, a strange build error would
occur (see
https://github.com/rust-lang/rust/pull/73594#issuecomment-647671463)

To prevent this kind of issue from happening again, we now panic if we
find multiple versions of a crate in the build directly, instead of
silently picking the first version we find.
2020-06-22 13:29:39 -04:00
Eduardo Broto
a7743e9084 redundant_pattern_matching: avoid non-const fn in const context 2020-06-17 00:32:47 +02:00
Ericko Samudera
8c1ee063bb mem_replace_with_uninit: suggest std::ptr::read 2020-06-17 01:26:37 +07:00
Iain Brandram-Adams
c020e45cd3 Update stderr to match, and reinforce comments 2020-06-14 12:40:36 +12:00
Teddy_Wang
40ee620e51 Added a lint for .map(|x| x) 2020-06-13 10:08:12 -04:00
Iain Brandram-Adams
f663a21c8f Remove bar from blacklisted names 2020-06-14 01:24:36 +12:00
Eduardo Broto
b21ef2b365 Fix ICE in consts::binop 2020-06-13 00:52:32 +02:00
Lzu Tao
c9bd35cac3 Migrate to numeric associated consts 2020-06-10 01:35:47 +00:00
Eduardo Broto
a083b84b78 if_same_then_else: don't assume multiplication is always commutative 2020-06-09 23:49:21 +02:00
Devin R
e521a4ed38 Add enough attrs to the test file so the fix compiles with no errors, fmt/clippy 2020-06-09 16:39:31 -04:00
Lzu Tao
8db24840f7 Merge commit 'ff0993c5e9162ddaea78e83d0f0161e68bd4ea73' into clippy 2020-06-09 14:36:01 +00:00
Devin R
288df59b25 Fix suggestion output, add run-rustfix to test file, stop sorting import segments duh 2020-06-08 16:00:33 -04:00
Devin R
8c5a5a92ec cleaned up import suggestion formatter, look into code reuse with wildcard impotrs 2020-06-08 16:00:33 -04:00
Devin R
d4f60b5ff4 wip: of handling nested import paths for multi-macro paths 2020-06-08 16:00:33 -04:00
Devin R
8bc106b29d fix some of the review, rename, fmt, refactor 2020-06-08 16:00:33 -04:00
Devin R
8ffbf6f94d use hashset not map for keeping track of seen macro refs
remove stdout, fix clippy warnings, fmtcar
2020-06-08 16:00:33 -04:00
Devin R
ede366be63 collected all the imports and names
how to compare macro to import path

add more imports to test
2020-06-08 16:00:30 -04:00
Devin R
a4b8bb88f2 warn on macro_use attr
cargo dev update lints

use if_chain

clean up alot, span_lint_and_sugg

find imported macros for sugg
2020-06-08 15:59:41 -04:00
bors
ff0993c5e9 Auto merge of #5692 - ebroto:5689_N_dotdot_N, r=yaahc
reversed_empty_ranges: avoid linting N..N except in for loop arguments

changelog: [`reversed_empty_ranges`]: avoid linting N..N except in for loop arguments

r? @yaahc
Fixes #5689
2020-06-08 17:15:45 +00:00
bors
f947644f0d Auto merge of #5680 - ebroto:3792_let_return, r=Manishearth
let_and_return: avoid "does not live long enough" errors

EDIT: Add #3324 to the list of fixes

<details>
<summary>Description of old impl</summary>
<br>
Avoid suggesting turning the RHS expression of the last statement into the block tail expression if a temporary borrows from a local that would be destroyed before.

This is my first incursion into MIR so there's probably room for improvement!
</details>

Avoid linting if the return type of some method or function called in the last statement has a lifetime parameter.

changelog: Fix false positive in [`let_and_return`]

Fixes #3792
Fixes #3324
2020-06-08 16:47:22 +00:00
Mazdak Farrokhzad
d6136b92a2
split unnested_or_patterns test 2020-06-07 21:16:05 +02:00
Mazdak Farrokhzad
7b6dc7b33d
add unnested_or_patterns lint 2020-06-07 21:09:47 +02:00
Eduardo Broto
ebfc1da07d reversed_empty_ranges: don't lint N..N except in for loop arg 2020-06-07 21:03:08 +02:00
Eduardo Broto
dac8a3c1ca let_and_return: do not lint if last statement borrows 2020-06-07 20:53:38 +02:00
Eduardo Broto
9c205d7b1b Rename let_and_return test for consistency with the lint name 2020-06-07 20:53:38 +02:00
flip1995
5bdbc45ae5
Rustup to rust-lang/rust#71796 2020-06-07 03:07:48 +02:00
Eduardo Broto
c325c120c2 Fix cargo ui tests when running inside rust repo 2020-06-05 22:30:14 +02:00
Lzu Tao
b39fd5f62f Fix false negative of checked_conversion lint 2020-06-03 09:04:24 +07:00
bors
153ef1c76f Auto merge of #5672 - phansch:regression-test-env, r=yaahc
Add regression test for `string_lit_as_bytes` issue

Closes #5619

Before the fix in https://github.com/rust-lang/rust/pull/72637, `string_lit_as_bytes` was incorrectly triggering on the `env!` macro. With the fix merged, this test makes sure that the lint is not triggering anymore.

changelog: none
2020-06-02 12:40:20 +00:00
bors
f760d77bdb Auto merge of #5597 - esamudera:slice_iter_next, r=flip1995
New lint: iter_next_slice

Hello, this is a work-in-progress PR for issue: https://github.com/rust-lang/rust-clippy/issues/5572

I have implemented lint to replace `iter().next()` for `slice[index..]` and `array` with `get(index)` and `get(0)` respectively. However since I made a lot of changes, I would like to request some feedback before continuing so that I could fix mistakes.

Thank you!

---

changelog: implement `iter_next_slice` lint and test, and modify `needless_continues`, `for_loop_over_options_result` UI tests since they have `iter().next()`
2020-06-02 11:42:22 +00:00
bors
bfafb8e0d6 Auto merge of #5673 - phansch:endless-loop, r=Manishearth
Add regression test for endless loop / update `pulldown_cmark`

Closes #4917

This was fixed in pulldown_cmark 0.7.1, specifically raphlinus/pulldown-cmark#438

changelog: none
2020-06-01 17:16:06 +00:00
Philipp Hansch
861b897c54
Add regression test for endless loop
This was fixed in pulldown_cmark 0.7.1, specifically
https://github.com/raphlinus/pulldown-cmark/pull/438
2020-06-01 10:20:17 +02:00
Philipp Hansch
ae0ce2255a
Add regression test for string_lit_as_bytes issue 2020-06-01 09:58:42 +02:00
bors
bee0608fad Auto merge of #5623 - JarredAllen:sort_by_key_reverse, r=phansch
New lint: Use Reverse with sort_by_key

Implements  #5578

changelog: New lint: [`unnecessary_sort_by`]
2020-06-01 07:43:16 +00:00
JarredAllen
9a5baed482 Implement suggestions from phansch 2020-05-31 15:09:12 -07:00
Ericko Samudera
32fde0b511 New lint: iter_next_slice 2020-06-01 03:08:51 +07:00
bors
9f9877c47f Auto merge of #5662 - ebroto:cargo_tests_invalid_crate, r=flip1995
cargo-ui tests: check that <dir>/src exists before processing test

I forgot that I had fixed this in a PR I closed some days ago (#5643).

Before this change, cargo UI tests could fail when switching between branches if the previous branch had a test that the current branch does not have. The directory is not removed when switching because an ignored `Cargo.lock` file exists, and the code was trying to reach `$DIR/src` unconditionally.

This change will just skip a directory that has no `src` subdirectory.

changelog: none
2020-05-31 19:12:00 +00:00
JarredAllen
20cb512e81 Updated test cases and formatted 2020-05-31 12:06:32 -07:00
JarredAllen
015ab9f925 Renamed to 2020-05-31 11:55:45 -07:00
JarredAllen
07886a9764 Detect also when works 2020-05-31 11:55:45 -07:00
JarredAllen
059e8edd15 Detect also a non-reversed comparison 2020-05-31 11:55:45 -07:00
JarredAllen
955a25ee7d Added negative test cases and ran cargo dev fmt 2020-05-31 11:55:45 -07:00
JarredAllen
943cb94dce Passes all tests now! 2020-05-31 11:55:45 -07:00
JarredAllen
8590ab4d46 More progress towards sort_by_key_reverse lint 2020-05-31 11:55:45 -07:00
JarredAllen
24847ea53e Attempted start at sort_by_key_reverse lint 2020-05-31 11:55:45 -07:00
JarredAllen
7e843515d9 Created lint 2020-05-31 11:55:45 -07:00
Eduardo Broto
14e9100543 cargo-ui tests: check that <dir>/src exists before processing test 2020-05-31 20:38:48 +02:00
flip1995
77dd0ea62a
Add tests for empty blocks 2020-05-31 19:29:36 +02:00
flip1995
6d15a14964
Update test files 2020-05-31 18:50:33 +02:00
flip1995
380d941a04
Adapt stderr and fixed files 2020-05-31 18:48:28 +02:00
Philipp Krones
00c656d8ee
Rollup merge of #5663 - matthiaskrgr:crash_test_3969, r=Manishearth
add testcase that no longer ICEs

Fixes #3969

changelog: none
2020-05-31 14:57:34 +02:00
Philipp Krones
873c9fc8f2
Rollup merge of #5656 - ebroto:len_zero_ranges, r=matthiaskrgr
len_zero: skip ranges if feature `range_is_empty` is not enabled

If the feature is not enabled, calling `is_empty()` on a range is ambiguous. Moreover, the two possible resolutions are unstable methods, one inherent to the range and the other being part of the `ExactSizeIterator` trait.

Since `len_zero` only checks for existing `is_empty()` inherent methods, we only take into account the `range_is_empty` feature.

Related: https://github.com/rust-lang/rust/issues/48111#issuecomment-445132965

changelog: len_zero: avoid linting ranges without #![feature(range_is_empty)]

Fixes: #3807
2020-05-31 14:57:33 +02:00