Commit graph

4345 commits

Author SHA1 Message Date
bors
849668ad71 Auto merge of #8690 - mucinoab:DoNot-rest_pat_in_fully_bound_structs-OnNonExhaustive, r=Manishearth
Do not trigger ``[`rest_pat_in_fully_bound_structs`]`` on `#[non_exhaustive]` structs

fixes #8029

Just adds an additional check to ensure that the`ty::VariantDef` is not marked as `#[non_exhaustive]`.

changelog: Do not apply ``[`rest_pat_in_fully_bound_structs`]`` on structs marked as non exhaustive.
2022-04-12 16:14:13 +00:00
bors
b3bd03afcd Auto merge of #8686 - Jarcho:undocumented_unsafe_blocks_8681, r=flip1995
Fix ICE in `undocumented_unsafe_blocks`

fixes #8681

changelog: Fix ICE in `undocumented_unsafe_blocks`
2022-04-12 07:17:57 +00:00
Bruno A. Muciño
739f273739 Do not apply rest_pat_in_fully_bound_structs on #[non_exhaustive] structs 2022-04-11 22:47:04 -05:00
bors
dbcd82885f Auto merge of #8624 - pitaj:is_digit_ascii_radix, r=xFrednet
New lint `is_digit_ascii_radix`

Closes #6399

changelog: Added [`is_digit_ascii_radix`]: recommend `is_ascii_digit()` or `is_ascii_hexdigit()` in place of `is_digit(10)` and `is_digit(16)`
2022-04-11 18:56:21 +00:00
bors
636ed84c81 Auto merge of #8687 - Alexendoo:cast-possible-truncation-overflow, r=xFrednet
Fix subtraction overflow in `cast_possible_truncation`

changelog: Fix false negative due to subtraction overflow in `cast_possible_truncation`

I *think* a false negative is the worst that can happen from this
2022-04-11 18:40:14 +00:00
Alex Macleod
4a21082da2 Fix subtraction overflow in cast_possible_truncation 2022-04-11 18:54:44 +01:00
Jason Newcomb
c82dd0f36e Fix ICE in undocumented_unsafe_blocks 2022-04-11 13:18:27 -04:00
bors
89ee6aa6e3 Auto merge of #8667 - Jarcho:proc_macro_check, r=flip1995
Don't lint various match lints when expanded by a proc-macro

fixes #4952

As always for proc-macro output this is a hack-job of a fix. It would be really nice if more proc-macro authors would set spans correctly.

changelog: Don't lint various lints on proc-macro output.
2022-04-11 16:41:51 +00:00
bors
131ff87a1e Auto merge of #8673 - Jarcho:same_functions_8139, r=Manishearth
Fix `same_functions_in_if_condition` FP

fixes #8139

changelog: Don't consider `Foo<{ SomeConstant }>` and `Foo<{ SomeOtherConstant }>` to be the same, even if the constants have the same value.
2022-04-11 15:36:55 +00:00
bors
18ab97d220 Auto merge of #8668 - Jarcho:iter_with_drain_8538, r=Manishearth
Don't lint `iter_with_drain` on references

fixes #8538
changelog: Don't lint `iter_with_drain` on references
2022-04-11 15:20:01 +00:00
bors
5c19ae96e7 Auto merge of #8660 - yoav-lavi:squashed-master, r=flip1995
`unnecessary_owned_empty_strings`

[`unnecessary_owned_empty_strings`]

Fixes https://github.com/rust-lang/rust-clippy/issues/8650

- \[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: Adds `unnecessary_owned_empty_strings`, a lint that detects passing owned empty strings to a function expecting `&str`
2022-04-11 11:12:33 +00:00
Yoav Lavi
10201370a1 unnecessary_owned_empty_string -> unnecessary_owned_empty_strings 2022-04-11 13:05:42 +02:00
Yoav Lavi
a4d1837f07 unnecessary_string_new 2022-04-11 12:35:44 +02:00
bors
85e91dc99e Auto merge of #8671 - andy-k:fix-typo, r=flip1995
fix typo

fix typo in #8630

changelog: none
2022-04-11 09:22:37 +00:00
bors
5344236715 Auto merge of #8631 - Alexendoo:splitn-overlap, r=xFrednet
Remove overlap between `manual_split_once` and `needless_splitn`

changelog: Remove overlap between [`manual_split_once`] and [`needless_splitn`]. Fixes some incorrect `rsplitn` suggestions for [`manual_split_once`]

Things that can trigger `needless_splitn` no longer trigger `manual_split_once`, e.g.

```rust
s.[r]splitn(2, '=').next();
s.[r]splitn(2, '=').nth(0);
s.[r]splitn(3, '=').next_tuple();
```

Fixes some suggestions:

```rust
let s = "should not match";

s.rsplitn(2, '.').nth(1);
// old -> Some("should not match")
Some(s.rsplit_once('.').map_or(s, |x| x.0));
// new -> None
s.rsplit_once('.').map(|x| x.0);

s.rsplitn(2, '.').nth(1)?;
// old -> "should not match"
s.rsplit_once('.').map_or(s, |x| x.0);
// new -> early returns
s.rsplit_once('.')?.0;
```
2022-04-10 17:45:19 +00:00
Alex Macleod
6fba89751b Remove overlap between manual_split_once and needless_splitn
Also fixes some incorrect suggestions for rsplitn
2022-04-10 17:05:07 +01:00
Jason Newcomb
719a040397 Compare inline constants by their bodies rather than value in SpanlessEq 2022-04-10 00:54:41 -04:00
Andy Kurnia
1450c989ae fix typo 2022-04-10 01:07:01 +08:00
kyoto7250
a9511482d6 fix comments in test for split_once
split_once was stabilized in 1.52
2022-04-09 20:34:43 +09:00
Jason Newcomb
744b0ff903 Don't lint iter_with_drain on references 2022-04-08 23:41:50 -04:00
bors
b029a86c6b Auto merge of #8648 - Jarcho:transmute_collection_7706, r=xFrednet
Fix `unsound_collection_transmute`

fixes #7706

changelog: Better check size and alignment requirements in `unsound_collection_transmute`
2022-04-08 21:43:26 +00:00
Jason Newcomb
63f6a79bf8 Don't lint various match lints when expanded by a proc-macro 2022-04-08 16:51:40 -04:00
bors
a63308be0a Auto merge of #8619 - pitaj:fix-6973, r=giraffate
ignore `&x | &y` in unnested_or_patterns

replacing it with `&(x | y)` is actually more characters

Fixes #6973

changelog: [`unnested_or_patterns`] ignore `&x | &y`, nesting would result in more characters
2022-04-08 00:37:56 +00:00
Peter Jaszkowiak
06cfeb90c1 New lint is_digit_ascii_radix 2022-04-07 14:14:30 -06:00
bors
abc59bb914 Auto merge of #8656 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2022-04-07 15:30:27 +00:00
flip1995
669fddab37
Merge remote-tracking branch 'upstream/master' into rustup 2022-04-07 15:44:37 +01:00
bors
574bf88e3e Auto merge of #8635 - pbor:unsigned-abs, r=giraffate
Add a lint to detect cast to unsigned for abs() and suggest unsigned_…

…abs()

changelog: Add a [`cast_abs_to_unsigned`] that checks for uses of `abs()` that are cast to the corresponding unsigned integer type and suggest to replace them with `unsigned_abs()`.
2022-04-07 13:17:28 +00:00
bors
650a0e52b8 Auto merge of #8646 - Alexendoo:option-as-deref-mut, r=giraffate
Fix `as_deref_mut` false positives in `needless_option_as_deref`

Also moves it into `methods/`

Fixes #7846
Fixes #8047

changelog: [`needless_option_as_deref`]: No longer lints for `as_deref_mut` on Options that cannot be moved

supersedes #8064
2022-04-07 13:00:15 +00:00
Alex Macleod
182b7c38d7 Fix as_deref_mut false positives in needless_option_as_deref
Also moves the lint to the methods directory
2022-04-07 12:39:21 +01:00
Paolo Borelli
b0edbca0e6 new lint cast_abs_to_unsigned
Add a lint to detect cast to unsigned for abs() and suggest
unsigned_abs() to avoid panic when called on MIN.
2022-04-07 11:28:14 +02:00
bors
0d66404941 Auto merge of #8630 - Jarcho:forget_non_drop, r=Manishearth
Add lints `drop_non_drop` and `forget_non_drop`

fixes #1897

changelog: Add lints `drop_non_drop` and `forget_non_drop`
2022-04-06 23:04:20 +00:00
bors
409a936f3b Auto merge of #8606 - InfRandomness:err()-expect()-lint, r=xFrednet
Add [`err_expect`] lint

[`expect_err`] lint

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

Fixes https://github.com/rust-lang/rust-clippy/issues/1435

changelog: Added a lint to detect usage of .err().expect()
2022-04-06 18:07:56 +00:00
InfRandomness
cebe575aad Add .err().expect() lint 2022-04-06 19:25:58 +02:00
bors
81e004aadb Auto merge of #8549 - J-ZhengLi:issue8542, r=llogiq
fix FP in lint `[needless_match]`

fixes: #8542
fixes: #8551
fixes: #8595
fixes: #8599

---

changelog: check for more complex custom type, and ignore type coercion in [`needless_match`]
2022-04-06 17:23:14 +00:00
Jason Newcomb
d5e887c6f0 Better check size and alignment requirements in unsound_collection_transmute 2022-04-06 11:57:55 -04:00
bors
cf1e2e9c1c Auto merge of #8612 - SabrinaJewson:suggest-from-utf8-unchecked-in-const, r=flip1995
Suggest from_utf8_unchecked in const contexts

Unfortunately I couldn't figure out how to check whether a given expression is in an `unsafe` context or not, so I just unconditionally emit the wrapping `unsafe {}` block in the suggestion. If there is an easy way to get it to work better then I would love to hear it.

changelog: Suggest `from_utf8_unchecked` instead of `from_utf8` in const contexts for ``[`transmute_bytes_to_str`]``

refs: #8379
2022-04-06 09:32:51 +00:00
bors
880ff2497d Auto merge of #8596 - Jaic1:unnecessary_cast, r=flip1995
Fix unnecessary_cast suggestion for type aliasses

Fix #6923. The [`unnecessary_cast`] lint now will skip casting to non-primitive type.

changelog: fix lint [`unnecessary_cast `]
2022-04-06 08:27:03 +00:00
bors
41f2eccf92 Auto merge of #8588 - pitaj:fix-8348, r=flip1995
`indexing_slicing` should not fire if a valid array index comes from a constant function that is evaluated at compile-time

fix #8348

changelog: [`indexing_slicing`] fewer false positives in `const` contexts and with `const` indices
2022-04-06 08:13:26 +00:00
Akshay
1582e7bf88
fix mispelling in diagnostic message of bytes_nth 2022-04-05 10:53:10 +01:00
Jason Newcomb
e4fc15e646 Don't lint cast_ptr_alignment when used for unaligned reads and writes 2022-04-04 13:54:52 -04:00
Jason Newcomb
5cd711b4f1 Add lints drop_non_drop and forget_non_drop 2022-04-04 12:30:09 -04:00
bors
190f0deac8 Auto merge of #8450 - Jarcho:unsafe_blocks_8449, r=giraffate
Rework `undocumented_unsafe_blocks`

fixes: #8264
fixes: #8449

One thing came up while working on this. Currently comments on the same line are supported like so:

```rust
/* SAFETY: reason */ unsafe {}
```

Is this worth supporting at all? Anything other than a couple of words doesn't really fit well.

edit: [zulip topic](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.60undocumented_unsafe_blocks.60.20same.20line.20comment)

changelog: Don't lint `undocumented_unsafe_blocks` when the unsafe block comes from a proc-macro.
changelog: Don't lint `undocumented_unsafe_blocks` when the preceding line has a safety comment and the unsafe block is a sub-expression.
2022-04-04 13:07:26 +00:00
bors
1cec8b30fa Auto merge of #8594 - FoseFx:unit_like_struct_brackets, r=giraffate
add `empty_structs_with_brackets`

<!-- 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. Also, it's helpful for us that
the lint name is put into brackets `[]` and backticks `` ` ` ``,
e.g. ``[`lint_name`]``.

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.

- \[ ] Followed [lint naming conventions][lint_naming]
- \[ ] Added passing UI tests (including committed `.stderr` file)
- \[ ] `cargo test` passes locally
- \[ ] Executed `cargo dev update_lints`
- \[ ] Added lint documentation
- \[ ] 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.

--

*Please write a short comment explaining your change (or "none" for internal only changes)*
-->
Closes #8591

I'm already sorry for the massive diff 😅

changelog: New lint [`empty_structs_with_brackets`]
2022-04-04 07:28:36 +00:00
Jason Newcomb
17c8bee95a Add a couple of examples to undocumented_unsafe_blocks 2022-04-02 00:46:45 -04:00
Peter Jaszkowiak
c70f1e0f8f ignore &x | &y in unnested_or_patterns
replacing it with `&(x | y)` is actually more characters
2022-04-01 22:36:30 -06:00
bors
f6b29923c6 Auto merge of #8616 - pitaj:single_element_loop_arrays, r=llogiq
single_element_loop: handle arrays for Edition2021

changelog: [`single_element_loop`] handle arrays in Edition 2021, handle `.iter_mut()` and `.into_iter()`, and wrap in parens if necessary
2022-04-01 18:45:49 +00:00
Peter Jaszkowiak
3bbb3e3329 single_element_loop: handle arrays for Edition2021
also handle `.iter_mut()`, `.into_iter()`,
and wrapping in parens if necessary
2022-04-01 00:04:19 -06:00
SabrinaJewson
11045f94e2
Don't unnecessarily suggest unsafe block 2022-04-01 06:32:22 +01:00
SabrinaJewson
7a80c23f83
Suggest from_utf8_unchecked in const contexts 2022-03-30 21:49:13 +01:00
bors
db5739ac55 Auto merge of #8610 - SabrinaJewson:transmute-int-to-char-const, r=xFrednet
Don't warn int-to-char transmutes in const contexts

changelog: Don't warn ``[`transmute_int_to_char`]`` in const contexts

fixes: #8379
2022-03-30 20:23:03 +00:00