Commit Graph

5383 Commits

Author SHA1 Message Date
Yoshitomo Nakanishi
d646aa2ae7 Fix unnecessary_sort_by.rs that fails the dogfood test 2021-02-21 05:05:13 +09:00
Yoshitomo Nakanishi
d23038944a New lint: inconsistent_struct_constructor 2021-02-21 05:05:11 +09:00
bors
67087a1b4e Auto merge of #6717 - booleancoercion:master, r=llogiq
Add the from_str_radix_10 lint

changelog: added the new `from_str_radix_10` which sometimes replaces calls to `primitive::from_str_radix` to `str::parse`

This is ready to be merged, although maybe the category should be `pedantic` instead of `style`? I'm not sure where it fits better.

Closes #6713.
2021-02-20 09:33:11 +00:00
bool
c4b8d87ab9 Fixed the known problems section 2021-02-19 22:00:23 +02:00
bool
bf55aee7b1 Updated from_str_radix_10 sugg to be slightly smarter and ran bless 2021-02-19 21:56:21 +02:00
Matthias Krüger
1f4153aa1e collapsible_match: fix lint message capitalization
(see https://rustc-dev-guide.rust-lang.org/diagnostics.html for details)
2021-02-19 10:02:17 +01:00
bors
0f70e88137 Auto merge of #6665 - pag4k:unnecessary_wraps_bug_6640, r=camsteffen
Fix for issue 6640

*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog: unnecessary_wraps will now suggest to remove unnecessary wrapped return unit type, like Option<()>
fixes #6640
2021-02-18 22:47:44 +00:00
Pierre-Andre Gagnon
a78271b861 Changed fn body suggestion msg 2021-02-18 17:32:55 -05:00
Yoshitomo Nakanishi
a87fa0e350 Fix FP of result_unit_err when using type aliases 2021-02-18 18:49:26 +09:00
Pierre-Andre Gagnon
6165cccf7e Added detailled suggs for new case 2021-02-17 16:41:50 -05:00
bors
e2753f9a7b Auto merge of #6662 - Y-Nak:default-numeric-fallback, r=flip1995
New lint: default_numeric_fallback

fixes #6064
r? `@flip1995`

As we discussed in [here](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Issue.20.236064/near/224647188) and [here](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Issue.20clippy.236064/near/224746333),   I start implementing this lint from the strictest version.
In this PR, I'll allow the below two cases to pass the lint to reduce FPs.

1. Appearances of unsuffixed numeric literals in `Local` if `Local` has a type annotation, for example:
```rust
// Good.
let x: i32 = 1;

// Also good.
let x: (i32, i32) = if cond {
   (1, 2)
} else {
   (2, 3)
};
```

2. Appearances of unsuffixed numeric literals in args of `Call` or `MethodCall`  if corresponding arguments of their signature have concrete types, for example:
```rust
fn foo_mono(x: i32) -> i32 {
    x
}

fn foo_poly<T>(t: T) -> t {
    t
}

// Good.
let x = foo_mono(13);

// Still bad.
let x: i32 = foo_poly(13);
```

changelog: Added restriction lint: `default_numeric_fallback`
2021-02-16 09:58:49 +00:00
Yoshitomo Nakanishi
9b0c1ebc18 Change to span_lint_and_sugg from span_lint_and_help 2021-02-16 18:07:09 +09:00
Yoshitomo Nakanishi
1f8ee3cc19 Handle struct ctor case 2021-02-16 11:20:51 +09:00
Yoshitomo Nakanishi
fb91c76586 Add more tests for default_numeric_fallback 2021-02-15 23:33:27 +09:00
Yoshitomo Nakanishi
0198ac7bdd Add fn_sig_opt to get fn signature from HirId 2021-02-15 23:29:18 +09:00
Yoshitomo Nakanishi
93796b2346 Add some restrictions to default_numeric_fallback to avoid FNs 2021-02-15 14:43:37 +09:00
bors
2f19f5f0d7 Auto merge of #6741 - ThibsG:BlockInIfConditions1141, r=flip1995
Do not lint when the closure is called using an iterator

Fix FP when the closure is used in an iterator for `blocks_in_if_conditions` lint

FIxes: #1141

changelog: none
2021-02-14 15:55:12 +00:00
ThibsG
12025506d6 Do not lint when the closure is called using an iterator 2021-02-14 16:21:12 +01:00
bors
9c3b43efdd Auto merge of #6701 - camsteffen:collapsible-if, r=flip1995
Fix collapsible_if with attributes

changelog: Fix collapsible_if FP with attributes

Fixes #6593
2021-02-14 14:43:35 +00:00
bors
eb80ac4e72 Auto merge of #6697 - camsteffen:vec-init-push-fp, r=flip1995
Fix vec_init_then_push false positives

changelog: Fix vec_init_then_push false positives

Fixes #6615
2021-02-14 14:27:13 +00:00
boolean_coercion
d36fe85569 Made parens addition smarter and added tests with bless 2021-02-13 00:33:08 +02:00
bors
047f3e16bf Auto merge of #6700 - daxpedda:panics-doc-unreachable, r=llogiq
Fix missing_panics_doc warning on `unreachable!`.

Fixes #6699.

Are there any other test-cases I should cover?

changelog: [`missing_panics_doc`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc): No longer lints on [`unreachable!`](https://doc.rust-lang.org/std/macro.unreachable.html)
2021-02-12 20:48:05 +00:00
boolean_coercion
642efabfbb Fixed typos and updated to matches! where applicable 2021-02-12 11:54:22 +02:00
boolean_coercion
9194c11d69 Fixed doctests that shouldn't have been compiled 2021-02-12 11:54:22 +02:00
boolean_coercion
d1a627ab3b Ran bless and rustfmt 2021-02-12 11:54:22 +02:00
boolean_coercion
0b31b470ad Changed applicability to MaybeIncorrect because of surrounding braces 2021-02-12 11:54:22 +02:00
boolean_coercion
a389c02461 from_str_radix_10 should be done 2021-02-12 11:54:22 +02:00
boolean_coercion
64729390a1 Implemented majority of from_str_radix_10 2021-02-12 11:54:22 +02:00
boolean_coercion
b80ac2af9c Added boilerplate 2021-02-12 11:54:22 +02:00
bors
605e9ba3d7 Auto merge of #6179 - flip1995:rewrite_use_self, r=phansch
Rework use_self impl based on ty::Ty comparison #3410 | Take 2

This builds on top of #5531

I already reviewed and approved the commits by `@montrivo.` So only the review of my commits should be necessary.

I would also appreciate your review `@montrivo,` since you are familiar with the challenges here.

Fixes #3410 and Fixes #4143 (same problem)
Fixes #2843
Fixes #3859
Fixes #4734 and fixes #6221
Fixes #4305
Fixes #5078 (even at expression level now 🎉)
Fixes #3881 and Fixes #4887 (same problem)
Fixes #3909

Not yet: #4140 (test added)

All the credit for the fixes goes to `@montrivo.` I only refactored and copy and pasted his code.

changelog: rewrite [`use_self`] lint and fix multiple (8) FPs. One to go.
2021-02-12 06:09:07 +00:00
flip1995
00f9981f5c
Merge remote-tracking branch 'upstream/master' into rustup 2021-02-11 14:36:52 +01:00
bors
beb49bad26 Auto merge of #6650 - daxpedda:cargo-common-metadata-publish, r=flip1995
Fix cargo_common_metadata warning on `publish = false`.

I believe `cargo_common_metadata` shouldn't trigger when `publish = false`, not sure if everybody agrees.
Made some tests to handle all edge-cases.

Fixes #6649.

changelog: [`cargo_common_metadata`](https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata): No longer lints if [`publish = false`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field) is defined in the manifest
2021-02-11 09:34:44 +00:00
bors
3784cdf98e Auto merge of #6657 - ThibsG:FromIterParens, r=llogiq
Fix suggestions that need parens in `from_iter_instead_of_collect` lint

Fixes broken suggestions that need parens (i.e.: range)

Fixes: #6648

changelog: none
2021-02-10 19:37:27 +00:00
alpaca-tc
94b8f23baf Fix typo 2021-02-11 00:45:28 +09:00
bors
b5e4389f53 Auto merge of #6695 - TaKO8Ki:add-bytes-nth, r=phansch
New lint: `bytes_nth`

This pull request adds a new lint named `bytes_nth`.

---
closes: https://github.com/rust-lang/rust-clippy/issues/6391

changelog: Added a new lint: `bytes_nth`
2021-02-10 13:54:33 +00:00
Cameron Steffen
52f98d832d
Use TyS::same_type 2021-02-10 11:58:21 +01:00
Cameron Steffen
7f61ddd5b8
Move "types to lint" to the item stack 2021-02-10 11:58:20 +01:00
Cameron Steffen
7e1c1c1541
Fix qpath_res call 2021-02-10 11:58:20 +01:00
flip1995
da65d8166f
Don't trigger use_self in macros 2021-02-10 11:57:28 +01:00
flip1995
ae2dd671f5
Rewrite use_self lint one more time
This rewrite gets rid of complicated visitors, by using the lint infrastructure as much as possible
2021-02-10 11:57:28 +01:00
Tim Nielens
fc334fb8f4
use_self - fix issue with hir_ty_to_ty 2021-02-10 11:57:28 +01:00
Tim Nielens
347b01eb1f
rework use_self impl based on ty::Ty comparison 2021-02-10 11:57:27 +01:00
Takayuki Maeda
932cc085e6
Update clippy_lints/src/methods/bytes_nth.rs
Co-authored-by: Phil Hansch <dev@phansch.net>
2021-02-10 15:49:07 +09:00
ThibsG
b932587c5d Add better turbofish extractor 2021-02-09 17:43:49 +01:00
Ömer Sinan Ağacan
34b373d309 Rename HIR UnOp variants
This renames the variants in HIR UnOp from

    enum UnOp {
        UnDeref,
        UnNot,
        UnNeg,
    }

to

    enum UnOp {
        Deref,
        Not,
        Neg,
    }

Motivations:

- This is more consistent with the rest of the code base where most enum
  variants don't have a prefix.

- These variants are never used without the `UnOp` prefix so the extra
  `Un` prefix doesn't help with readability. E.g. we don't have any
  `UnDeref`s in the code, we only have `UnOp::UnDeref`.

- MIR `UnOp` type variants don't have a prefix so this is more
  consistent with MIR types.

- "un" prefix reads like "inverse" or "reverse", so as a beginner in
  rustc code base when I see "UnDeref" what comes to my mind is
  something like "&*" instead of just "*".
2021-02-09 11:39:20 +03:00
Cameron Steffen
39ba449c2a Fix collapsible_if false positive with attributes 2021-02-08 11:00:30 -06:00
Cameron Steffen
1021327781 Simplify if_chain 2021-02-08 10:51:40 -06:00
daxpedda
6c73f989e2
Fix missing_panics_doc warning on unreachable!. 2021-02-08 17:25:10 +01:00
Cameron Steffen
37555f8f73 Use path_to_local_id 2021-02-08 09:50:13 -06:00
Cameron Steffen
5db48a382a Refactor out UnusedSelfVisitor 2021-02-08 08:56:33 -06:00