Commit graph

757 commits

Author SHA1 Message Date
Jade
11ef04728c Add unwrap_or_else_default lint
This will catch `unwrap_or_else(Default::default)` on Result and Option
and suggest `unwrap_or_default()` instead.
2021-08-10 14:40:26 -07:00
Fridtjof Stoldt
35a74a1a6b
Updated config value name in changelog for 1.54 2021-07-29 16:26:26 +02:00
xFrednet
fdf29c04ae
Updated changelog for 1.55
Co-authored-by: Philipp Krones <hello@philkrones.com>
Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>
2021-07-29 13:58:15 +02:00
flip1995
2b20f49841 Merge commit '0cce3f643bfcbb92d5a1bb71858c9cbaff749d6b' into clippyup 2021-07-29 12:16:06 +02:00
flip1995
54e539121d
Rename two lints to comply with our lint naming convention
self_named_constructor -> self_named_constructors
append_instead_of_extend -> extend_with_drain
2021-07-29 12:10:18 +02:00
flip1995
884ef4c287 Merge commit '4c41a222ca5d1325fb4b6709395bd06e766cc042' into clippyup 2021-07-19 11:52:05 +02:00
bors
f70a07454b Auto merge of #7403 - Anthuang:redundant-method-names, r=Manishearth
New lint: [`self_named_constructor`]

Adds the `self_named_constructor` lint for detecting when an implemented method has the same name as the type it is implemented for.

changelog: [`self_named_constructor`]

closes: #7142
2021-07-19 06:49:51 +00:00
flip1995
1d084b13a5 Merge commit '54a20a02ecd0e1352a871aa0990bcc8b8b03173e' into clippyup 2021-07-15 10:44:10 +02:00
flip1995
69fbd64e2a
Merge remote-tracking branch 'upstream/master' into rustup 2021-07-15 10:32:06 +02:00
Ryan Levick
30c5c2ff03 Add s to non_fmt_panic 2021-07-06 20:12:56 +02:00
Anthony Huang
357a8f0344 Add redundant_method_names lint 2021-07-05 14:15:20 -04:00
Mateusz Gacek
59a164e86c Add new lint: strlen_on_c_strings 2021-07-05 11:10:45 +02:00
bors
84209994ad Auto merge of #7316 - lengyijun:rc_mutex, r=llogiq
Add new lint: `rc_mutex`

changelog: Add new lint `rc_mutex`.

It lints on `Rc<Mutex<T>>`.

`Rc<Mutex<T>>` should be corrected to `Rc<RefCell<T>>`
2021-07-03 10:26:03 +00:00
flip1995
ebe52869a3 Merge commit '61eb38aeda6cb54b93b872bf503d70084c4d621c' into clippyup 2021-07-01 18:17:38 +02:00
Igor Aleksanov
018be41dee Implement 'disallowed_script_idents' lint 2021-06-30 19:06:33 +03:00
Devin Ragotzy
9492de5843 Add import_rename lint, this adds a field on the Conf struct
Rename lint and fix review issues
2021-06-24 16:13:02 -04:00
bors
3120b09151 Auto merge of #7299 - DevinR528:macro-brace, r=llogiq
Add macro_braces lint to check for irregular brace use in certain macros

The name is a bit long but this sounds good as `#[allow(unconventional_macro_braces)]` and it seems more clear that we are talking about the macro call not macro definitions, any feedback let me know. Thanks!
fixes #7278

changelog: Add ``[`unconventional_macro_braces`]`` lint that checks for uncommon brace usage with macros.
2021-06-19 17:56:56 +00:00
flip1995
40fee52e49
Fix link in changelog 2021-06-17 21:06:50 +02:00
flip1995
218a609f3c
Update changelog 2021-06-17 17:59:08 +02:00
Devin Ragotzy
723f515b60 Add macro_braces lint to check for irregular brace use in certain macros
Rename unconventional -> nonstandard, add config field

Add standard_macro_braces fields so users can specify macro names and
brace combinations to lint for in the clippy.toml file.

Fix errors caused by nonstandard_macro_braces in other lint tests

Fix users ability to override the default nonstandard macro braces

Add type position macros impl `check_ty`
2021-06-17 07:02:36 -04:00
valentine-mario
44608b1857 added lint to check for full range of vector and suggest append 2021-06-10 09:12:06 +01:00
Devin Ragotzy
ea45e2a9cf Add disallowed_types lint, this adds a field to the Conf struct
Replace use of node_type -> node_type_opt, fix clippy warnings

Don't walk the hir unnecessarily let the visitor do it
2021-06-09 07:21:16 -04:00
lyj
c0f3c2fe27 correct lint 2021-06-04 10:44:34 +08:00
flip1995
6c27482115 Merge commit '3ae8faff4d46ad92f194c2a4b941c3152a701b31' into clippyup 2021-06-03 08:41:37 +02:00
Jason Newcomb
97311f0906
Add lint manual_str_repeat 2021-05-30 23:26:48 -04:00
Jason Newcomb
898b6a0e07
Add lint suspicious_splitn 2021-05-30 09:49:55 -04:00
Jason Newcomb
6d4dc35882
Improve needless_borrow lint
Suggest changing usages of ref bindings to match the new type
Split out some cases into new lint `ref_binding_to_reference`
2021-05-20 09:03:47 -04:00
flip1995
97705b7ea6 Merge commit '9e3cd88718cd1912a515d26dbd9c4019fd5a9577' into clippyup 2021-05-20 13:07:57 +02:00
bors
a3223af9fe Auto merge of #7133 - arya-k:master, r=llogiq
Add `needless_bitwise_bool` lint

fixes #6827
fixes #1594

changelog: Add ``[`needless_bitwise_bool`]`` lint

Creates a new `bitwise_bool` lint to convert `x & y` to `x && y` when both `x` and `y` are booleans. I also had to adjust thh `needless_bool` lint slightly, and fix a couple failing dogfood tests. I made it a correctness lint as per flip1995's comment [here](https://github.com/rust-lang/rust-clippy/pull/3385#issuecomment-434715723), from a previous WIP attempt at this lint.
2021-05-17 18:57:14 +00:00
bors
acdf43f257 Auto merge of #7225 - InquisitivePenguin:unnessecary-async, r=llogiq
New lint: `unused_async`

changelog: Adds a lint, `unused_async`, which checks for async functions with no await statements

`unused_async` is a lint that reduces code smell and overhead by encouraging async functions to be refactored into synchronous functions.

Fixes #7176

### Examples

```rust
async fn get_random_number() -> i64 {
    4 // Chosen by fair dice roll. Guaranteed to be random.
}
```

Could be written as:

```rust
fn get_random_number() -> i64 {
    4 // Chosen by fair dice roll. Guaranteed to be random.
}
```

Something like this, however, should **not** be caught by clippy:
```rust
#[async_trait]
trait AsyncTrait {
    async fn foo();
}

struct Bar;

#[async_trait]
impl AsyncTrait for Bar {
    async fn foo() {
        println!("bar");
    }
}
```
2021-05-17 06:00:55 +00:00
Jackson Lewis
75ef9dc708
update_lints 2021-05-14 17:12:25 -07:00
Arya Kumar
5ba236f303 added needless_bitwise_bool lint 2021-05-11 19:34:14 +00:00
Kevin Reid
91851d8040
Fix duplicated "Rust 1.52" version section header
The most recent changelog update 037ddf282b accompanying the 1.52 release added a second "Rust 1.52" section header, with the result that the Rust release announcement https://blog.rust-lang.org/2021/05/06/Rust-1.52.0.html is linking to the "current beta" changelog section for Clippy rather than the stable changelog. I don't know the release process but based on previous changes to this file, I assume the correct thing to do is to mark the topmost section as being for Rust 1.53, not 1.52.
2021-05-06 17:18:45 -07:00
flip1995
037ddf282b
Update CHANGELOG.md 2021-05-06 15:32:05 +02:00
flip1995
02bf692169 Merge commit '98e2b9f25b6db4b2680a3d388456d9f95cb28344' into clippyup 2021-04-22 11:31:13 +02:00
bors
79b9eb5371 Auto merge of #7072 - ebobrow:imports-ending-with-self, r=camsteffen
add unnecessary_self_imports lint

fixes #6552

changelog: add `unnecessary_self_imports` lint
2021-04-21 14:47:49 +00:00
Elliot Bobrow
224881b94d add unnecessary_self_imports lint 2021-04-21 07:17:42 -07:00
bors
bbc22e2ef3 Auto merge of #7083 - GuillaumeGomez:bool-assert-eq, r=camsteffen
Add lint to check for boolean comparison in assert macro calls

This PR adds a lint to check if an assert macro is using a boolean as "comparison value". For example:

```rust
assert_eq!("a".is_empty(), false);
```

Could be rewritten as:

```rust
assert!(!"a".is_empty());
```

PS: The dev guidelines are amazing. Thanks a lot for writing them!

changelog: Add `bool_assert_comparison` lint
2021-04-21 13:58:53 +00:00
Guillaume Gomez
e2e104b993 Add lint to check for boolean comparison in assert macro calls 2021-04-19 22:15:51 +02:00
Cameron Steffen
5af078ac1b Add flat_map_option lint 2021-04-16 15:23:49 -05:00
Cameron Steffen
0462666c70 Add cloned_instead_of_copied lint 2021-04-16 11:39:31 -05:00
Joshua Nelson
012f9d47b2 Use register_renamed instead of register_removed for uplifted lints
This still applies the lint, and also adds a structured suggestion to
rename it.
2021-04-09 10:56:11 -04:00
boxdot
4f7fc11ef1
Add invalid null pointer usage lint. 2021-04-08 22:49:48 +02:00
flip1995
f6d1f368db Merge commit 'b40ea209e7f14c8193ddfc98143967b6a2f4f5c9' into clippyup 2021-04-08 17:50:13 +02:00
xFrednet
a6f54f5dfd Renaming the lint to branches_sharing_code and fixing typos 2021-04-05 13:35:51 +02:00
xFrednet
d1df73228a A new lint for shared code in if blocks
* Added expression check for shared_code_in_if_blocks
* Finishing touches for the shared_code_in_if_blocks lint
* Applying PR suggestions
* Update lints yay
* Moved test into subfolder
2021-04-05 13:33:45 +02:00
bors
775ef473d7 Auto merge of #6342 - bbqbaron:issue-6061, r=flip1995
Lint: filter(Option::is_some).map(Option::unwrap)

Fixes #6061

*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog:
* add new lint for filter(Option::is_some).map(Option::unwrap)

First Rust PR, so I'm sure I've violated some idioms. Happy to change anything.

I'm getting one test failure locally -- a stderr diff for `compile_test`. I'm having a hard time seeing how I could be causing it, so I'm tentatively opening this in the hopes that it's an artifact of my local setup against `rustc`. Hoping it can at least still be reviewed in the meantime.

I'm gathering that since this is a method lint, and `.filter(...).map(...)` is already checked, the means of implementation needs to be a little different, so I didn't exactly follow the setup boilerplate. My way of checking for method calls seems a little too direct (ie, "is the second element of the expression literally the path for `Option::is_some`?"), but it seems like that's how some other lints work, so I went with it. I'm assuming we're not concerned about, eg, closures that just end up equivalent to `Option::is_some` by eta reduction.
2021-03-31 16:19:07 +00:00
Eric Loren
56fbbf7b8f Suggest flatten instead of is_some -> unwrap 2021-03-31 11:35:24 -04:00
Yoshitomo Nakanishi
527fbbef48 Refactor excessive_for_each 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
5029dc805f New Lint: excessive_for_each 2021-04-01 00:05:42 +09:00
Elliot Bobrow
7fcd155712 Add non_octal_unix_permissions lint 2021-03-30 16:04:16 -07:00
xFrednet
3a4c0a7fd8
Updated changelog for 1.52
Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>
2021-03-25 19:37:31 +01:00
flip1995
9f6b5de7de Merge commit '0e87918536b9833bbc6c683d1f9d51ee2bf03ef1' into clippyup 2021-03-25 19:29:11 +01:00
flip1995
f2f2a005b4 Merge commit '6ed6f1e6a1a8f414ba7e6d9b8222e7e5a1686e42' into clippyup 2021-03-12 15:30:50 +01:00
Yusuke Tanaka
a672d335a2
Implement new lint: if_then_some_else_none 2021-03-07 02:08:46 +09:00
Takayuki Maeda
51617b83a1 new lint: iter_count 2021-02-27 14:15:57 +09:00
Andrea Nall
3d3cfd3754 added new lint implicit_clone 2021-02-26 19:13:47 -06:00
flip1995
f64149dd04 Merge commit '928e72dd10749875cbd412f74bfbfd7765dbcd8a' into clippyup 2021-02-25 11:25:22 +01:00
bors
a2c25fa9f0 Auto merge of #6573 - Jarcho:option_match_map, r=llogiq
New lint: option_manual_map

fixes: #6
changelog: Added lint: `match_map`
2021-02-23 21:56:25 +00:00
Jason Newcomb
efe33f9fe4
Add: option_manual_map lint 2021-02-21 22:06:03 -05: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
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
boolean_coercion
b80ac2af9c Added boilerplate 2021-02-12 11:54:22 +02:00
flip1995
cc82e559f6
Update changelog for 1.51 2021-02-11 16:49:44 +01:00
flip1995
8b9f4a0d34 Merge commit '70c0f90453701e7d6d9b99aaa1fc6a765937b736' into clippyup 2021-02-11 15:04:38 +01:00
Takayuki Maeda
1c3033d5cf add a new lint bytes_nth 2021-02-08 01:34:59 +09:00
bors
ad9ceeebdc Auto merge of #6685 - magurotuna:filter_map_identity, r=phansch
Add new lint `filter_map_identity`

<!--
Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
`changelog: none`. Otherwise, please write a short comment
explaining your change.

If your PR fixes an issue, you can add "fixes #issue_number" into this
PR description. This way the issue will be automatically closed when
your PR is merged.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

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

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR.
-->

This commit adds a new lint named filter_map_identity.
This lint is the same as `flat_map_identity` except that it checks for the usage of `filter_map`.

---

Closes #6643

changelog: Added a new lint: `filter_map_identity`
2021-02-07 09:55:32 +00:00
Yusuke Tanaka
a60c143fe0
Add new lint filter_map_identity
This commit adds a new lint named `filter_map_identity`. This lint is
the same as `flat_map_identity` except that it checks for `filter_map`.

Closes #6643
2021-02-06 18:03:14 +09:00
Bastian Kersting
eb9c6698ee First version of the lint 2021-02-05 20:19:22 +01:00
bors
357c6a7e27 Auto merge of #6646 - nahuakang:for_loops_over_options_or_results, r=flip1995
New Lint: Manual Flatten

This is a draft PR for [Issue 6564](https://github.com/rust-lang/rust-clippy/issues/6564).

r? `@camsteffen`

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

---

*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog: Add new lint [`manual_flatten`] to check for loops over a single `if let` expression with `Result` or `Option`.
2021-02-04 10:03:45 +00:00
Yoshitomo Nakanishi
e32e4dedf1 New lint: default_numeric_fallback 2021-02-04 17:26:43 +09:00
Manish Goregaokar
c8cb90abbd Merge commit '3e4179766bcecd712824da04356621b8df012ea4' into sync-from-clippy 2021-02-02 20:43:30 -08:00
Caden Haustein
bde667af7e
Add missing_panics_doc lint 2021-02-02 16:36:32 +01:00
nahuakang
b87e189694 Implement manual flatten lint 2021-02-01 16:58:31 +01:00
nahuakang
8973f2c03a Run cargo dev update_lints 2021-02-01 16:49:53 +01:00
nahuakang
3da25ed955 Rename lint 2021-02-01 16:49:53 +01:00
nahuakang
5753614152 Draft skeleton for new lint 2021-02-01 16:49:53 +01:00
flip1995
ac912be984 Merge commit '95c0459217d1661edfa794c8bb122452b92fb485' into clippyup 2021-01-30 18:06:34 +01:00
bors
8d57cee9ca Auto merge of #6617 - Manishearth:exhaustive_enums, r=camsteffen
New lint: exhaustive_enums, exhaustive_structs

Fixes #6616

changelog: Added restriction lint: `exhaustive_enums`, `exhaustive_structs`
2021-01-25 23:06:39 +00:00
Manish Goregaokar
8cb7e85006 Add exhaustive_structs lint 2021-01-22 11:59:36 -08:00
Cameron Steffen
a752d31e0a Replace find_map with manual_find_map 2021-01-21 18:18:21 -06:00
Cameron Steffen
c92bdc4dbb Split filter_map into manual_filter_map 2021-01-21 18:18:18 -06:00
Manish Goregaokar
f1ab3024b2 New lint: exhaustive_enums 2021-01-21 13:31:06 -08:00
Hirochika Matsumoto
ab1da8f865 Add new lint upper_case_acronyms 2021-01-20 18:03:06 +09:00
Hirochika Matsumoto
6c830ff9e4 Run cargo dev new_lint 2021-01-20 18:02:29 +09:00
bors
d71dea40cf Auto merge of #6577 - nahuakang:inspect_then_for_each, r=flip1995
New Lint: inspect_then_for_each

**Work In Progress**

This PR addresses [Issue 5209](https://github.com/rust-lang/rust-clippy/issues/5209) and adds a new lint called `inspect_then_for_each`.

Current seek some guidance.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[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: Add [`inspect_for_each`] lint for the use of `inspect().for_each()` on `Iterators`.
2021-01-19 13:12:39 +00:00
nahuakang
3269070261 Create new lint for the usage of inspect for each. 2021-01-19 11:30:20 +01:00
Jason Newcomb
837bc99065
Initial implementation of redundant_slicing lint 2021-01-15 16:41:13 -05:00
flip1995
488153ff2f Merge commit '953f024793dab92745fee9cd2c4dee6a60451771' into clippyup 2021-01-15 10:56:44 +01:00
Javier Alvarez
61f3d9d46b Add case_sensitive_file_extensions lint
Closes #6425

Looks for ends_with methods calls with case sensitive extensions.
2021-01-05 14:22:26 +01:00
rail
4b478a5731 Add a new lint ptr_as_ptr,
which checks for `as` casts between raw pointers
without changing its mutability
and suggest replacing it with `pointer::cast`.
2021-01-05 10:19:03 +13:00
bors
976850b69b Auto merge of #6538 - Jarcho:vec_init_then_push, r=llogiq
New lint: vec_init_then_push

fixes: #1483

This will trigger on `new`, `default`, and `with_capacity` when the given capacity is less than or equal to the number of push calls. Is there anything else this should trigger on?

changelog: Added lint: `vec_init_then_push`
2021-01-04 20:42:18 +00:00
bors
ae9ae9713c Auto merge of #6507 - bengsparks:lint/issue6410, r=flip1995
Needless Question Mark Lint

Fixes #6410, i.e the needless question mark lint

changelog: [`needless_question_mark`] New lint
2021-01-04 14:17:24 +00:00
Benjamin Sparks
ba87acb440
Implemented needless question mark lint 2021-01-04 14:51:48 +01:00
Matthias Krüger
6dcec6ae86 collapsible_if: split collapsible_else_if into its own lint so we can enable/disable it particularly
This splits up clippy::collapsible_if into collapsible_if for
if x {
  if y { }
}
=>
if x && y { }

and collapsible_else_if for

if x {
} else {
 if y { }
}

=>
if x {

} else if y {

}

so that we can lint for only the latter but not the first if we desire.

changelog: collapsible_if: split up linting for if x {} else { if y {} } into collapsible_else_if lint
2021-01-04 13:34:14 +01:00
bors
78f6009878 Auto merge of #6520 - phansch:update-changelog, r=flip1995
Update CHANGELOG for Rust 1.50

changelog: none

r? `@flip1995`
2021-01-02 16:13:24 +00:00
Jason Newcomb
1853f8b228
Add lint 2021-01-02 11:08:56 -05:00
flip1995
ba4bf4f9c5 Merge commit '1fcc74cc9e03bc91eaa80ecf92976b0b14b3aeb6' into clippyup 2021-01-02 16:29:43 +01:00
Philipp Hansch
b81111bc35
Address review comments 2020-12-30 17:29:15 +01:00