Commit graph

5415 commits

Author SHA1 Message Date
Jason Newcomb
ae5af0cd1a Remove cargo_metadata dependency from clippy 2022-04-01 23:18:47 -04:00
bors
6206086dd5 Auto merge of #8487 - dswij:8478, r=giraffate
[`map_identity`] checks for needless `map_err`

Closes #8478

changelog: [`map_identity`] checks for needless `map_err`
2022-03-28 00:25:45 +00:00
bors
59c0f29916 Auto merge of #8519 - tysg:redundant-modulo, r=giraffate
Check if lhs < rhs in modulos in `identity_op`

Fixes #8508

changelog: [`identity_op`] now checks for modulos, e.g. `1 % 3`
2022-03-28 00:11:32 +00:00
Tianyi Song
52b563b283 Emit lint when rhs is negative 2022-03-27 21:49:38 +08:00
flip1995
1147b2c481
Merge remote-tracking branch 'upstream/master' into rustup 2022-03-24 14:22:35 +01:00
Yoav Lavi
b60a7fb7b6
unnecessary_join lint 2022-03-24 13:18:18 +01:00
bors
f07ee8a998 Auto merge of #8232 - Jarcho:match_same_arm_860, r=xFrednet
`match_same_arms` fix

fixes #860
fixes #1140

changelog: Don't lint `match_same_arms` when an interposing arm's pattern would overlap
2022-03-21 20:42:51 +00:00
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
J-ZhengLi
5b6295d663 allowing [map_flatten] to split long suggestions
add new function `span_lint_and_sugg_` for edges in `clippy_utils::diagnostics`
2022-03-21 14:11:22 +08:00
Max Baumann
0f83753934
feat: change error message 2022-03-20 23:43:17 +01:00
Max Baumann
20c352a4f6
test: add method chain test 2022-03-19 18:17:43 +01:00
Max Baumann
895de1f13e
feat: make fixable 2022-03-18 23:18:36 +01:00
Max Baumann
f00e844a1f
feat: use span_lint_and_sugg 2022-03-18 22:44:56 +01:00
bors
a31dcb77be Auto merge of #8562 - Jarcho:enum_tuple_variant_as_int, r=Manishearth
Add lint `cast_enum_constructor`

fixes: #1116

changelog: Add lint `cast_enum_constructor`
2022-03-18 15:54:45 +00:00
Max Baumann
fd2c860171
feat: add comment 2022-03-18 14:45:48 +01:00
bors
9fd3c2d788 Auto merge of #8543 - dswij:8393, r=giraffate
`unnecessary_lazy_eval` show suggestions on multiline lint

Closes #8393

changelog: [`unnecessary_lazy_eval`] now shows suggestions for long-line lints
2022-03-18 00:42:18 +00: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
44c62c9aa2
feat: add tests and fix existing ones 2022-03-18 00:51:26 +01:00
Max Baumann
3f00f074de
fix: fix tests 2022-03-17 19:13:44 +01:00
Max Baumann
f49a2c3457
feat: add use_unwrap_or 2022-03-17 18:57:28 +01:00
bors
8d5c0eadde Auto merge of #8552 - Jarcho:ptr_arg_8495, r=xFrednet
Don't lint `ptr_arg` on `&mut Cow<_>`

fixes: #8495

changelog: Don't lint `ptr_arg` on `&mut Cow<_>`
2022-03-17 17:05:26 +00:00
Jason Newcomb
773d20341a Fix mixed enum variant kinds + code cleanup 2022-03-17 01:09:25 -04:00
Jason Newcomb
08a7157a37 Improve message for match_single_arms 2022-03-16 13:58:09 -04:00
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
8e5208cbff Don't lint transmute_undefined_repr when changing the type of generic params 2022-03-16 12:56:23 -04:00
Jason Newcomb
851e715e5a Don't lint ptr_arg on &mut Cow<_> 2022-03-16 12:00:27 -04:00
codehorseman
4beda1be70 resolve the conflict in compiler/rustc_session/src/parse.rs
Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-16 20:12:30 +08: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
dswij
6a3dbe4798 unnecessary_lazy_eval show suggestions on multiline lint 2022-03-15 23:59:26 +08: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
d1b087fdee Merge commit 'dc5423ad448877e33cca28db2f1445c9c4473c75' into clippyup 2022-03-14 12:02:53 +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
Tianyi Song
a944ccb677 Check if lhs < rhs in modulos and emit 2022-03-11 16:02:49 +08: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