Commit Graph

4895 Commits

Author SHA1 Message Date
Matthias Krüger
c6412aeebc handle macros returning Strings in single_char_push_str and single_char_insert_str 2020-10-30 23:29:38 +01:00
Matthias Krüger
2350ee75b2 single_char_push_str lint using insert_str() on single-char literals and suggest insert()
changelog: single_char_push_str: lint using string.insert_str() with single char literals and suggests string.insert() with a char

Fixes #6026
2020-10-30 23:28:17 +01:00
bors
7387b87bb9 Auto merge of #6197 - ThibsG:ImproveFilterNext, r=ebroto
Improve suggestions for several lints

This PR is a follow-up of this [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/filter_next.20lint).

It unifies placeholders for `methods` module and improves several suggestions for `filter_next`, `filter_map_next` and `map_unwrap_or` lints.

changelog: none
2020-10-30 21:58:09 +00:00
Cameron Steffen
c0d1002d93 Fix unnecessary_lazy_eval suggestion applicability
Fixes #6240
2020-10-30 16:10:01 -05:00
bors
0be654482c Auto merge of #6229 - henil:improve-integer-division-lint, r=phansch
Update the existing arithmetic lint

re: #6209

Updates the lint to not the error message if RHS of binary operation `/` of `%` is a literal/constant that is not `0` or `-1`, as suggested [here](https://github.com/rust-lang/rust-clippy/issues/6209#issuecomment-715624354)

changelog: Expand [`integer_arithmetic`] to work with RHS literals and constants
2020-10-30 12:37:46 +00:00
henil
fa0a78b130 removed lint for division/modulo for literal 0 2020-10-30 17:31:10 +05:30
LeSeulArtichaut
1c8c3d14ef Remove implicit Continue type 2020-10-30 12:27:47 +01:00
LeSeulArtichaut
4a06145ced Use ControlFlow::is{break,continue} 2020-10-30 12:27:46 +01:00
LeSeulArtichaut
fa79cc4f6f TypeVisitor: use ControlFlow in clippy 2020-10-30 12:27:45 +01:00
bors
74d8fbb7a4 Auto merge of #6200 - rail-rain:borrowed_box_invalid_sugg, r=phansch
fix the error-causing suggestion of 'borrowed_box'

Fixes #3128

Fix the suggestion of 'borrowed_box', which causes a syntax error because it misses necessary parentheses.

---

changelog: Fix the error-causing suggestion of 'borrowed_box'
2020-10-30 10:40:44 +00:00
Tim Nielens
d780f61d7b add manual_ok_or / pr remarks 2020-10-29 19:08:54 +01:00
dvermd
230d9cbe36
Update clippy_lints/src/ref_option_ref.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-10-29 17:39:19 +01:00
bors
c57d8ae515 Auto merge of #6227 - HMPerson1:collect_map, r=phansch
Add lint for replacing `.map().collect()` with `.try_for_each()`

Fixes #6208

changelog: Add `map_collect_result_unit`
2020-10-29 15:34:15 +00:00
bors
e1a2845558 Auto merge of #6226 - Urcra:master, r=flip1995
Add lint for comparing to empty slices instead of using .is_empty()

Hey first time making a clippy lint

I added the implementation of the lint the `len_zero` since it shared a lot of the code, I would otherwise have to rewrite. Just tell me if the lint should use it's own file instead

changelog: Add lint for comparing to empty slices

Fixes #6217
2020-10-29 15:12:24 +00:00
bors
ee9da9a194 Auto merge of #6176 - achris:issues/578, r=phansch
Lint items after statements in local macro expansions

The items_after_statements lint was skipping all expansions.  Instead
we should still lint local macros.

Fixes #578

---

*Please keep the line below*
changelog: The items_after_statements now applies to local macro expansions
2020-10-29 14:51:41 +00:00
Christian Nielsen
e3de544c22
Remove empty lines in doc comment
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-10-29 15:49:42 +01:00
bors
e8de57c20d Auto merge of #6212 - ThibsG:MacroTopLevelRefArg, r=flip1995
No lint in macro for `toplevel_ref_arg`

Do not lint when the span is from a macro.

Question: shouldn't we extend this for external macros also ?

Fixes: #5849

changelog: none
2020-10-29 14:29:30 +00:00
henil
e97602e482 Update existing arithmetic lint and add new tests related to it. 2020-10-29 19:08:52 +05:30
Eduardo Broto
50419118b4 Merge commit '645ef505da378b6f810b1567806d1bcc2856395f' into clippyup 2020-10-28 23:36:07 +01:00
Eduardo Broto
a50d9e7af6 Deprecate temporary_cstr_as_ptr 2020-10-28 22:34:45 +01:00
Takayuki Nakata
8e988e1c66 Merge remote-tracking branch 'upstream/master' into sync-from-rust 2020-10-28 14:14:09 +09:00
Takayuki Nakata
4c58860cbf Fix suggestion to add unneeded space in unused_unit 2020-10-28 12:40:47 +09:00
Aleksei Latyshev
2b7dd31368
improve MATCH_LIKE_MATCHES_MACRO lint
- add tests
- refactor match_same_arms lint
- prioritize match_expr_like_matches_macro over match_same_arms
2020-10-27 23:45:58 +03:00
Aleksei Latyshev
09e7053607
simplify SpanlessEq::eq_path_segment 2020-10-27 20:44:41 +03:00
Michael Wright
f79c4afd3a Fix invalid paths 2020-10-27 07:43:38 +02:00
Michael Wright
66d56fefc5 Add invalid_paths internal lint 2020-10-27 07:42:13 +02:00
Tim Nielens
111b9023da add manual_ok_or lint 2020-10-27 01:57:04 +01:00
rail
e568a328f9 fix the error-causing suggestion of 'borrowed_box'
fix the error-causing suggestion of 'borrowed_box',
which missed parentheses and was ambiguous.
2020-10-27 12:11:09 +13:00
Nathan Whitaker
a1bb10e9b8 Remove lint from clippy 2020-10-26 18:19:48 -04:00
dvermd
8337c467e9 Change Applicability to MaybeIncorrect
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-10-26 22:34:43 +01:00
dvermd
ffddb669e0 clippy_lint: run after changing category to pendantic 2020-10-26 22:34:43 +01:00
dvermd
db40a07665 Update clippy_lints/src/ref_option_ref.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-10-26 22:34:43 +01:00
dvermd
7fd74c6bf6 clippy_lint: Add Known Problems message 2020-10-26 22:34:43 +01:00
dvermd
1566db704d Update clippy_lints/src/ref_option_ref.rs
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-10-26 22:34:43 +01:00
dvermd
8e26004a5f Update clippy_lints/src/ref_option_ref.rs doctest
Co-authored-by: Philipp Krones <hello@philkrones.com>
2020-10-26 22:34:43 +01:00
dvermd
b41b38cb7f clippy_lint: Refactor 'ref_option_ref' 2020-10-26 22:34:42 +01:00
dvermd
c1f3bab6b1 clippy_lint: Add 'ref_option_ref' remove unused import 2020-10-26 22:34:42 +01:00
dvermd
469b2fc781 clippy_lint: Add 'ref_option_ref' move to check_ty and add type alias test 2020-10-26 22:34:42 +01:00
dvermd
d1baa25f04 clippy_lint: Add 'ref_option_ref' refactor code 2020-10-26 22:34:42 +01:00
dvermd
213dbf7aac clippy_lint: Add 'ref_option_ref' 2020-10-26 22:34:40 +01:00
ThibsG
3fec6f568d Improve some suggestions for filter_map_next, filter_next and map_unwrap_or lints 2020-10-26 11:02:07 +01:00
ThibsG
2911d9c7de Use better placeholders for some methods lint messages 2020-10-26 11:02:07 +01:00
ThibsG
bab338685f No lint in external macro for toplevel_ref_arg 2020-10-26 10:14:03 +01:00
HMPerson1
f0cf3bdca1
Add lint for replacing .map().collect() with .try_for_each() 2020-10-25 21:20:57 -04:00
Urcra
45aa3ef8dd Remove unnecesary format 2020-10-26 01:55:44 +01:00
Urcra
4532dd9e43 run cargo fmt 2020-10-26 01:31:13 +01:00
Urcra
4cf5b5ff70 Run update lints 2020-10-26 01:21:34 +01:00
Urcra
deecfb5d13 Add description to lint 2020-10-26 01:02:10 +01:00
Urcra
4417af801d Revert changes to Cargo.toml file 2020-10-26 00:53:51 +01:00
Urcra
7f7faa1ccf Move implementation into len_zero.rs 2020-10-26 00:51:18 +01:00
Urcra
de5a6d3420 Initial implementation of comparison_to_empty 2020-10-26 00:31:25 +01:00
bors
83bb5ecec8 Auto merge of #6202 - giraffate:fix_invalid_suggestion_in_needless_collect_test, r=flip1995
Fix an invalid suggestion in `needless_collect` test

A test, https://github.com/rust-lang/rust-clippy/blob/master/tests/ui/needless_collect_indirect.rs#L11-L12, suggests following codes, but the suggested codes don't work. An example is here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6947d9f2806a83f41cc5eb8e39b09d0b.
```
error: avoid using `collect()` when not needed
  --> $DIR/needless_collect_indirect.rs:11:5
   |
LL | /     let indirect_contains = sample.iter().collect::<VecDeque<_>>();
LL | |     indirect_contains.contains(&&5);
   | |____^
   |
help: Check if the original Iterator contains an element instead of collecting then checking
   |
LL |
LL |     sample.iter().any(|x| x == &&5);
```

changelog: none
2020-10-25 17:35:33 +00:00
bors
15f6fb99e4 Auto merge of #6194 - giraffate:remove_an_extra_blank_line, r=flip1995
Remove an extra blank line in doc examples

It seems to be an extra blank line in doc example.

changelog: none

<img width="1141" alt="スクリーンショット 2020-10-19 10 32 21" src="https://user-images.githubusercontent.com/17407489/96392372-d0583200-11f6-11eb-9aab-f7e8f87eb04e.png">
2020-10-25 17:15:42 +00:00
bors
eceebc3448 Auto merge of #6183 - cgm616:hex_bin_digit_grouping, r=flip1995
Hex bin digit grouping

This revives and updates an old pr (#3391) for the current API.

Closes #2538.

---

*Please keep the line below*
changelog: Add [`unusual_byte_groupings`] lint.
2020-10-25 16:40:14 +00:00
flip1995
77746b9060
Merge remote-tracking branch 'upstream/master' into rustup 2020-10-25 16:43:53 +01:00
cgm616
312bbff696
Integrate suggestions from code review 2020-10-25 11:31:24 -04:00
Takayuki Nakata
3ce820bf83 Fix an invalid suggestion in needless_collect test 2020-10-25 23:58:14 +09:00
cgm616
e7e4b35bdf Fix logic mistake 2020-10-25 09:34:46 -04:00
cgm616
f5a88b6de5 Allow hex literals to pass w/ groups of 2 2020-10-25 09:18:38 -04:00
Florian Hartwig
db8380c4a0 Add lint for unusually-grouped hex/binary literals 2020-10-25 09:18:38 -04:00
bors
9c9aa2db52 Auto merge of #6222 - JohnTitor:redundant-local-def-id, r=flip1995
Remove redundant `expect_local()` call

The field `owner` of `HirId` is `LocalDefId` and `hir_id.owner.to_def_id().expect_local()` is redundant. I wonder they were introduced in some rustups.

changelog: none
2020-10-25 11:58:51 +00:00
bors
718bb28f68 Auto merge of #6211 - ThibsG:NeedlessBoolCfg, r=flip1995
No lint with `cfg!` and fix sugg for macro in `needless_bool` lint

Don't lint if `cfg!` macro is one of the operand.
Fix suggestion when the span originated from a macro, using `hir_with_macro_callsite`.

Fixes: #3973

changelog: none
2020-10-25 11:37:18 +00:00
bors
38be214724 Auto merge of #6198 - montrivo:needless-lifetime, r=flip1995
needless-lifetime / multiple where clause predicates regression

Closes #6159.

changelog: fix regression in needless-lifetimes
2020-10-25 11:15:01 +00:00
bors
90cb25d3f6 Auto merge of #6177 - rust-lang:manual-range-contains, r=flip1995
New lint: manual-range-contains

This fixes #1110, at least for the contains-suggesting part.

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`
---

changelog: new lint: manual-range-contains
2020-10-25 10:35:46 +00:00
Yuki Okushi
d5713898ac Remove redundant expect_local() call 2020-10-25 19:30:00 +09:00
bors
399732bf79 Auto merge of #6103 - FrancisMurillo:mut_mutex_lock, r=flip1995
Add lint for `&mut Mutex::lock`

Fixes #1765

changelog: Add lint [`mut_mutex_lock`] for `&mut Mutex::lock` and suggests using `&mut Mutex::get_mut` instead.
2020-10-25 10:16:23 +00:00
bors
fd62c180fe Auto merge of #6162 - josephlr:empty-loop-no-std, r=flip1995
Update empty_loop documentation/message.

Originally part of #6161, but now this PR only deals with `std` crates

This change:
  - Updates the `std` message .
  - Updates the docs to mention how the busy loops should be fixed
    - Gives examples of how to do this for `no_std` targets
  - Updates the tests/stderr files to test this change.

changelog: Update `empty_loop` lint documentation
2020-10-25 09:56:16 +00:00
Yuki Okushi
df85532112 Rollup merge of #78326 - Aaron1011:fix/min-stmt-lints, r=petrochenkov
Split out statement attributes changes from #78306

This is the same as PR https://github.com/rust-lang/rust/pull/78306, but `unused_doc_comments` is modified to explicitly ignore statement items (which preserves the current behavior).

This shouldn't have any user-visible effects, so it can be landed without lang team discussion.

---------
When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306
2020-10-25 18:43:49 +09:00
Francis Murillo
e7e03b7912 Change from correctness to style and MaybeIncorrect instead of MachineApplicable 2020-10-25 17:41:30 +08:00
Francis Murillo
292cb9bfb6 Use sugg_lint_and_help 2020-10-25 17:41:30 +08:00
Francis Murillo
77e34a69bb Inline is_mut_mutex_lock_call 2020-10-25 17:41:30 +08:00
Francis Murillo
ec0c3afa73 Run update_lints 2020-10-25 17:41:30 +08:00
Francis Murillo
fb8a9cb38d Change lint doc test 2020-10-25 17:41:24 +08:00
bors
6b01c39e64 Auto merge of #6181 - cgm616:undropped-manually-drops, r=flip1995
Add new lint for undropped ManuallyDrop values

Adds a new lint for the following code:

```rust
struct S;

impl Drop for S {
    fn drop(&mut self) {
        println!("drip drop");
    }
}

fn main() {
    // This will not drop the `S`!!!
    drop(std::mem::ManuallyDrop::new(S));
    unsafe {
        // This will.
        std::mem::ManuallyDrop::drop(&mut std::mem::ManuallyDrop::new(S));
    }
}
```

The inner value of a `ManuallyDrop` will not be dropped unless the proper, unsafe drop function is called on it. This lint makes sure that a user does not accidently use the wrong function and forget to drop a `ManuallyDrop` value.

Fixes #5581.

---

*Please keep the line below*
changelog: none
2020-10-25 09:37:09 +00:00
Francis Murillo
f82f9c2c55 Add lint for &mut Mutex::lock 2020-10-25 17:18:52 +08:00
bors
e0e617adaa Auto merge of #6109 - patrickelectric:single_element_for_check, r=flip1995
Add linter for a single element for loop

changelog: Fixes #1540, check for vectors that contain a single element in a for loop
2020-10-25 09:15:55 +00:00
bors
a675778cfb Auto merge of #6029 - Daniel-B-Smith:refcell_ref_await, r=flip1995
Add lint for holding RefCell Ref across an await

Fixes #6008

This introduces the lint await_holding_refcell_ref. For async functions, we iterate
over all types in generator_interior_types and look for `core::cell::Ref` or `core::cell::RefMut`. If we find one then we emit a lint.

Heavily cribs from: https://github.com/rust-lang/rust-clippy/pull/5439

changelog: introduce the await_holding_refcell_ref lint
2020-10-25 08:54:27 +00:00
bors
b06856eae0 Auto merge of #6187 - geoffreycopin:master, r=ebroto
Lint unnecessary int-to-int and float-to-float casts

This is an implementation of a lint that detects unnecessary casts of number literals, as discussed here:
https://github.com/rust-lang/rust-clippy/issues/6116

---

changelog: lint unnecessary as-casts of literals when they could be written using literal syntax.
2020-10-24 23:29:49 +00:00
bors
29979ad043 Auto merge of #6190 - montrivo:manual_result_unwrap_or, r=ebroto
manual_unwrap_or / support Result::unwrap_or

Implements partially #5923.

changelog: support Result::unwrap_or in manual_unwrap_or
2020-10-24 23:09:14 +00:00
Cauê Baasch de Souza
e8731a926c Add large_types_passed_by_value lint
Refactor trivially_copy_pass_by_ref and the new lint into pass_by_ref_or_value module

Update stderr of conf_unknown_key test

Rename lint to large_types_passed_by_value

Increase `pass_by_value_size_limit` default value to 256

Improve rules for `large_types_passed_by_value`

Improve tests for `large_types_passed_by_value`

Improve documentation for `large_types_passed_by_value`

Make minor corrections to pass_by_ref_or_value.rs suggested by clippy itself

Fix `large_types_passed_by_value` example and improve docs

pass_by_ref_or_value: Tweak check for mut annotation in params

large_types_passed_by_value: add tests for pub trait, trait impl and inline attributes
2020-10-24 14:46:56 -03:00
Aaron Hill
33f3cfcadc Fix inconsistencies in handling of inert attributes on statements
When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306
2020-10-24 11:55:48 -04:00
Tim Nielens
0d21ae0e19 manual-unwrap-or / pr remarks, round 3 2020-10-24 11:35:05 +02:00
ThibsG
62f60e1ae5 No lint with cfg! and fix sugg for macro in needless_bool lint 2020-10-24 09:37:23 +02:00
Geoffrey Copin
d46edd9966 Keep sign in int-to-float casts 2020-10-24 00:04:37 +02:00
Eduardo Broto
6caeed1bfa Remove duplicate import of Target 2020-10-23 23:45:37 +02:00
Eduardo Broto
cdb555f4fc Merge commit 'bf1c6f9871f430e284b17aa44059e0d0395e28a6' into clippyup 2020-10-23 22:16:59 +02:00
Joe Richey
3807634a47
clippy_lints: Update empty_loop lint
We also update the documentation to note that the remediations are
different for `std` and `no_std` crates.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-10-22 22:03:13 -07:00
Geoffrey Copin
02f01104bf Add test case for negative literals 2020-10-23 00:04:27 +02:00
Geoffrey Copin
e8f12d2f02 Address review comments 2020-10-22 23:56:49 +02:00
Tim Nielens
6533d8becf manual-unwrap-or / pr remarks, round 2 2020-10-22 23:39:59 +02:00
Andre Bogus
c693de350a New lint: manual-range-contains 2020-10-22 08:45:21 +02:00
cgm616
e70817e712 Update tests and add known problems to docs 2020-10-21 21:21:11 -04:00
cgm616
4a4f998c39 Add new lint for undropped ManuallyDrop values 2020-10-21 21:21:11 -04:00
Daniel Smith
86f2b29d2f Merge lints into one pass 2020-10-21 11:04:26 -04:00
Daniel Smith
d8c6bce440 Convert the await holding lints to correctness 2020-10-21 11:04:26 -04:00
Daniel Smith
ee20ebadaf Move refcell lint into shared module 2020-10-21 11:04:26 -04:00
Daniel Smith
3ed69cdb13 Move existing lint into shared file 2020-10-21 11:04:26 -04:00
Daniel Smith
57bf80f776 Add lint for holding RefCell Ref across an await 2020-10-21 11:04:26 -04:00
Tim Nielens
65b52d84f8 needless-lifetime / multiple where clause predicates regression 2020-10-20 00:42:00 +02:00
bors
eaffd0e418 Auto merge of #6167 - ThibsG:IdenticalArgumentsAssertEq3574, r=ebroto
Identical arguments on assert macro family

Lint when identical args are used on `assert_eq!`, `debug_assert_eq!`, `assert_ne!` and `debug_assert_ne!` macros.

Added to the lint `eq_op`.

Common functions added to `utils/higher.rs`

Fixes: #3574
Fixes: #4694

changelog: Lint on identical args when calling `assert_eq!`, `debug_assert_eq!`, `assert_ne!` and `debug_assert_ne!` macros
2020-10-19 19:50:12 +00:00