Commit Graph

4232 Commits

Author SHA1 Message Date
Jason Newcomb
b37317b028 Check if there are any overlapping patterns between equal arm bodies in match_same_arm 2022-03-16 13:18:29 -04:00
Jason Newcomb
47c9ed697b Fix checking transmutes with adjusted types 2022-03-15 23:11:11 -04:00
Jason Newcomb
911e10562a Don't lint transmute_undefined_repr on unions. 2022-03-15 22:38:15 -04:00
Jason Newcomb
442d4ce1c3 Don't lint fat pointer to (usize, usize) conversion in transmute_undefined_repr 2022-03-15 22:31:07 -04:00
Jason Newcomb
e71ac41d44 Fix transmute_undefined_repr for single element tuples 2022-03-15 21:51:07 -04:00
bors
71ecbc42f9 Auto merge of #8509 - smoelius:fix-8507, r=giraffate
Fix `unncessary_to_owned` false positive

Fix #8507

changelog: none
2022-03-15 01:08:47 +00:00
xFrednet
2ee5372389
Allow single_component_path_imports for all macros 2022-03-14 22:45:00 +01:00
flip1995
d5ab347d5c
Merge remote-tracking branch 'upstream/master' into rustup 2022-03-14 11:29:18 +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
086b045822 add checking for x -> x and ref x -> x and related test cases. 2022-03-10 14:46:58 +08:00
Jaeyong Sung
69161c6327
fix to lint Self::function 2022-03-10 15:46:40 +09:00
J-ZhengLi
ec9116412a rename lint to needless_match
and change its lint group to "complexity"
2022-03-10 09:44:25 +08:00
J-ZhengLi
750204e3e3 fix a bug that caused internal test fail 2022-03-08 18:15:11 +08:00
J-ZhengLi
6bfc1120cf add nop if-let expression check.
re-design test cases as some of them are not worth the effort to check.
2022-03-08 17:37:53 +08:00
Eric Holk
43ce0a94af Update and fix clippy tests 2022-03-07 08:47:18 -08:00
J-ZhengLi
db3fcf8df7 add basic code to check nop match blocks
modify `manual_map_option` uitest because one test case has confliction.
2022-03-07 18:12:35 +08:00
Jaeyong Sung
e4766776d2
add test for trait recursion 2022-03-07 12:15:00 +09: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
Samuel E. Moelius III
1a95590faf Fix #8507 2022-03-05 21:18:44 -05:00
Jaeyong Sung
2b0f9aba64
don't lint when implementing trait 2022-03-05 21:39:00 +09:00
Esteban Kuber
90da7cdd41 Do not point at whole file missing fn main
Only point at the end of the crate. We could try making it point at the
beginning of the crate, but that is confused with `DUMMY_SP`, causing
the output to be *worse*.

This change will make it so that VSCode will *not* underline the whole
file when `main` is missing, so other errors will be visible.
2022-03-05 02:42:55 +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
bors
53189ad190 Auto merge of #8500 - rust-lang:testless-dbg-macro, r=Manishearth
Omit dbg_macro in test code

This fixes #8481.

---

changelog: none
2022-03-03 18:32:07 +00:00
Andre Bogus
63907234d7 Omit dbg_macro in test code 2022-03-03 19:28:05 +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
Ralf Jung
c45a42a332 bless clippy 2022-03-02 19:20:27 -05: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
bors
2e40dc81b7 Auto merge of #8456 - ebobrow:use_self_pat, r=llogiq
check `use_self` in `pat`

fixes #6955

changelog: check `use_self` in `pat`
2022-03-02 19:31:22 +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
Samuel E. Moelius III
cfd32522c0 Add tests to tests/ui/unnecessary_filter_map.rs
The tests currently fail, and are fixed by the next commit.
2022-02-28 05:24:00 -05:00
Elliot Bobrow
914ae1e849 check use_self in pat 2022-02-26 09:23:29 -08:00
bors
d1ca1c1d0c Auto merge of #8462 - ken-matsui:use-precise-namespace-for-reverse, r=llogiq
Use the precise namespace for `Reverse`

Closes: https://github.com/rust-lang/rust-clippy/issues/8461

changelog: [`unnecessary_sort_by`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by): Use the precise namespace for `Reverse`
2022-02-26 14:49:39 +00:00
flip1995
35020280a0 Merge commit 'e329249b6a3a98830d860c74c8234a8dd9407436' into clippyup 2022-02-26 14:26:21 +01:00
bors
e329249b6a Auto merge of #8464 - Jarcho:ptr_arg_8463, r=camsteffen
Fix `ptr_arg`

fixes: #8463

changelog: Fix `ptr_arg` when multiple arguments are being checked in one function
2022-02-26 03:00:53 +00:00
bors
2c8d5a2500 Auto merge of #8453 - tamaroning:fix_large_enum_variant, r=camsteffen
fix false positives of large_enum_variant

fixes: #8321
The size of enums containing generic type was calculated to be 0.
I changed [large_enum_variant] so that such enums are not linted.

changelog: none
2022-02-26 02:42:43 +00:00
Alex Macleod
52f3d61a2a Add print_in_format_impl lint 2022-02-25 21:10:06 +00:00
Florian Nagel
862211d540 Disable `[new-without-default]` for new() methods that are marked with '#[doc(hidden)]'
Fixes issue #8152
2022-02-25 16:34:37 +01:00
J-ZhengLi
30fb8229e1 add tests, add base bone for the new lint 2022-02-25 18:08:52 +08:00
Vadim Petrochenkov
a30eba2c7e Update clippy tests 2022-02-24 22:55:40 +03:00
tamaron
db62821c03 fix 2022-02-24 00:16:24 +09:00
Jason Newcomb
382b3f0601 Fix counting the number of unchangeable arguments in ptr_arg 2022-02-23 01:04:49 -05:00
Ken Matsui
7412e6976e
Use the precise namespace for Reverse 2022-02-23 06:06:09 +09:00
bors
9e605ef80f Auto merge of #8443 - Jarcho:match_cfg_arm, r=flip1995
Don't lint `match` expressions with `cfg`ed arms

Somehow there are no open issues related to this for any of the affected lints. At least none that I could fine from a quick search.

changelog: Don't lint `match` expressions with `cfg`ed arms in many cases
2022-02-21 08:46:42 +00:00
tamaron
e3b5cac3c8 fix 2022-02-21 13:25:53 +09:00
Jason Newcomb
d28d19d74c Fix transmute_undefined_repr when converting between a fat pointer and a type containing a fat pointer 2022-02-18 15:02:28 -05:00
Jason Newcomb
7c07022c98 Allow transmuting fat pointers to some types in transmute_undefined_repr 2022-02-18 15:02:28 -05:00