Commit graph

808 commits

Author SHA1 Message Date
bors
4a07662d94 Auto merge of #8561 - FoseFx:use_unwrap_or, r=xFrednet
add `or_then_unwrap`

Closes #8557

changelog: New lint [`or_then_unwrap`]
2022-03-21 20:08:29 +00:00
Max Baumann
3c4192f3e9
fix: ran update_lints 2022-03-18 01:12:39 +01:00
Max Baumann
05e05eaed7
refactor: rename lint to or_then_unwrap 2022-03-18 01:04:33 +01:00
Jason Newcomb
39329d1d40 Add lint cast_enum_constructor 2022-03-17 19:57:35 -04:00
Max Baumann
f49a2c3457
feat: add use_unwrap_or 2022-03-17 18:57:28 +01:00
bors
e2e492c10e Auto merge of #8422 - buttercrab:only_used_in_recursion, r=llogiq
new lint: `only_used_in_recursion`

changed:
- added `only_used_in_recursion`.
- fixed code that variables are only used in recursion.
- this would not lint when `unused_variable`

This fixes: #8390

-----

changelog: add lint [`only_used_in_recursion`]
2022-03-13 16:11:25 +00:00
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
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
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
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
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
Piotr Mikulski
1c9b31d350 New line: cloned_next 2022-01-16 09:59:29 -08: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
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
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
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
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