Commit graph

3264 commits

Author SHA1 Message Date
Eduardo Broto
3b58d66b22 Add the manual_async_fn lint 2020-05-07 21:42:40 +02:00
Oliver Scherer
780a63a1ba Update ui tests 2020-05-05 15:11:59 +02:00
Vadim Petrochenkov
2d10babb71 Stabilize fn-like proc macros in expression, pattern and statement positions 2020-05-03 19:24:41 +03:00
bors
76ddac5e8e Auto merge of #5560 - CrazyRoka:fix-match-on-vector-full-range, r=phansch,flip1995
Fix match on vec items: match on vec[..]

- Added new tests
- Fixed false positive when matching on full range, which will never panic

Closes #5551
changelog: fix match_on_vec_items when matching full range
2020-05-02 16:13:02 +00:00
bors
75a717159d Auto merge of #5558 - ThibsG:FixUnwrapInArgs, r=flip1995
Fix `unnecessary_unwrap` lint when checks are done in parameters

Fixes a false positive in `unnecessary_unwrap` lint when checks are done in macro parameters.

FIxes #5174

changelog: Fixes a false positive in `unnecessary_unwrap` lint when checks are done in macro parameters.
2020-05-02 15:59:18 +00:00
bors
60538d6c8e Auto merge of #5559 - alex-700:fix-while-let-on-iterator-fp, r=flip1995
Fix FP on while-let-on-iterator

- fix `is_refutable` for slice patterns
- fix `is_refutable` for bindings
- add some TODO-s for cases, which can not be fixed easily

fixes #3780

changelog: fix FP on while-let-on-iterator for arrays and bindings
2020-05-02 15:30:58 +00:00
bors
cc9088f287 Auto merge of #5550 - ebroto:manual_non_exhaustive, r=flip1995
Implement the manual_non_exhaustive lint

Some implementation notes:
* Not providing automatic fixups because additional changes may be needed in other parts of the code, e.g. when constructing a struct.
* Even though the attribute is valid on enum variants, it's not possible to use the manual implementation of the pattern because the visibility is always public, so the lint ignores enum variants.
* Unit structs are also ignored, it's not possible to implement the pattern manually without fields.
* The attribute is not accepted in unions, so those are ignored too.
* Even though the original issue did not mention it, tuple structs are also linted because it's possible to apply the pattern manually.

changelog: Added the manual non-exhaustive implementation lint

Closes #2017
2020-05-02 13:53:39 +00:00
CrazyRoka
e7138e0629 Fix match on vec items: match on vec[..]
- Added new tests
- Fixed false positive when matching on full range, which will never panic
2020-05-02 14:25:45 +03:00
Aleksei Latyshev
d0c1f8ada2
fix fp on while-let-on-iterator
- fix `is_refutable` for slice patterns
- fix `is_refutable` for bindings
- add some TODO-s for cases, which can not be fixed easily
2020-05-02 14:21:29 +03:00
ThibsG
72ce6d5be9 Fix unwrap lint when checks are done in parameters 2020-05-02 13:03:11 +02:00
bors
e3b8c41d0d Auto merge of #5536 - rail-rain:fix_manual_memcpy, r=phansch
Fix the bugs of `manual_memcpy`, simplify the suggestion and refactor it

While I’m working on the long procrastinated work to expand `manual_memcpy`(#1670), I found a few minor bugs and probably unidiomatic or old coding style. There is a brief explanation of changes to the behaviour this PR will make below. And, I have a questoin: do I need to add tests for the first and second fixed bugs? I thought it might be too rare cases to include the tests for those. I added for the last one though.

* Bug fix
  * It negates resulted offsets (`src/dst_offset`) when `offset` is subtraction by 0. This PR will remove any subtraction by 0 as a part of minification.

    ```rust
    for i in 0..5 {
        dst[i - 0] = src[i];
    }
    ```

    ```diff
     warning: it looks like you're manually copying between slices
       --> src/main.rs:2:14
        |
    LL  |     for i in 0..5 {
    -   |              ^^^^ help: try replacing the loop by: `dst[..-5].clone_from_slice(&src[..5])`
    +   |              ^^^^ help: try replacing the loop by: `dst[..5].clone_from_slice(&src[..5])`
        |
    ```
  * It prints `RangeTo` or `RangeFull` when both of `end` and `offset` are 0, which have different meaning. This PR will print 0. I could reject the cases `end` is 0, but I thought I won’t catch other cases `reverse_range_loop` will trigger, and it’s over to catch every such cases.

    ```rust
    for i in 0..0 {
        dst[i] = src[i];
    }
    ```

    ```diff
     warning: it looks like you're manually copying between slices
       --> src/main.rs:2:14
        |
     LL |     for i in 0..0 {
    -   |              ^^^^ help: try replacing the loop by: `dst.clone_from_slice(&src[..])`
    +   |              ^^^^ help: try replacing the loop by: `dst[..0].clone_from_slice(&src[..0])`
        |
    ```
  * it prints four dots when `end` is `None`. This PR will ignore any `for` loops without `end` because a `for` loop that takes `RangeFrom` as its argument and contains indexing without the statements or the expressions that end loops such as `break` will definitely panic, and `manual_memcpy` should ignore the loops with such control flow.

    ```rust
    fn manual_copy(src: &[u32], dst: &mut [u32]) {
        for i in 0.. {
            dst[i] = src[i];
        }
    }
    ```

    ```diff
    -warning: it looks like you're manually copying between slices
    -  --> src/main.rs:2:14
    -   |
    -LL |     for i in 0.. {
    -   |              ^^^ help: try replacing the loop by: `dst[....].clone_from_slice(&src[....])`
    -   |
    ```
* Simplification of the suggestion

  * It prints 0 when `start` or `end` and `offset` are same (from #3323). This PR will use `RangeTo`

changelog: fixed the bugs of `manual_memcpy` and also simplify the suggestion.
2020-05-02 08:11:48 +00:00
Eduardo Broto
42b0b4754c Apply suggestions from PR review 2020-05-01 22:37:14 +02:00
Eduardo Broto
f072ded3bf Implement the manual_non_exhaustive lint 2020-05-01 02:10:16 +02:00
rail
461f4a3466 Add missing tests 2020-04-30 17:32:37 +12:00
CrazyRoka
20c069beec Fixed incorrect suggestion of clone_double_ref lint
- Added `<_>` to suggestion
- Changed help message
2020-04-29 22:40:57 +03:00
flip1995
cd3480991a
Rustup to rust-lang/rust#71518 2020-04-29 15:48:43 +02:00
Eduardo Broto
fc5fc6378c Test that we lint the awaited expression 2020-04-27 21:29:31 +02:00
Eduardo Broto
3a96f548d1 used_underscore_binding: do not lint on await desugaring 2020-04-27 21:20:08 +02:00
rail
be9f7c2b6d Merge branch 'master' into fix_manual_memcpy 2020-04-27 19:52:49 +12:00
rail
75ad839cd2 Do not trigger manual_memcpy for RangeTo 2020-04-27 18:04:37 +12:00
bors
d13ffbe3fe Auto merge of #5522 - CrazyRoka:match_vec_item, r=phansch
New  lint `match_vec_item`

Added new lint to warn a match on index item which can panic. It's always better to use `get(..)` instead.
Closes #5500
changelog: New lint `match_on_vec_items`
2020-04-27 06:02:05 +00:00
rail
37261a904c Print 0 when end and offset is 0, and also simplify the suggestion 2020-04-27 17:51:01 +12:00
Eduardo Broto
303e7d1af8 Split tests in unix/non-unix 2020-04-26 21:27:29 +02:00
Eduardo Broto
4a405c9977 Remove some OSes from the test to comply with stderr line limit 2020-04-26 21:27:29 +02:00
Eduardo Broto
ce50e42ed6 Use the span of the attribute for the error message 2020-04-26 21:27:29 +02:00
Eduardo Broto
d24a106395 Apply suggestions from PR review
- Show just one error message with multiple suggestions in case of
  using multiple times an OS in target family position
- Only suggest #[cfg(unix)] when the OS is in the Unix family
- Test all the operating systems
2020-04-26 21:27:29 +02:00
Eduardo Broto
149f6d6046 Implement mismatched_target_os lint 2020-04-26 21:27:29 +02:00
CrazyRoka
940c662654 Small lint update
- Changed lint category to `correctness`
- Moved main function to bottom in test file
- Added `FIXME` comment to `span_lint_and_sugg` to improve later
2020-04-26 18:00:51 +03:00
bors
07dd5fada9 Auto merge of #5511 - alex-700:fix-redundant-pattern-matching, r=flip1995
Fix redundant_pattern_matching lint

fixes #5504

changelog: Fix suggestion in `redundant_pattern_matching` for macros.
2020-04-25 21:41:56 +00:00
bors
44eb953adc Auto merge of #5525 - flip1995:issue_1654, r=phansch
Don't trigger while_let_on_iterator when the iterator is recreated every iteration

r? @phansch

Fixes #1654

changelog: Fix false positive in [`while_let_on_iterator`]
2020-04-25 21:29:03 +00:00
bors
a76bfd46c5 Auto merge of #5530 - ebroto:issue_5524, r=flip1995
map_clone: avoid suggesting `copied()` for &mut

changelog: map_clone: avoid suggesting `copied()` for &mut

Fixes #5524
2020-04-25 21:16:06 +00:00
Eduardo Broto
806d973adc map_clone: avoid suggesting copied() for &mut 2020-04-25 22:52:19 +02:00
Aleksei Latyshev
69fe6b4c98
fix redundant_pattern_matching lint
- now it gives correct suggestion in case of macros
- better tests
- remove a couple of non-relevant tests
2020-04-25 23:51:30 +03:00
Philipp Krones
9b882bab26
Rollup merge of #5523 - phansch:add-new-ret-no-self-testcase, r=flip1995
Add lifetime test case for `new_ret_no_self`

cc https://github.com/rust-lang/rust-clippy/issues/734#issuecomment-619344352

changelog: none
2020-04-25 21:06:31 +02:00
Philipp Krones
e1d13c34b0
Rollup merge of #5408 - dtolnay:matchbool, r=flip1995
Downgrade match_bool to pedantic

I don't quite buy the justification in https://rust-lang.github.io/rust-clippy/. The justification is:

> It makes the code less readable.

In the Rust codebases I've worked in, I have found people were comfortable using `match bool` (selectively) to make code more readable. For example, initializing struct fields is a place where the indentation of `match` can work better than the indentation of `if`:

```rust
let _ = Struct {
    v: {
        ...
    },
    w: match doing_w {
        true => ...,
        false => ...,
    },
    x: Nested {
        c: ...,
        b: ...,
        a: ...,
    },
    y: if doing_y {
        ...
    } else { // :(
        ...
    },
    z: ...,
};
```

Or sometimes people prefer something a bit less pithy than `if` when the meaning of the bool doesn't read off clearly from the condition:

```rust
if set.insert(...) {
    ... // ???
} else {
    ...
}

match set.insert(...) {
    // set.insert returns false if already present
    false => ...,
    true => ...,
}
```

Or `match` can be a better fit when the bool is playing the role more of a value than a branch condition:

```rust
impl ErrorCodes {
    pub fn from(b: bool) -> Self {
        match b {
            true => ErrorCodes::Yes,
            false => ErrorCodes::No,
        }
    }
}
```

And then there's plain old it's-1-line-shorter, which means we get 25% more content on a screen when stacking a sequence of conditions:

```rust
let old_noun = match old_binding.is_import() {
    true => "import",
    false => "definition",
};
let new_participle = match new_binding.is_import() {
    true => "imported",
    false => "defined",
};
```

Bottom line is I think this lint fits the bill better as a pedantic lint; I don't think linting on this by default is justified.

changelog: Remove match_bool from default set of enabled lints
2020-04-25 21:06:26 +02:00
flip1995
a1826222cf
Add tests for #1654 2020-04-25 20:51:23 +02:00
flip1995
dda1c8d8af
Update issue_2356.stderr reference file 2020-04-25 20:11:15 +02:00
flip1995
44511d5ee6
Update while_let_on_iterator tests 2020-04-25 20:11:15 +02:00
Philipp Hansch
bf73d51959
Add lifetime test case for new_ret_no_self 2020-04-25 10:43:41 +02:00
CrazyRoka
63b451ea25 Renamed lint to match_on_vec_items 2020-04-25 11:34:16 +03:00
CrazyRoka
b0115fb996 Removed unnecessary code, added support for vector references 2020-04-25 00:52:02 +03:00
CrazyRoka
96e2bc80f5 Added lint match_vec_item 2020-04-24 22:45:15 +03:00
David Tolnay
ef28361293
Downgrade match_bool to pedantic 2020-04-23 16:30:06 -07:00
Andy Weiss
d6e55e97ff Make lint also capture blocks and closures, adjust language to mention other mutex types 2020-04-21 21:07:43 -07:00
Andy Weiss
6c25c3c381 Lint for holding locks across await points
Fixes #4226

This introduces the lint await_holding_lock. For async functions, we iterate
over all types in generator_interior_types and look for types named MutexGuard,
RwLockReadGuard, or RwLockWriteGuard. If we find one then we emit a lint.
2020-04-21 21:07:43 -07:00
Matthias Krüger
7221db2dc3 fix crash on issue-69020-assoc-const-arith-overflow.rs
Fixes #5497
2020-04-20 23:01:34 +02:00
bors
6ce05bf849 Auto merge of #5332 - DevinR528:if-let-else-mutex, r=flip1995
If let else mutex

changelog: Adds lint to catch incorrect use of `Mutex::lock` in `if let` expressions with lock calls in any of the blocks.

closes: #5219
2020-04-20 20:21:33 +00:00
Devin R
3fbe321440 update stderr file 2020-04-20 15:47:08 -04:00
Devin R
489dd2e504 factor ifs into function, add differing mutex test 2020-04-20 15:08:44 -04:00
Devin R
a9f1bb43ef test for mutex eq, add another test case 2020-04-20 06:30:01 -04:00
Devin R
c6c77d9a42 use Visitor api to find Mutex::lock calls 2020-04-20 06:30:00 -04:00
Devin R
fca3537fa3 add note about update-all-refs script, revert redundant pat to master 2020-04-20 06:30:00 -04:00
Devin R
51c2325dd7 move closures to seperate fns, remove known problems 2020-04-20 06:30:00 -04:00
Devin R
40bbdffc89 use span_lint_and_help, cargo dev fmt 2020-04-20 06:30:00 -04:00
Devin R
139e2c6227 creating suggestion 2020-04-20 06:30:00 -04:00
Devin R
001a42e632 progress work on suggestion for auto fix 2020-04-20 06:29:59 -04:00
Eduardo Broto
00b4f2819f Implement unsafe_derive_deserialize lint 2020-04-19 23:26:17 +02:00
bors
6dcc8d5038 Auto merge of #5141 - xiongmao86:issue5095, r=flip1995
Fixes issue 5095

fixes #5095.

- [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`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

changelog: (internal) warn about collapsible `span_lint_and_then` calls.
2020-04-19 19:19:54 +00:00
flip1995
7aeb3a43c9
Update empty_enum.stderr 2020-04-19 21:00:25 +02:00
bors
2efc2d6366 Auto merge of #5491 - smklein:borrowed_box, r=flip1995
Fix issue #2907.

Update the "borrow box" lint to avoid recommending the following
conversion:

```
  // Old
  pub fn f(&mut Box<T>) {...}

  // New
  pub fn f(&mut T) {...}
```

Given a mutable reference to a box, functions may want to change
"which" object the Box is pointing at.

This change avoids recommending removing the "Box" parameter
for mutable references.

changelog: Don't trigger [`borrow_box`] lint on `&mut Box` references
2020-04-19 18:59:23 +00:00
Sean Klein
0ef5dee3b8 Fix issue #2907.
Update the "borrow box" lint to avoid recommending the following
conversion:

```
  // Old
  pub fn f(&mut Box<T>) {...}

  // New
  pub fn f(&mut T) {...}
```

Given a mutable reference to a box, functions may want to change
"which" object the Box is pointing at.

This change avoids recommending removing the "Box" parameter
for mutable references.
2020-04-19 10:56:15 -04:00
Shotaro Yamada
554f47bb48 Don't trigger toplevel_ref_arg for for loops 2020-04-19 22:56:47 +09:00
xiongmao86
d7f1a1ed2b Change note_span argument for span_lint_and_note. 2020-04-18 18:29:36 +08:00
xiongmao86
cf4e35339b Add an Option<Span> argument to span_lint_and_help. 2020-04-18 18:28:29 +08:00
xiongmao86
bdd32e7700 Implement collapsible_span_lint_calls lint. 2020-04-18 18:13:50 +08:00
pmk21
1c1103561e Polished lint and tests 2020-04-18 12:03:52 +05:30
pmk21
4d03b4d2f0 Added final lint and tests 2020-04-18 12:02:13 +05:30
pmk21
7c52e51d79 Added basic lint and tests 2020-04-18 11:39:54 +05:30
Aleksei Latyshev
092c4595fe
fix redundant_pattern_matching lint
- now it handles `while let` case
- better suggestions in `if let` case
2020-04-17 21:51:07 +03:00
bors
f1fb815603 Auto merge of #5423 - rkuhn:add_futures_not_send, r=flip1995
add lint futures_not_send

changelog: add lint futures_not_send

fixes #5379

~Remark: one thing that can (should?) still be improved is to directly include the error message from the `Send` check so that the programmer stays in the flow. Currently, getting the actual error message requires a restructuring of the code to make the `Send` constraint explicit.~
It now shows all unmet constraints for allowing the Future to be Send.
2020-04-17 16:04:14 +00:00
Roland Kuhn
d2cbbff217 add lint futures_not_send 2020-04-17 13:54:05 +02:00
logan-dev-oss
9c89cf00c0 Fix issue #4892. 2020-04-17 09:27:54 +02:00
Shotaro Yamada
f58bb5b234 question_mark: don't add as_ref() for a call expression 2020-04-17 13:09:02 +09:00
bors
adf7c505e6 Auto merge of #5476 - ThibsG:FixMatchesInExternalMacros, r=flip1995
Do not lint in macros for match lints

Don't lint in macros for match lints, more precisely in `check_pat` and `check_local` where it was not the case.

changelog: none

fixes: #5362
2020-04-16 20:51:56 +00:00
ThibsG
7fb94c2ac9 Do not lint in macros for match lints 2020-04-16 14:57:12 +02:00
Marcin Serwin
72a8fc24e6 Add test to map_flatten with an Option 2020-04-16 08:00:32 +02:00
Philipp Krones
19183a6af5
Rollup merge of #5468 - Toxyxer:zero-single-char-names, r=flip1995
Zero single char names

Fixes: #4086

changelog:
- Make the inequality strict
2020-04-15 20:12:31 +02:00
Philipp Krones
071a5904eb
Rollup merge of #5466 - phansch:large-enum-variant-output, r=flip1995
large_enum_variant: Report sizes of variants

This reports the sizes of the largest and second-largest variants.

Closes #5459

changelog: `large_enum_variant`: Report the sizes of the largest and second-largest variants.
2020-04-15 20:12:30 +02:00
Philipp Krones
2538e63885
Rollup merge of #5430 - michaelsproul:integer-arithmetic, r=flip1995
Disallow bit-shifting in integer_arithmetic

Make the `integer_arithmetic` lint detect all the operations that are defined as being capable of overflow in the [Rust Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow), by also linting for bit-shifting operations (`<<`, `>>`).

changelog: Disallow bit-shifting in `integer_arithmetic`
2020-04-15 20:12:29 +02:00
Philipp Krones
ceea3c6a35
Rollup merge of #5248 - ThibsG:ConstValues, r=flip1995
Add lint on large non scalar const

This PR adds the new lint `non_scalar_const` that aims to warn against `const` declaration of large arrays. For performance, because of inlining, large arrays should be preferably declared as `static`.

Note: i made this one to warn on all const arrays, whether they are in a body function or not. I don't know if this is really necessary, i could just reduce this lint to variables out of function scope.

Fixes: #400

changelog: add new lint for large non-scalar types declared as const
2020-04-15 20:12:28 +02:00
ThibsG
3c2bbcf00e Better precedence case management + more tests 2020-04-15 17:18:12 +02:00
ThibsG
72b9ae2a10 Use only check_expr with parent expr and precedence 2020-04-15 17:18:12 +02:00
ThibsG
b6d4330550 Check for Deref trait impl + add fixed version 2020-04-15 17:18:12 +02:00
ThibsG
c1132434a7 Report using stmts and expr + tests 2020-04-15 17:18:12 +02:00
ThibsG
6b4ab82746 Global rework + fix imports 2020-04-15 17:18:12 +02:00
Tom Milligan
b2d986850d Working basic dereference clip 2020-04-15 17:18:12 +02:00
Marcin Serwin
512f23fff1 Add test for zero single char names 2020-04-15 13:35:44 +02:00
Philipp Hansch
69c3e9c90f
large_enum_variant: Report sizes of variants
This reports the sizes of the largest and second-largest variants.
2020-04-15 09:56:32 +02:00
bors
a96f874301 Auto merge of #5345 - Toxyxer:add-lint-for-float-in-array-comparison, r=flip1995
Add lint for float in array comparison

Fixes #4277
changelog:
- Added new handler for expression of index kind (e.g. `arr[i]`). It returns a constant when both array and index are constant, or when the array is constant and all values are equal.
- Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities.
- Added appropriate tests for such cases.
2020-04-15 06:39:11 +00:00
bors
3c77188c04 Auto merge of #5460 - phansch:fix_incorrect_tests, r=matthiaskrgr
result_map_unit_fn: Fix incorrect UI tests

`x` and the `HasResult` struct were missing in this file.

changelog: none
2020-04-14 19:33:11 +00:00
bors
74e92566d5 Auto merge of #5453 - rabisg0:fix/redundant_clone, r=phansch
Fixes #5405: redundant clone false positive with arrays

Check whether slice elements implement Copy before suggesting to drop
the clone method

changelog: add a check for slice indexing on redundant_clone lint
2020-04-14 05:59:26 +00:00
Philipp Hansch
a4deb5aca5
Explain panic on E0463 in integration tests 2020-04-13 22:12:57 +02:00
Philipp Hansch
9a52d52068
result_map_unit_fn: Fix incorrect UI tests
`x` and the `HasResult` struct were missing in this file.
2020-04-13 15:26:53 +02:00
Rabi Guha
ab3946d7e9 Fixes #5405: redundant clone false positive with arrays
Check whether slice elements implement Copy before suggesting to drop
the clone method
2020-04-13 11:43:42 +05:30
Michael Sproul
23df4a0183
Disallow bit-shifting in integer_arithmetic lint
With this change, the lint checks all operations that are defined as
being capable of overflow in the Rust Reference.
2020-04-13 13:23:59 +10:00
Dan B
a296058e50 Allow UUID style formatting for inconsistent_digit_grouping lint
This change adds a check to the `inconsistent_digit_grouping` to add a check for
NumericLiterals that follow the UUID format of 8-4-4-4-12.

If the NumericLiteral matches the UUID format, no further inconsistent grouping checks
will be performed.

Closes #5431
2020-04-12 01:24:37 +01:00
bors
5e8c0c5ae0 Auto merge of #5441 - rabisg0:fix/clone-on-copy, r=phansch
Check for clone-on-copy in argument positions

Earlier if arguments to method calls matched the above pattern they were
not reported. This patch ensures such arguments are checked as well.

Fixes #5436

changelog: apply clone_on_copy lint to func args as well
2020-04-10 21:49:26 +00:00
bors
0353f21d23 Auto merge of #5446 - rust-lang:gimme-a-second, r=flip1995
compare with the second largest instead of the smallest variant

This should make the lint less noisy for now. See [my comment](https://github.com/rust-lang/rust-clippy/issues/5418#issuecomment-610440898) to issue #5418.

---

changelog: none
2020-04-10 21:33:45 +00:00
Andre Bogus
89f6012a4d compare with the second largest instead of the smallest variant 2020-04-10 17:01:56 +02:00
Rabi Guha
183c4abb22 Check for clone-on-copy in argument positions
Earlier if arguments to method calls matched the above pattern they were
not reported. This patch ensures such arguments are checked as well.

Fixes #5436
2020-04-09 21:59:42 +05:30
ThibsG
380f7218b3 Add lint on large const arrays 2020-04-09 09:09:39 +02:00
Marcin Serwin
4449cc799b Make the epsilon note spanless 2020-04-09 08:18:52 +02:00
Marcin Serwin
f637c45f8b Indicate when arrays are compared in error message 2020-04-09 08:10:14 +02:00
Marcin Serwin
84ae3d8bc8 Make epsilon note spanless when comparing arrays 2020-04-09 08:10:14 +02:00
Marcin Serwin
c7b5e30423 Add float cmp const tests for arrays 2020-04-09 08:08:36 +02:00
Marcin Serwin
3c738b2286 Add float cmp tests for arrays 2020-04-09 08:08:36 +02:00
Marcin Serwin
b4ff774d72 Update stderr of float_cmp test 2020-04-09 08:05:51 +02:00
briankabiro
0d00eafd32 Add tests for float in array comparison 2020-04-09 08:05:51 +02:00
bors
c25f26d4ca Auto merge of #5411 - dtolnay:hasher, r=flip1995
Downgrade implicit_hasher to pedantic

From the [documentation](https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher), this lint is intended to suggest:

```diff
- pub fn foo(map: &mut HashMap<i32, i32>) { }

+ pub fn foo<S: BuildHasher>(map: &mut HashMap<i32, i32, S>) { }
```

I think this is pedantic. I get that this lint can benefit core libraries like serde, but that's exactly the use case for pedantic lints; a library like serde will [enable clippy_pedantic](fd6741f4b0/src/lib.rs (L304)) and take the time to go through everything possible. Similar for libraries doing a libz blitz style checkup before committing to a 1.0 release; it would make sense to run through all the available pedantic lints then.

But otherwise, for most codebases and certainly for industrial codebases, the above suggested change just makes the codebase more obtuse for questionable benefit.

changelog: Remove implicit_hasher from default set of enabled lints
2020-04-08 17:14:09 +00:00
bors
940bbd6aa4 Auto merge of #5437 - rabisg0:should-impl-trait, r=flip1995
Check fn header along with decl when suggesting to implement trait

When checking for functions that are potential candidates for trait
implementations check the function header to make sure modifiers like
asyncness, constness and safety match before triggering the lint.

Fixes #5413, #4290

changelog: check fn header along with decl for should_implement_trait
2020-04-08 16:55:47 +00:00
Rabi Guha
c2e5534157 Check fn header along with decl when suggesting to implement trait
When checking for functions that are potential candidates for trait
implementations check the function header to make sure modifiers like
asyncness, constness and safety match before triggering the lint.

Fixes #5413, #4290
2020-04-08 21:24:20 +05:30
David Tolnay
5f92faec6d
Downgrade implicit_hasher to pedantic 2020-04-08 08:43:20 -07:00
David Tolnay
899a1b5598
Move cognitive_complexity to nursery 2020-04-08 08:37:20 -07:00
flip1995
381f9cb34e
Run fmt and update test 2020-04-08 16:00:03 +02:00
Philipp Krones
79d152190c
Rollup merge of #5425 - xiongmao86:issue5367, r=flip1995
Ehance opt_as_ref_deref lint.

- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Run `cargo dev fmt`

Lint on opt.as_ref().map(|x| &**x). Fixes #5367.

changelog: lint on opt.as_ref().map(|x| &**x)
2020-04-08 15:50:28 +02:00
Philipp Krones
8fc592a8e7
Rollup merge of #5424 - jpospychala:suspicious_op_assign_impl, r=flip1995
Incorrect suspicious_op_assign_impl

fixes #5255

changelog: In suspicious_op_assign_impl ignore all operators in expression if it's part of AssignOp
2020-04-08 15:50:26 +02:00
Philipp Krones
2011d9a783
Rollup merge of #5419 - dtolnay:unreadable, r=flip1995
Downgrade unreadable_literal to pedantic

As motivated by #5418. This is the top most commonly suppressed Clippy style lint, which indicates that the community has decided they don't share Clippy's opinion on the best style of this.

I've left the lint in as pedantic, though it could be that "restriction" would be better -- I can see this lint being useful as an opt-in restriction in some codebases.

changelog: Remove unreadable_literal from default set of enabled lints
2020-04-08 15:50:23 +02:00
Philipp Krones
a1e49f962c
Rollup merge of #5415 - nickrtorres:master, r=flip1995
Add new lint for `Result<T, E>.map_or(None, Some(T))`

Fixes #5414

PR Checklist
---
- [x] Followed lint naming conventions (the name is a bit awkward, but it seems to conform)
- [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

`Result<T, E>` has an [`ok()`](https://doc.rust-lang.org/std/result/enum.Result.html#method.ok) method that adapts a `Result<T,E>` into an `Option<T>`.
It's possible to get around this adapter by writing `Result<T,E>.map_or(None, Some)`.

This lint is implemented as a new variant of the existing [`option_map_none` lint](https://github.com/rust-lang/rust-clippy/pull/2128)
2020-04-08 15:50:20 +02:00
Philipp Krones
1e1bd519a1
Rollup merge of #5410 - dtolnay:trivially, r=flip1995
Downgrade trivially_copy_pass_by_ref to pedantic

The rationale for this lint is documented as:

> In many calling conventions instances of structs will be passed through registers if they fit into two or less general purpose registers.

I think the purported performance benefits of clippy's recommendation are overstated. This isn't worth asking people to sprinkle code with more `*`​`*`​`&`​`*`​`&` to chase the alleged performance.

This should be a pedantic lint that is disabled by default and opted in if some specific performance sensitive codebase determines that it is worthwhile.

As a reminder, a typical place that a reference to a primitive would come up is if the function is used as a filter. Triggering a performance-oriented lint on this type of code is the definition of pedantic.

```rust
fn filter(_n: &i32) -> bool {
    true
}

fn main() {
    let v = vec![1, 2, 3];
    v.iter().copied().filter(filter).for_each(drop);
}
```

```console
warning: this argument (4 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)
 --> src/main.rs:1:15
  |
1 | fn filter(_n: &i32) -> bool {
  |               ^^^^ help: consider passing by value instead: `i32`
```

changelog: Remove trivially_copy_pass_by_ref from default set of enabled lints
2020-04-08 15:50:17 +02:00
Philipp Krones
935b45db61
Rollup merge of #5409 - dtolnay:letunit, r=flip1995
Downgrade let_unit_value to pedantic

Given that the false positive in #1502 is marked E-hard and I don't have much hope of it getting fixed, I think it would be wise to disable this lint by default. I have had to suppress this lint in every substantial codebase (\>100k line) I have worked in. Any time this lint is being triggered, it's always the false positive case.

The motivation for this lint is documented as:

> A unit value cannot usefully be used anywhere. So binding one is kind of pointless.

with this example:

> ```rust
> let x = {
>     1;
> };
> ```

Sure, but the author would find this out via an unused_variable warning or from `x` not being the type that they need further down. If there ends up being a type error on `x`, clippy's advice isn't going to help get the code compiling because it can only run if the code already compiles.

changelog: Remove let_unit_value from default set of enabled lints
2020-04-08 15:50:16 +02:00
Philipp Krones
46337cb6a8
Rollup merge of #5406 - flip1995:update_lints_fix, r=flip1995
Fix update_lints

This fixes a bug in update_lints, where `internal` lints were not registered properly. This also cleans up some code. For example: The code generation functions no longer filter the lints the are given. This is now the task of the caller. This way, it is more obvious in the `replace_in_file` calls which lints will be included in which part of a file.

This also turns the lint modules private. There is no need for them to be public, since shared code should be in the utils module anyway.

And last but not least, this fixes the `register_lints` code generation, so also internal lints get registered.

changelog: none
2020-04-08 15:50:15 +02:00
Linus Färnstrand
b192f2cd15 Use primitive type assoc consts in more tests 2020-04-08 00:43:27 +02:00
Linus Färnstrand
51bb1d28c5 Use assoc const NAN for zero_div_zero lint 2020-04-08 00:43:27 +02:00
Linus Färnstrand
645b62e436 Fix float cmp to use assoc fxx::EPSILON 2020-04-08 00:43:27 +02:00
Linus Färnstrand
0b4ee9a649 Fix NAN comparison lint to use assoc NAN 2020-04-08 00:43:27 +02:00
xiongmao86
d7056f8ffb Refine lint message. 2020-04-07 21:25:07 +08:00
xiongmao86
4f14826e09 Lint on opt.as_ref().map(|x| &**x). 2020-04-06 22:53:59 +08:00
Jacek Pospychala
9c9af1d885 Include OpAssign in suspicious_op_assign_impl 2020-04-05 22:25:51 +02:00
Nick Torres
fb276dc3fa result_map_or_into_option: add opt.map_or(None, |_| Some(y)) test 2020-04-04 14:16:26 -07:00
Nick Torres
d0738bd673 result_map_or_into_option: destructure lint tuple or return early 2020-04-04 14:16:23 -07:00
David Tolnay
be34bc46ed
Downgrade unreadable_literal to pedantic 2020-04-04 12:52:03 -07:00
Nick Torres
91d8a804d3 result_map_or_into_option: add lint to catch manually adpating Result -> Option
Result<T, E> has an `ok()` method that adapts a Result<T,E> into an Option<T>.
It's possible to get around this adapter by writing Result<T,E>.map_or(None, Some).

This lint is implemented as a new variant of the existing
[`option_map_none` lint](https://github.com/rust-lang/rust-clippy/pull/2128)
2020-04-04 03:17:13 -07:00
flip1995
30503a91d2
Move matches test in matches module 2020-04-03 22:02:27 +02:00
David Tolnay
94154cad20
Downgrade trivially_copy_pass_by_ref to pedantic 2020-04-02 18:56:10 -07:00
David Tolnay
adcaa1b86d
Downgrade let_unit_value to pedantic 2020-04-02 18:31:31 -07:00
bors
a840d594cc Auto merge of #5349 - jpospychala:useless_rc, r=Manishearth
useless Rc<Rc<T>>, Rc<Box<T>>, Rc<&T>, Box<&T>

refers to  #2394

changelog: Add lints for Rc<Rc<T>> and Rc<Box<T>> and Rc<&T>, Box<&T>

this is based on top of another change #5310 so probably should go after that one.
2020-04-02 03:11:29 +00:00
Jacek Pospychala
f8e892db5e useless Rc<Rc<T>>, Rc<Box<T>>, Rc<&T>, Box<&T> 2020-04-02 00:02:25 +02:00
bors
7ebb3aa55d Auto merge of #5402 - pmk21:allow-let-underscore-must-use, r=flip1995
Allow let_underscore_must_use to be ignored

changelog: none
Fixes #5366
2020-04-01 21:43:44 +00:00
bors
42796e11c5 Auto merge of #5401 - dtolnay:option, r=Manishearth
Downgrade option_option to pedantic

Based on a search of my work codebase (\>500k lines) for `Option<Option<`, it looks like a bunch of reasonable uses to me. The documented motivation for this lint is:

> an optional optional value is logically the same thing as an optional value but has an unneeded extra level of wrapping

which seems a bit bogus in practice. For example a typical usage would look like:

```rust
let mut host: Option<String> = None;
let mut port: Option<i32> = None;
let mut payload: Option<Option<String>> = None;

for each field {
    match field.name {
        "host" => host = Some(...),
        "port" => port = Some(...),
        "payload" => payload = Some(...), // can be null or string
        _ => return error,
    }
}

let host = host.ok_or(...)?;
let port = port.ok_or(...)?;
let payload = payload.ok_or(...)?;
do_thing(host, port, payload)
```

This lint seems to fit right in with the pedantic group; I don't think linting on occurrences of `Option<Option<T>>` by default is justified.

---

changelog: Remove option_option from default set of enabled lints
2020-04-01 21:30:24 +00:00
David Tolnay
f6e8da81f1
Update option_option ui test 2020-04-01 12:15:39 -07:00
pmk21
97acabe56a Test for ignoring let_underscore_must_use 2020-04-02 00:44:09 +05:30
flip1995
7d58ba20b4
Rustup to rust-lang/rust#70632 2020-04-01 20:14:05 +02:00
flip1995
63987aafba
Rustup to rust-lang/rust#70081 2020-04-01 20:12:36 +02:00
pmk21
79ab05458f Small formatting change 2020-03-31 16:13:51 +05:30
pmk21
793403a2a8 Added test for single_match_else in macro 2020-03-31 15:49:49 +05:30
pmk21
ba6a3280f5 Added test for single_match in macro 2020-03-31 15:49:27 +05:30
bors
0a25944f78 Auto merge of #5294 - tmiasko:trait-ptr-cmp, r=Manishearth
Lint unnamed address comparisons

Functions and vtables have an insignificant address. Attempts to compare such addresses will lead to very surprising behaviour. For example: addresses of different functions could compare equal; two trait object pointers representing the same object and the same type could be unequal.

Lint against unnamed address comparisons to avoid issues like those in rust-lang/rust#69757 and rust-lang/rust#54685.

changelog: New lints: [`fn_address_comparisons`] [#5294](https://github.com/rust-lang/rust-clippy/pull/5294), [`vtable_address_comparisons`] [#5294](https://github.com/rust-lang/rust-clippy/pull/5294)
2020-03-30 19:52:41 +00:00
Tomasz Miąsko
b77b219280 Lint unnamed address comparisons 2020-03-30 21:42:16 +02:00
bors
42c36dc77b Auto merge of #5365 - mgr-inz-rafal:issue4983_bool_updates, r=yaahc
Issue4983 bool updates

changelog: Check for bool inequality comparison that might be written more concisely

Fixes #4983
2020-03-30 19:20:10 +00:00
bors
563da5248d Auto merge of #5387 - jpospychala:useless_self_fp, r=yaahc
`unused_self` false positive

fixes #5351

Remove the for loop in `unused_self` so that lint enabled for one method doesn't trigger on another method.

changelog: Fix false positive in `unused_self` around lint gates on impl items
2020-03-30 18:10:21 +00:00
Matthias Krüger
aff57e0f43 rustup https://github.com/rust-lang/rust/pull/70536 2020-03-30 11:17:58 +02:00
Jacek Pospychala
82f929cbaf unused_self false positive 2020-03-29 22:22:36 +02:00
Lzu Tao
d055b7d61c Deprecate REPLACE_CONSTS lint 2020-03-29 12:59:35 +07:00
Matthias Krüger
b86e8434df move redundant_pub_crate to nursery
cc #5369
2020-03-25 18:14:11 +01:00
bors
100a24d9d8 Auto merge of #5364 - flip1995:useless_transmute_quarantine, r=Manishearth
Move useless_transmute to nursery

cc #5343

@rust-lang/clippy anyone against moving this to nursery?

changelog: Move [`useless_transmute`] to nursery
2020-03-23 20:52:57 +00:00
bors
d3989eef2d Auto merge of #5319 - 1tgr:master, r=flip1995
Lint for `pub(crate)` items that are not crate visible due to the visibility of the module that contains them

changelog: Add `redundant_pub_crate` lint

Closes #5274.
2020-03-23 20:35:49 +00:00
mgr-inz-rafal
ff9602515e Code clean-up and formatting 2020-03-23 21:21:18 +01:00
mgr-inz-rafal
3d3af07845 Provide appropriate suggestion 2020-03-23 21:00:02 +01:00
flip1995
13fcee51e7
Move useless_transmute to nursery 2020-03-23 20:32:04 +01:00
mgr-inz-rafal
12796cd688 Initial lint without suggestion 2020-03-23 20:29:12 +01:00
Tim Robinson
870b9e8139 nursery group -> style 2020-03-23 16:45:31 +00:00
ThibsG
badfbbbbde Fix single binding in closure 2020-03-22 10:31:30 +01:00
Tim Robinson
de9092438d Update for PR feedback 2020-03-20 22:52:53 +00:00
bors
0e5e2c4365 Auto merge of #5323 - rabisg0:fix/5284, r=flip1995
Improvement: Don't show function body in needless_lifetimes

Changes the span on which the lint is reported to point to only the
function return type instead of the entire function body.
Fixes #5284

changelog: none
2020-03-20 12:45:30 +00:00
Philipp Krones
983d195bb5
Rollup merge of #5333 - matthiaskrgr:rustup_34, r=flip1995
rustup https://github.com/rust-lang/rust/pull/69189

rustups https://github.com/rust-lang/rust/pull/69189 which is part of https://github.com/rust-lang/rust/pull/70085
(at least I think this is the only pr that changes clippy test stdout)

changelog: none
2020-03-19 15:00:30 +01:00
Rabi Guha
0812a0af4c Improvement: Don't show function body in needless_lifetimes
Changes the span on which the lint is reported to point to only the
function return type instead of the entire function body.
Fixes #5284
2020-03-19 12:03:02 +05:30
Matthias Krüger
ec1dcde46b tests: arithmetic: split into integer_arithmetic and float_arithmetic files. 2020-03-18 15:50:01 +01:00
flip1995
a808779441
Split up checked_unwrap test further 2020-03-18 15:26:24 +01:00
Matthias Krüger
c7c7ab23aa integer_arithmetic: detect integer arithmetic on references.
Also fixes the same for float_arithmetic.

changelog: integer_arithmetic,float_arithmetic: fix false negatives with references on integers

Fixes #5328
2020-03-18 14:52:01 +01:00
Matthias Krüger
b875c53d2c rustup https://github.com/rust-lang/rust/pull/69189
rustups https://github.com/rust-lang/rust/pull/69189 which is part of https://github.com/rust-lang/rust/pull/70085
(at least I think this is the only pr that changes clippy test stdout)
2020-03-18 03:27:05 +01:00
Tim Robinson
52208f3cf3 Lint for pub(crate) items that are not crate visible due to the visibility of the module that contains them
Closes #5274.
2020-03-16 12:21:00 +00:00
Lzu Tao
9febcf5e8d Don't convert Path to lossy str 2020-03-14 22:20:16 +07:00
Lzu Tao
6be0220967 Use into_path 2020-03-14 22:20:16 +07:00
Lzu Tao
29df0139dc Use pattern matching instead of manually checking condition 2020-03-14 19:29:48 +07:00
Philipp Krones
626f2fe1cb
Fix typo
Co-Authored-By: Mateusz Mikuła <mati865@users.noreply.github.com>
2020-03-14 10:22:49 +01:00
Eric Huss
34a00fe7f4 Remove git2 dependency. 2020-03-13 18:22:51 -07:00
Shotaro Yamada
d9ad33852c Use visit_place 2020-03-13 02:06:47 +09:00
Shotaro Yamada
aca64b8df7 Check for mutation 2020-03-13 01:25:18 +09:00
Shotaro Yamada
9de642190e Extend redundant_clone to the case that cloned value is not consumed 2020-03-13 00:31:09 +09:00
bors
fdce47ba7d Auto merge of #5272 - jmeyers35:file_read_lint, r=flip1995
add lint on File::read_to_string and File::read_to_end

Adds lint `verbose_file_reads` which checks for use of File::read_to_end and File::read_to_string.

Closes https://github.com/rust-lang/rust-clippy/issues/4916

changelog: add lint on File::{read_to_end, read_to_string}
2020-03-10 22:35:15 +00:00
bors
9d5ffe8105 Auto merge of #5300 - JohnTitor:edition-flag, r=flip1995
Use `edition:2018` flag more widely

Now we recommend using `// edition:2018`, so let's use it more widely.
Also replace a too old example with new one in the docs.

changelog: none
2020-03-10 22:02:41 +00:00
Jacob Meyers
a4ba1027fc add CR feedback 2020-03-10 18:00:37 -04:00
Yuki Okushi
515847dad1
Use edition:2018 flag more widely 2020-03-11 06:35:07 +09:00
bors
23bd427f92 Auto merge of #5298 - rust-lang:needless_doc_main_code, r=flip1995,Manishearth
needless_doc_main: only check rust code

This fixes #5280 by checking the language attribute on code blocks.

---

changelog: none
2020-03-10 21:30:44 +00:00
Manish Goregaokar
d5c8b783b8
Update tests/ui/needless_doc_main.rs
Co-Authored-By: Philipp Krones <hello@philkrones.com>
2020-03-10 14:30:07 -07:00
Andre Bogus
2fa3da4869 needless_doc_main: only check rust code 2020-03-10 20:19:37 +01:00
bors
557f6848bd Auto merge of #5296 - sinkuu:fix_ice_trivial_bounds, r=flip1995
Fix ICE with trivial_bounds feature

https://github.com/rust-lang/rust/issues/69874#issuecomment-596890446

changelog: Fix ICE with trivial_bounds feature
2020-03-10 12:25:07 +00:00
Yuki Okushi
8d2a3e0a61
Use node_type_opt over node_type 2020-03-10 18:18:34 +09:00
Shotaro Yamada
a3d9355bef Fix ICE with trivial_bounds feature 2020-03-10 13:17:35 +09:00
Jacek Pospychala
697e3c89a7 Improve placeholder in map_unit_fn 2020-03-09 20:37:06 +01:00
bors
d8f64b6eba Auto merge of #5287 - matthiaskrgr:pat_isref, r=flip1995
redundant_pattern: take binding (ref, ref mut) into account in suggestion

fixes #5271

changelog: redundant_pattern: take binding (ref, ref mut) into account in suggestion (#5271)
2020-03-09 17:25:09 +00:00
bors
118594ffa2 Auto merge of #5291 - ThibsG:FixSingleBinding, r=flip1995
Fix match single binding when in a let stmt

Fix bad suggestion when `match_single_binding` lints when inside a local (let) statement.

Fixes #5267

changelog: none
2020-03-09 16:04:26 +00:00
ThibsG
40a04f2657 Fix match single binding when in a let stmt 2020-03-09 16:59:24 +01:00
Vivek Ghaisas
ab6e709ee6 Improve error messages for {option,result}_map_unit_fn
Instead of saying "unit function", use the phrase the description
uses: "function that returns the unit type".

Fixes #5180.
2020-03-08 21:28:06 +00:00
Matthias Krüger
75a2300e27 redundant_pattern: take binding (ref, ref mut) into account in suggestion.
fixes #5271
2020-03-08 10:47:18 +01:00
Jacob Meyers
0f7f30711e add lint on File::read_to_string and File::read_to_end 2020-03-06 09:50:49 -05:00
flip1995
57393b5106
Rename macro_use_import -> macro_use_imports 2020-03-05 19:22:17 +01:00
bors
23d2b21297 Auto merge of #5230 - DevinR528:macro-use, r=flip1995
Macro use

---

changelog: This lint enforces Rust 2018 idiom of importing macro's directly without `#[macro_use]` fixes #5179 .
2020-03-05 17:30:52 +00:00
bors
329923edec Auto merge of #5257 - mlegner:cast_hex_fp, r=flip1995
Resolve false positives of unnecessary_cast for non-decimal integers

This PR resolves false positives of `unnecessary_cast` for hexadecimal integers to floats and adds a corresponding test case.

Fixes: #5220

changelog: none
2020-03-04 16:11:40 +00:00
Devin R
597e02dcdf warn on macro_use attr 2020-03-04 09:36:02 -05:00