Commit graph

3078 commits

Author SHA1 Message Date
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
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
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