Commit graph

3733 commits

Author SHA1 Message Date
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
cgm616 312bbff696
Integrate suggestions from code review 2020-10-25 11:31:24 -04:00
Takayuki Nakata 2f5d418011 Add test case 2020-10-26 00:01:20 +09:00
Takayuki Nakata 3ce820bf83 Fix an invalid suggestion in needless_collect test 2020-10-25 23:58:14 +09:00
cgm616 0c0f8db347 Remove accidental test inclusion 2020-10-25 09:19:58 -04:00
Florian Hartwig db8380c4a0 Add lint for unusually-grouped hex/binary literals 2020-10-25 09:18:38 -04: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
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
Francis Murillo 292cb9bfb6 Use sugg_lint_and_help 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
Geoffrey Copin 71ac0c0be8 Keep separators in cast_size_32bits stderr 2020-10-24 14:08:53 +02: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 d17edaa152 Merge remote-tracking branch 'upstream/master' into rustup 2020-10-23 14:37:17 +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 30f80c3b8c Fix test file 2020-10-23 00:33:15 +02: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
Tim Nielens f2da0c701e manual-unwrap-or / pr remarks 2020-10-22 22:46:10 +02:00
varkor fcde7683fe Fix clippy tests 2020-10-22 13:23:14 +01: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 4d3322525d Separate tests for each lint 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 b3a427d873 Add another test case 2020-10-21 11:04:26 -04:00
Daniel Smith 0f4abbf99a Better naming post copy/paste 2020-10-21 11:04:26 -04:00
Daniel Smith 8727169f72 fmt 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
ThibsG 16b5f37b5a Split eq_op ui tests to avoid file limit error in CI 2020-10-19 17:36:48 +02:00
Patrick José Pereira ba1ca19c3b tests: if_same_then_else2: Ignore single_element_loop lint
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2020-10-19 09:53:35 -03:00
Patrick José Pereira ec23db9496 Add linter for a single element for loop
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2020-10-19 09:53:35 -03:00
Tim Nielens 915ce36087 manual_unwrap_or / support Result::unwrap_or 2020-10-18 01:18:59 +02:00
Geoffrey Copin bb0ce32423 Lint unnecessary int-to-int and float-to-float casts 2020-10-17 16:12:51 +02:00
bors 4e83a38618 Auto merge of #6123 - montrivo:less_concise_than, r=ebroto
add lint manual_unwrap_or

Implements partially #5923.

changelog: add lint manual_unwrap_or
2020-10-16 20:43:45 +00:00