Commit graph

5527 commits

Author SHA1 Message Date
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
Jason Newcomb
ddd3af2273 Only lint mut_from_ref when unsafe code is used 2022-04-06 10:59:57 -04:00
Jason Newcomb
6e20a634e7 Don't lint manual_non_exhaustive when the enum variant is used 2022-04-06 10:12:30 -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
bors
938b9fd720 Auto merge of #8403 - nerdypepper:fix/diagnostic-message-mispelling, r=flip1995,Manishearth
fix misspelling in diagnostic message of `bytes_nth`

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: fix misspelling in diagnostic message in ``[`bytes_nth`]``
2022-04-05 10:07:13 +00:00
Akshay
1582e7bf88
fix mispelling in diagnostic message of bytes_nth 2022-04-05 10:53:10 +01:00
bors
511752fd9d Auto merge of #8620 - Alexendoo:test-fmt-first, r=flip1995
Run fmt test before compile-test/dogfood

I seem to always forget to run `cargo dev fmt` before doing a test. This lets it fail fast rather than going through the much longer compile-test/dogfood tests first

changelog: none
2022-04-05 09:50:53 +00: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
Alex Macleod
515b4eceff Run fmt test before compile-test/dogfood 2022-04-02 12:34:06 +01:00
bors
85b88be2a4 Auto merge of #8605 - Jarcho:remove-deps, r=xFrednet
Remove deps

This remove both `regex` and `cargo_metadata` as dependencies making `clippy_dev` compile ~3x faster (~46s -> ~16s locally). `cargo_metadata` was used to extract the `version` field from `Cargo.toml`, which is done trivially without that. `regex` was used to parse `define_clippy_lint` in `update_lints` which is now done using `rustc_lexer`. This isn't any simpler, but it compiles ~15s faster and runs ~3x faster (~2.1s -> ~0.7s locally).

The next biggest offenders to compile times are `clap` and `winapi` on windows. `clap` could be removed, but re-implementing enough is probably more work than it's worth. `winapi` is used by `opener` and `walkdir` so it's stuck there.

changelog: none
2022-04-02 10:42:12 +00:00
bors
baaddf2b84 Auto merge of #8611 - Alexendoo:module-files-relative-paths, r=llogiq
Handle relative paths in module_files lints

The problem being that when clippy is run in the project's directory `lp` would be a relative path, this wasn't caught by the tests as there `lp` is an absolute path. Being a relative path it did not start with `trim_src_path` and so was ignored

Also allowed the removal of some `.to_os_string`/`.to_owned`s

changelog: Fixes [`self_named_module_files`] and [`mod_module_files`] not linting

Fixes #8123, cc `@DevinR528`
2022-04-02 07:06:03 +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
Jason Newcomb
ae5af0cd1a Remove cargo_metadata dependency from clippy 2022-04-01 23:18:47 -04: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
Max Baumann
e552267db3 style -> pedantic 2022-03-30 20:13:16 +02:00
Max Baumann
2953cba116 unit_like_struct_brackets -> empty_structs_with_brackets 2022-03-30 20:13:16 +02:00
Max Baumann
37d5a6264c changes after review 2022-03-30 20:12:58 +02:00
Max Baumann
33383a418d use span_suggestion_hidden 2022-03-30 20:12:58 +02:00
Max Baumann
7192297c28 additional checks for conditionally compiled code 2022-03-30 20:12:58 +02:00
Max Baumann
315521afc6 fix uitests 2022-03-30 20:12:58 +02:00
Max Baumann
9be3945be7 fix existing clippy tests 2022-03-30 20:12:58 +02:00
Max Baumann
528ada958b add unit_like_struct_brackets 2022-03-30 20:12:58 +02:00
SabrinaJewson
d6f05c6a89
Don't warn int-to-char transmutes in const contexts 2022-03-30 18:47:50 +01:00
Alex Macleod
10a6d872d4 Handle relative paths in module_files lints 2022-03-30 18:44:04 +01:00
bors
c0a5693abc Auto merge of #8602 - giraffate:fix_ice_for_iter_overeager_cloned, r=llogiq
Fix ICE for `iter_overeager_cloned`

Fix https://github.com/rust-lang/rust-clippy/issues/8527

changelog: Fix ICE for [`iter_overeager_cloned`]
2022-03-30 17:12:24 +00:00
bors
fe7254ff6f Auto merge of #8576 - smoelius:crate_in_macro_def, r=llogiq
Add `crate_in_macro_def` lint

This PR adds a lint to check for `crate` as opposed to `$crate` used in a macro definition.

I think this can close #4798. That issue focused on the case where the macro author "imports something into said macro."

But I think use of `crate` is likely to be a bug whether it appears in a `use` statement or not. There could be some use case I am failing to see, though. (cc: `@nilscript` `@flip1995)`

changelog: `crate_in_macro_def`
2022-03-30 16:57:24 +00:00
Samuel E. Moelius III
aaf04dc043 Fix error message in crate_in_macro_def.stderr 2022-03-30 12:52:31 -04:00
bors
0031f69999 Auto merge of #8592 - c410-f3r:stuff, r=flip1995
Do not fire `panic` in a constant environment

Let rustc handle panics in constant environments.

Since https://github.com/rust-lang/rust-clippy/issues/8348 I thought that such modification would require a lot of work but thanks to https://github.com/rust-lang/rust-clippy/pull/8588 I now know that it is not the case.

changelog: [`panic`]: No longer lint in constant context. `rustc` already handles this.
2022-03-30 16:04:14 +00:00
bors
d9819c3b8d Auto merge of #8584 - Alexendoo:map-unit-fn-context, r=Manishearth
Provide suggestion context in map_unit_fn

Fixes #8569

changelog: Fix incorrect suggestion for `option_map_unit_fn` , `result_map_unit_fn`
2022-03-30 15:25:37 +00:00
lcnr
104ba478f2 clippy: nameres for primitive type impls 2022-03-30 11:57:53 +02:00
lcnr
148b593954 get clippy to compile again 2022-03-30 11:23:58 +02:00
Takayuki Nakata
c22b7b8814 Fix ICE for iter_overeager_cloned 2022-03-29 21:51:37 +09:00
J-ZhengLi
448a26d696 improve parent expr check 2022-03-29 15:23:19 +08:00
Samuel E. Moelius III
cb307bbfcd Address review comments 2022-03-28 04:48:12 -04:00
Jaic1
ec851b870b First submit 2022-03-28 12:09:01 +08: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
bors
a7da8a6019 Auto merge of #95274 - jendrikw:slice-must-use, r=Dylan-DPC
add #[must_use] to functions of slice and its iterators.

Continuation of #92853.

Tracking issue: #89692.
2022-03-26 20:17:04 +00:00
Caio
af8ed04e09 Rustfmt 2022-03-26 15:48:17 -03:00
Caio
c687f6575f Do not fire panic in a constant environment 2022-03-26 15:39:21 -03:00
Jendrik
41f1413085 add #[must_use] to functions of slice and its iterators. 2022-03-26 16:19:47 +01:00
Jendrik
96f4e1c630 add #[must_use] to functions of slice and its iterators. 2022-03-26 15:37:48 +01:00
Peter Jaszkowiak
21eae8ceb6 fix indexing_slicing with const
- should not fire if indexing with a constant block
- should not fire if indexing within a constant context
(const statement or const block)
2022-03-25 23:05:38 -06:00
Alex Macleod
610db04222 Provide suggestion context in map_unit_fn 2022-03-25 20:47:54 +00:00
bors
b7b0dad656 Auto merge of #95273 - flip1995:clippyup, r=manishearth
Update Clippy

r? `@Manishearth`
2022-03-24 22:52:34 +00:00
flip1995
1fa3d66e62 Merge commit 'd0cf3481a84e3aa68c2f185c460e282af36ebc42' into clippyup 2022-03-24 14:50:04 +01: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
Oli Scherer
6fc3850847 update clippy stderr file 2022-03-24 11:27:07 +00:00
Samuel E. Moelius III
65a26692fd Add crate_in_macro_def lint 2022-03-24 05:08:10 -04: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
J-ZhengLi
4b128624ed fix #8551, add test cases, and some code improvement 2022-03-17 23:06:31 +08: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
J-ZhengLi
2909b33a24 quick fix of issue#8542 for lint [needless_match]
remove `ref`/`ref mut` check
2022-03-16 16:26:56 +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
Jason Newcomb
30b333645d Don't lint undocumented_unsafe_blocks on bad proc-macro spans. 2022-03-15 16:52:28 -04:00
Jason Newcomb
65f96e2b53 Rework undocumented_unsafe_blocks 2022-03-15 14:18:05 -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