Commit Graph

3908 Commits

Author SHA1 Message Date
Elichai Turkel
ecd0a67b01
Make match_wild_err_arm pedantic, and update help messages 2020-05-20 16:39:03 +03:00
bors
cafa94662c Auto merge of #5582 - vtmargaryan:match_wildcard_for_single_variants, r=flip1995
New lint: `match_wildcard_for_single_variants`

changelog: Added a new lint match_wildcard_for_single_variants to warn on enum matches where a wildcard is used to match a single variant

Closes #5556
2020-05-20 12:51:28 +00:00
flip1995
f28f1f15da
Fix dogfood fallout 2020-05-20 13:32:53 +02:00
Amanieu d'Antras
d25b25610b Handle InlineAsm in clippy 2020-05-18 14:41:33 +01:00
flip1995
f1d3086492 Merge commit 'e214ea82ad0a751563acf67e1cd9279cf302db3a' into clippyup 2020-05-17 17:36:26 +02:00
Ralf Jung
8bba1b7589 Rollup merge of #72047 - Julian-Wollersberger:literal_error_reporting_cleanup, r=petrochenkov
Literal error reporting cleanup

While doing some performance work, I noticed some code duplication in `librustc_parser/lexer/mod.rs`, so I cleaned it up.

This PR is probably best reviewed commit by commit.

I'm not sure what the API stability practices for `librustc_lexer` are. Four public methods in `unescape.rs` can be removed, but two are used by clippy, so I left them in for now.
I could open a PR for Rust-Analyzer when this one lands.

But how do I open a PR for clippy? (Git submodules are frustrating to work with)
2020-05-16 19:46:31 +02:00
Dylan DPC
b0490cc80d Rollup merge of #71948 - csmoe:issue-61076, r=oli-obk
Suggest to await future before ? operator

Closes https://github.com/rust-lang/rust/issues/71811
cc #61076
2020-05-16 02:37:21 +02:00
Vardan Margaryan
2620d2449d Fix check for missing enum variants from match expressions
TupleStruct matches are checked for exhaustiveness
2020-05-16 00:06:52 +03:00
Vardan Margaryan
10313a2631 Revert "Fix cases of match_wildcard_for_single_variants lint when it is spanned on Option"
This reverts commit 4948307977.
2020-05-15 22:33:37 +03:00
csmoe
0a86335cd4 implement type_implments_trait query 2020-05-15 15:37:11 +08:00
Vardan Margaryan
1c59cd5f21 Fix example code of wildcard_enum_match_arm lint 2020-05-14 22:41:05 +03:00
Vardan Margaryan
749619cfe3 Apply suggestions from PR review 2020-05-14 22:40:33 +03:00
Vardan Margaryan
4948307977 Fix cases of match_wildcard_for_single_variants lint when it is spanned on Option 2020-05-14 22:36:46 +03:00
Vardan Margaryan
0ad9f7d651 Fix trivial cases of new match_wildcard_for_single_variants lint 2020-05-14 22:36:46 +03:00
Vardan Margaryan
94e4b5ec31 Add the redundant_wildcard_enum_match lint 2020-05-14 22:36:46 +03:00
bors
e1842b0cac Auto merge of #5583 - ebroto:reversed_empty_ranges, r=yaahc,flip1995
Reversed empty ranges

This lint checks range expressions with inverted limits which result in empty ranges. This includes also the ranges used to index slices.

The lint reverse_range_loop was covering iteration of reversed ranges in a for loop, which is a subset of what this new lint covers, so it has been removed. I'm not sure if that's the best choice. It would be doable to check in the new lint that we are not in the arguments of a for loop; I went for removing it because the logic was too similar to keep them separated.

changelog: Added reversed_empty_ranges lint that checks for ranges where the limits have been inverted, resulting in empty ranges. Removed reverse_range_loop which was covering a subset of the new lint.

Closes #4192
Closes #96
2020-05-14 12:59:24 +00:00
Eduardo Broto
671c1e34cc Avoid running doctest that is expected to panic 2020-05-13 21:07:13 +02:00
Eduardo Broto
e4cd8e7961 Fix ICE caused in unwrap module 2020-05-13 20:35:52 +02:00
Eduardo Broto
0f2b1193f9 Remove reverse_range_loop lint 2020-05-13 20:33:32 +02:00
Eduardo Broto
8ffa0bfaa2 New lint: reversed_empty_ranges 2020-05-13 20:33:32 +02:00
Julian Wollersberger
ff9a9ed37c Replace some usages of the old unescape_ functions in AST, clippy and tests. 2020-05-13 10:05:04 +02:00
flip1995
505280b108
Run cargo dev fmt 2020-05-11 21:31:01 +02:00
Camille GILLOT
8ab3224b3b
Fix clippy. 2020-05-11 21:26:39 +02:00
flip1995
d13d8987b0 Merge commit '43a1777b89cf6791f9e20878b4e5e3ae907867a5' into clippyup 2020-05-11 20:23:47 +02:00
Glenn Hope
b69200b846 Move is_test_module check to top of function 2020-05-09 11:10:16 -07:00
Glenn Hope
0ba61c612e Check is_macro inside check_exceptions, update references to fix test 2020-05-09 11:10:16 -07:00
Glenn Hope
4db6abcd50 Remove check for Fn, reflect this in test cases, make test cases more robust/explicit 2020-05-09 11:09:38 -07:00
Glenn Hope
152cdcb45b Remove unnecessary field, check for Mod/Fn ItemKind 2020-05-09 11:09:38 -07:00
Glenn Hope
a42a2bdac2 Also have flag disable macro check 2020-05-09 11:09:38 -07:00
Glenn Hope
ad92486d52 Add check for "test" in parent name. Include flag for disabling wildcard import exceptions 2020-05-09 11:09:38 -07:00
Glenn Hope
56f4e1c3a8 Check if the parent module name contains "test" 2020-05-09 11:09:38 -07:00
Glenn Hope
bdc75dbb7b Run cargo dev fmt 2020-05-09 11:09:38 -07:00
Glenn Hope
0c14ea8ed7 Allow 'use super::*;' imports 2020-05-09 11:09:38 -07:00
Camille GILLOT
31c84e5077 Fix clippy. 2020-05-08 13:57:01 +02:00
bors
ceddf34b2e Auto merge of #5541 - DarkEld3r:patch-1, r=flip1995
Extend example for the `unneeded_field_pattern` lint

Current example is incorrect (or pseudo-code) because a struct name is omitted. I have used the code from the tests instead. Perhaps this example can be made less verbose, but I think it is more convenient to see a "real" code as an example.

---

changelog: extend example for the `unneeded_field_pattern` lint
2020-05-08 10:34:50 +00:00
Eduardo Broto
3e4bc026e2 Apply suggestions from PR review 2020-05-07 22:40:28 +02:00
Eduardo Broto
4ac348b308 Fix doc comment in lint declaration 2020-05-07 22:03:38 +02:00
Eduardo Broto
3b58d66b22 Add the manual_async_fn lint 2020-05-07 21:42:40 +02:00
Oliver Scherer
7744cf4e53 Update to rustc changes 2020-05-04 15:13:07 +02:00
Dylan MacKenzie
41fe5c1ca7 Update clippy lint 2020-05-03 11:41:03 -07: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
CrazyRoka
de58c5644d Changed RANGE_FULL constant in utils 2020-05-02 17:37:03 +03: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
991efa6375 Auto merge of #5555 - flip1995:pedantic_match_on_vec_items, r=phansch
Move match_on_vec_items to pedantic

Addresses https://github.com/rust-lang/rust-clippy/issues/5551#issuecomment-622515580

Fixes #5553

changelog: Move [`match_on_vec_items`] to pedantic

r? @phansch
2020-05-02 08:45:59 +00: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