Commit Graph

963 Commits

Author SHA1 Message Date
bors
75b616e92f Auto merge of #8471 - J-ZhengLi:master-issue7040, r=llogiq
new lint that detects useless match expression

fixes #7040

changelog: Add new  lint [`needless_match`] under complexity lint group
2022-03-13 14:49:56 +00:00
J-ZhengLi
ec9116412a rename lint to needless_match
and change its lint group to "complexity"
2022-03-10 09:44:25 +08:00
bors
0c483f69db Auto merge of #8445 - asquared31415:slice_ptr_cast, r=llogiq
Llint for casting between raw slice pointers with different element sizes

This lint disallows using `as` to convert from a raw pointer to a slice (e.g. `*const [i32]`, `*mut [Foo]`) to any other raw pointer to a slice if the element types have different sizes.  When a raw slice pointer is cast, the data pointer and count metadata are preserved.  This means that when the size of the inner slice's element type changes, the total number of bytes pointed to by the count changes.  For example a `*const [i32]` with length 4 (four `i32` elements) is cast `as *const [u8]` the resulting pointer points to four `u8` elements at the same address, losing most of the data.  When the size *increases* the resulting pointer will point to *more* data, and accessing that data will be UB.

On its own, *producing* the pointer isn't actually a problem, but because any use of the pointer as a slice will either produce surprising behavior or cause UB I believe this is a correctness lint.  If the pointer is not intended to be used as a slice, the user should instead use any of a number of methods to produce just a data pointer including an `as` cast to a thin pointer (e.g. `p as *const i32`) or if the pointer is being created from a slice, the `as_ptr` method on slices.  Detecting the intended use of the pointer is outside the scope of this lint, but I believe this lint will also lead users to realize that a slice pointer is only for slices.

There is an exception to this lint when either of the slice element types are zero sized (e.g `*mut [()]`).  The total number of bytes pointed to by the slice with a zero sized element is zero.  In that case preserving the length metadata is likely intended as a workaround to get the length metadata of a slice pointer though a zero sized slice.

The lint does not forbid casting pointers to slices with the *same* element size as the cast was likely intended to reinterpret the data in the slice as some equivalently sized data and the resulting pointer will behave as intended.

---

changelog: Added ``[`cast_slice_different_sizes`]``, a lint that disallows using `as`-casts to convert between raw pointers to slices when the elements have different sizes.
2022-03-06 07:46:56 +00:00
bors
48d54942f5 Auto merge of #8504 - xFrednet:8502-allow-lint-without-reason, r=flip1995
Add lint to detect `allow` attributes without reason

I was considering putting this lint into the pedantic group. However, that would result in countless warnings for existing projects. Having it in restriction also seems good to me 🙃 (And now I need sleep 💤 )

---

changelog: New lint [`allow_lint_without_reason`] (Requires the `lint_reasons` feature)

Closes: rust-lang/rust-clippy#8502
2022-03-04 19:23:39 +00:00
asquared31415
f932c304bb lint for casting raw pointers to slices with different element sizes 2022-03-04 13:23:06 -05:00
xFrednet
ab6ffb6371
Add lint to detect allow attributes without reason 2022-03-04 17:45:43 +01:00
Liu Dingming
6cc2eeaa56 Suggest into_iter() over drain(..)
Add doc

Add description

iter_with_drain dogfood

Disable emiting on struct field.

Fix clippy

Add eq_path for SpanlessEq

Fix tests

Better error message

Fix doc test

Fix version

Apply suggestions
2022-03-03 13:10:19 +08:00
bors
6e211eac7c Auto merge of #8489 - smoelius:unnecessary-find-map, r=llogiq
Add `unnecessary_find_map` lint

This PR adds an `unnecessary_find_map` lint. It is essentially just a minor enhancement of `unnecessary_filter_map`.

Closes #8467

changelog: New lint `unnecessary_find_map`
2022-03-02 19:50:27 +00:00
Andre Bogus
9f1080cc6e new lint: missing-spin-loop 2022-03-02 19:31:06 +01:00
Samuel E. Moelius III
2a588d810f Add unnecessary_find_map lint 2022-03-01 19:24:55 -05:00
flip1995
35020280a0 Merge commit 'e329249b6a3a98830d860c74c8234a8dd9407436' into clippyup 2022-02-26 14:26:21 +01:00
Alex Macleod
52f3d61a2a Add print_in_format_impl lint 2022-02-25 21:10:06 +00:00
J-ZhengLi
30fb8229e1 add tests, add base bone for the new lint 2022-02-25 18:08:52 +08:00
Jason Newcomb
90bb7a3476 New lint cast_enum_truncation 2022-02-18 09:16:17 -05:00
bors
668b3e47f9 Auto merge of #8218 - Jarcho:redundant_slicing_deref, r=camsteffen
Improve `redundant_slicing` lint

fixes #7972
fixes #7257

This can supersede #7976

changelog: Fix suggestion for `redundant_slicing` when re-borrowing for a method call
changelog: New lint `deref_as_slicing`
2022-02-17 16:08:45 +00:00
Jason Newcomb
113ac6e15e Split off new lint deref_by_slicing from redundant_slicing 2022-02-17 00:02:26 -05:00
James McMurray
b162b11abc Add recursive_format_impl lint
The to_string_in_display lint is renamed to recursive_format_impl
A check is added for the use of self formatted with Display or Debug
inside any format string in the same impl
The to_string_in_display check is kept as is - like in the
format_in_format_args lint

For now only Display and Debug are checked
This could also be extended to other Format traits (Binary, etc.)
2022-02-14 18:49:51 +01:00
Jaeyong Sung
4f96ca353e
add only_used_in_recursion lint
- fix code that have variables that is "only used in recursion"
- add test
2022-02-13 02:32:09 +09:00
flip1995
611d039814 Merge commit '57b3c4b90f4346b3990c1be387c3b3ca7b78412c' into clippyup 2022-02-10 18:40:06 +01:00
bors
093e32052e Auto merge of #8398 - Jarcho:unordered_transmute, r=llogiq
Add lint `transmute_undefined_repr`

Partially implements #3999 and #546

This doesn't consider `enum`s at all right now as those are going to be a pain to deal with. This also allows `#[repr(Rust)]` structs with only one non-zero sized fields. I think those are technically undefined when transmuted.

changelog: Add lint `transmute_undefined_repr`
2022-02-06 16:05:00 +00:00
Jason Newcomb
3403b3e717 Add lint transumte_undefined_repr 2022-02-05 16:28:25 -05:00
bors
b8c80ddbb5 Auto merge of #8330 - flip1995:changelog, r=llogiq
Update Changelog

[Rendered](https://github.com/flip1995/rust-clippy/blob/changelog/CHANGELOG.md)

changelog: none
2022-02-01 19:30:25 +00:00
cameron
cb29e3effb add doc_link_with_quotes lint 2022-02-01 11:21:42 +00:00
bors
7ceffdee9b Auto merge of #8289 - jubnzv:unspecified-layout-union, r=camsteffen
Add `default_union_representation` lint

Closes #8235

changelog: Added a new lint  [`default_union_representation`]
2022-01-29 10:58:16 +00:00
Georgy Komarov
b7000b2a53 Add default_union_representation lint
Closes #8235
2022-01-29 07:02:28 +03:00
flip1995
bf66aeda0a Merge commit 'a98e7ab8b94485be6bd03e0c6b8682ecab5b52e6' into clippyup 2022-01-27 15:12:45 +01:00
flip1995
64f5b3611e
Update Changelog 2022-01-25 16:59:31 +01:00
Jason Newcomb
c61514086d Subsume ref_in_deref into needless_borrow 2022-01-22 21:22:33 -05:00
Jason Newcomb
9e9110e4f3 Remove final reference on fields and method calls in needless_borrow 2022-01-22 20:35:32 -05:00
flip1995
ddad101b8a Merge commit '8d14c94b5c0a66241b4244f1c60ac5859cec1d97' into clippyup 2022-01-17 13:29:07 +01:00
Piotr Mikulski
1c9b31d350 New line: cloned_next 2022-01-16 09:59:29 -08:00
flip1995
fb0142ae41 Merge commit '97a5daa65908e59744e2bc625b14849352231c75' into clippyup 2022-01-13 13:18:19 +01:00
Paolo Barbolini
166737f3cb Add manual_bits lint 2022-01-12 16:46:57 +01:00
Federico Guerinoni
3298de7f66 Add borrow_as_ptr lint
Closes: #6995

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
2022-01-11 09:53:29 +01:00
bors
a6f80fccb1 new lint: single_char_lifetime_names
This pull request adds a lint against single character lifetime names, as they might not divulge enough information about the purpose of the lifetime. This can make code harder to understand. I placed this in `restriction` rather than `pedantic` (as suggested in #8233) since most of the Rust ecosystem already uses single character lifetime names (to my knowledge, at least) and since single character lifetime names aren't incorrect. I'd be happy to change this upon request, however. Fixes #8233.

- [x] Followed lint naming conventions
- [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`

changelog: new lint: [`single_char_lifetime_names`]
2022-01-09 14:27:36 +00:00
flip1995
97ab44ca97 Merge commit '0eff589afc83e21a03a168497bbab6b4dfbb4ef6' into clippyup 2021-12-30 15:10:43 +01:00
Andre Bogus
3ebd2bc2e4 new lint: init-numbered-fields 2021-12-26 16:19:22 +01:00
flip1995
adcd3ded13
Fix commits and formatting of CHANGELOG.md 2021-12-17 16:27:29 +01:00
Manish Goregaokar
69bd99f8e0
Update CHANGELOG.md
Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>
2021-12-17 19:51:01 +05:30
Manish Goregaokar
8160ccd3ac
Update CHANGELOG.md
Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>
2021-12-17 19:50:53 +05:30
Manish Goregaokar
80e986485c Update changelog 2021-12-17 19:39:07 +05:30
flip1995
ece0946d7f Merge commit '23d11428de3e973b34a5090a78d62887f821c90e' into clippyup 2021-12-17 13:40:22 +01:00
Samuel E. Moelius III
468c86e4a3 Add unnecessary_to_owned lint 2021-12-13 06:31:17 -05:00
Guillaume Gomez
8dfb3ec8a4 Add new lint to warn when #[must_use] attribute should be used on a method 2021-12-08 11:16:14 +01:00
flip1995
8fea1d94f3 Merge commit 'a5d597637dcb78dc73f93561ce474f23d4177c35' into clippyup 2021-12-06 12:33:31 +01:00
Alex Macleod
3957244120 Add needless_late_init lint 2021-11-23 15:08:49 +00:00
Georg Brandl
982124acfa Add new lint octal_escapes
This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.
2021-11-20 11:57:25 +01:00
flip1995
9b38fb7b71
Also pluralize disallowed_method(s) lint
To stay consistent with the sister lint disallowed_type, also rename the
disallowed_method lint to disallowed_methods.
2021-11-18 17:37:06 +01:00
Philipp Hansch
b7f18916fa
Pluralize disallowed_type lint
This was brought up in [Zulip] and is also mentioned in the lint naming
conventions. Since this is still a nursery lint, I think there shouldn't
be any problem in renaming it.

[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/disallow_type.20vs.20disallowed-types
2021-11-18 17:37:02 +01:00
bors
46687f1313 Auto merge of #7896 - surechen:fix_manual_split_once, r=camsteffen
Fix for #7889 and add new lint needless_splitn

fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.
2021-11-17 01:46:58 +00:00
surechen
c051656c83 fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.
2021-11-17 08:38:45 +08:00
xFrednet
e444cbe5d6
New index_refutable_slice lint
* Finding pattern slices for `avoidable_slice_indexing`
* `avoidable_slice_indexing` analysing slice usage
* Add configuration to `avoidable_slice_indexing`
* Emitting `avoidable_slice_indexing` with suggestions
* Dogfooding and fixing bugs
* Add ui-toml test for `avoidable_slice_indexing`
* Correctly suggest `ref` keywords for `avoidable_slice_indexing`
* Test and document `mut` for `avoid_slice_indexing`
* Handle macros with `avoidable_slice_indexing` lint
* Ignore slices with sub patterns in `avoidable_slice_indexing`
* Update lint description for `avoidable_slice_indexing`
* Move `avoidable_slice_indexing` to nursery
* Added more tests for `avoidable_slice_indexing`
* Update documentation and message for `avoidable_slice_indexing`
* Teach `avoidable_slice_indexing` about `HirId`s and `Visitors`
* Rename lint to `index_refutable_slice` and connected config
2021-11-11 17:34:02 +01:00
flip1995
e674d0a599 Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup 2021-11-04 12:52:36 +00:00
bors
38d80257d0 Auto merge of #7726 - dswij:unseparated-literal-suffix, r=flip1995
Unseparated literal suffix

Closes #7658

Since `literal_suffix` style is opinionated, we should disable by default and only enforce if it's stated as so.

changelog: [`unseparated_literal_suffix`] is renamed to `literal_suffix`, adds a new configuration `literal-suffix-style` to enforce a certain style writing literal_suffix. Possible values for `literal-suffix-style`: `"separated"`, `"unseparated"`
2021-11-02 09:57:12 +00:00
dswij
bb1cf72999 Update CHANGELOG to include separated_literal_suffix 2021-11-01 22:26:38 +08:00
Cameron Steffen
022146d2c3 Rename if_then_panic to manual_assert 2021-10-28 09:41:53 -05:00
bors
962e21cf15 Auto merge of #7875 - mbStavola:unit-hash, r=xFrednet
Add unit-hash lint

changelog: [`unit_hash`] Add lint for hashing unit values

This will lint for situations where the end user is attempting to hash a unit value (`()`), as the implementation in `std` simply [does nothing][impl]. Closes #7159 .

Example:

```rust
().hash(&mut state);

// Should (probably) be replaced with:
0_u8.hash(&mut state);
```

[impl]: a5f164faad/library/core/src/hash/mod.rs (L656)
2021-10-27 14:37:54 +00:00
Matt Stavola
36d4a4ea82
Add unit-hash lint 2021-10-27 06:32:37 -07:00
bors
075996efd7 Auto merge of #7878 - rust-lang:string-slice, r=giraffate
new lint: string-slice

This is a restriction lint to highlight code that should have tests containing non-ascii characters. See #6623.

changelog: new lint: [`string-slice`]
2021-10-26 08:11:49 +00:00
Andre Bogus
999b3004c4 new lint: string-slice 2021-10-26 09:05:28 +02:00
flip1995
949fc44ccc
Update CHANGELOG 2021-10-25 10:50:49 +02:00
flip1995
7631fc5d82 Merge commit '91496c2ac6abf6454c413bb23e8becf6b6dc20ea' into clippyup 2021-10-21 13:11:36 +02:00
flip1995
085181e29d
Merge remote-tracking branch 'upstream/master' into rustup 2021-10-21 12:18:12 +02:00
bors
300b821d51 Auto merge of #7838 - nhamovitz:trailing_zs_arr_wo_repr, r=Manishearth
Warn on structs with a trailing zero-sized array but no `repr` attribute

Closes #2868

changelog: Implement ``[`trailing_empty_array`]``, which warns if a struct is defined where the last field is a zero-sized array but there are no `repr` attributes. Zero-sized arrays aren't very useful in Rust itself, so such a struct is likely being created to pass to C code or in some other situation where control over memory layout matters. Either way, a `repr` attribute is needed.
2021-10-20 20:35:58 +00:00
bors
06722c0c15 Auto merge of #7775 - F3real:no_effect, r=xFrednet
Detect underscored variables with no side effects

Fixes #7545

changelog: Lint on underscored variables with no side effects in [`no_effect`]
2021-10-20 09:33:45 +00:00
F3real
6b22bba902 Lint on underscore variable assignment
Fix tests after no_effect update

Add a drop testcase

Don't lint _ variables in macro expansion

Address review comments and update tests

Don't shadow unnecessary operation lint if no_effect is allowed

Revert shadowing change and remove no_effect allows

Update clippy_lints/src/no_effect.rs

Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>

Update clippy_lints/src/no_effect.rs

Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>

Address review comments
2021-10-20 00:39:28 +02:00
Nathaniel Hamovitz
0f9f591e30 Rename lint 2021-10-19 14:33:43 -07:00
Nathaniel Hamovitz
7f84e3d791 Rename lint 2021-10-18 03:45:08 -07:00
Nathaniel Hamovitz
797507c583 Add boilerplate and basic tests 2021-10-18 03:05:18 -07:00
Samuel E. Moelius III
c9599d79a3 Add format_in_format_args and to_string_in_format_args lints
Fixes #7667 and #7729
2021-10-15 12:44:38 -04:00
bors
b9b11a96d2 Auto merge of #7805 - aDotInTheVoid:transmute-num-bits, r=camsteffen
Add lint transmute_num_to_bytes

Closes #7803

changelog: [`transmute_num_to_bytes`] new lint
2021-10-13 19:40:33 +00:00
Nixon Enraght-Moony
58969807ab Add lint transmute_num_to_bytes
Closes #7803

changelog: [`transmute_num_to_bytes`] new lint
2021-10-13 20:05:05 +01:00
bors
3d9c4a655b Auto merge of #7682 - Qwaz:uninit_vec, r=xFrednet
Implement uninit_vec lint

changelog: add the new lint [`uninit_vec`]

Fix #7681
2021-10-12 21:04:13 +00:00
Serial
9e0ce14700 Add match_str_case_mismatch lint 2021-10-11 20:19:34 -04:00
flip1995
f44a904a56 Deprecate mem_discriminant_non_enum
This lint has been uplifted and is now included in
enum_intrinsics_non_enums.
2021-10-11 10:10:16 +02:00
Yechan Bae
452181c69d Implement uninit_vec lint 2021-10-09 05:38:19 -04:00
Serial
412b862fba Add undocumented_unsafe_blocks lint 2021-10-07 17:06:21 -04:00
Michael Sproul
fbd0fb9aed Restriction lint for function pointer casts 2021-10-07 09:11:47 -05:00
flip1995
5cf4984872 Merge commit 'b7f3f7f6082679da2da9a0b3faf1b5adef3afd3b' into clippyup 2021-10-07 11:21:30 +02:00
hkalbasi
388a3d0983 Implement equatable if let lint 2021-10-04 22:16:42 +03:30
Yechan Bae
fb0353b28d Update documentation and name for non_send_fields_in_send_ty lint 2021-10-02 19:22:37 -04:00
Yechan Bae
e4c3000e5b Initial implementation 2021-10-01 14:04:20 -04:00
flip1995
23d5457e6d Merge commit 'cb7915b00c235e9b5861564f3be78dba330980ee' into clippyup 2021-09-28 18:03:12 +01:00
bors
08cead31a1 Auto merge of #7727 - flip1995:changelog, r=xFrednet
Update changelog to 1.56

As expected a pretty short changelog, because of the missed sync last release cycle.

[Rendered](https://github.com/flip1995/rust-clippy/blob/changelog/CHANGELOG.md)

changelog: none
2021-09-28 10:27:47 +00:00
flip1995
7f11e5a914
Fix CHANGELOG formatting 2021-09-28 11:08:40 +01:00
Andrew Pollack
b6ffb29315 Adjusting changelog 2021-09-27 22:23:17 -07:00
Andrew Pollack
9a3ccd8547 Removed value from changelog to get pass 2021-09-27 22:23:17 -07:00
Andrew Pollack
b7d40bc103 Adding new linting 2021-09-27 22:23:17 -07:00
flip1995
46f8aa9c31
Update changelog to 1.56 2021-09-27 11:59:33 +02:00
Labelray
543b638dbe Add new lint if_then_panic 2021-09-24 22:14:20 +08:00
F3real
bb971e0f58 Add missing reference to box_vec 2021-09-22 20:06:03 +02:00
F3real
63ed2f9eb4 Expand BOX_VEC to BOX_COLLECTION 2021-09-20 10:23:55 +02:00
lengyijun
e2cdaec984 same_name_method 2021-09-14 09:20:27 +08:00
Labelray
8f88acdbfa add new lint iter_not_returning_iterator 2021-09-09 09:21:38 +08:00
flip1995
091ed44b50 Merge commit '27afd6ade4bb1123a8bf82001629b69d23d62aff' into clippyup 2021-09-08 16:31:47 +02:00
bors
7a0d7d8283 Auto merge of #7596 - lengyijun:option_needless_deref, r=llogiq
New lint: option_needless_deref

changelog: [`option_needless_deref`]
fix #7571
2021-09-05 18:11:56 +00:00
hamidreza kalbasi
8221f9e795 add derivable impls lint 2021-09-05 01:25:59 +04:30
lengyijun
4184cc369a needless_option_as_deref 2021-09-04 22:18:23 +08:00
flip1995
c7c2036cb9
Fix remaining dogfood errors
Except for the missing docs ones
2021-09-02 12:40:52 +01:00
flip1995
61bb96738c
Merge remote-tracking branch 'upstream/master' into rustup2 2021-09-02 12:38:17 +01:00
bors
de80188c64 Auto merge of #7543 - DevinR528:disallowed-mod, r=Manishearth
Add module_style lint to style

changelog: Add new [`module_style`] style lint

This is a configurable (no mod file/mod file) lint that determines if `mod.rs` is used consistently or if `mod.rs` is never used (using the new mod layout).
2021-08-25 15:20:28 +00:00
Devin Ragotzy
31738b1da3 Add module_style lint to restriction
Add tests for disallowed_mod in ui-cargo test section

Use correct algorithm to determine if mod.rs is missing

Move to two lints and remove config option

Switch lint names so they read "warn on ..."

Emit the same help info for self_named_mod_file warnings

Bail when both lints are Allow

Reword help message for both module_style lints
2021-08-24 15:53:58 -04:00
bors
22606e7358 Auto merge of #7539 - Labelray:master, r=camsteffen
Add new lint `negative_feature_names` and `redundant_feature_names`

Add new lint [`negative_feature_names`] to detect feature names with prefixes `no-` or `not-` and new lint [`redundant_feature_names`] to detect feature names with prefixes `use-`, `with-` or suffix `-support`
changelog: Add new lint [`negative_feature_names`] and [`redundant_feature_names`]
2021-08-23 13:56:18 +00:00
Labelray
0a021d5900 Add new lints negative_feature_names and redundant_feature_names 2021-08-23 21:05:44 +08:00
Jason Newcomb
a7f376fbd3
Add lint manual_split_once 2021-08-16 09:34:58 -04:00
flip1995
1ad5464200 Merge commit '7bfc26ec8e7a454786668e7e52ffe527fc649735' into clippyup 2021-08-12 11:16:25 +02:00
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