Commit Graph

20446 Commits

Author SHA1 Message Date
Jason Newcomb
f178316ae2 Refactor excessive_bools:
* Check HIR tree before checking for macros.
* Check item count before checking for bools.
2024-07-07 16:11:11 -04:00
Jason Newcomb
1b0230cf25 Refactor endian_bytes:
* Merge code paths.
* Check HIR tree before checking for macros.
2024-07-07 16:10:19 -04:00
bors
a4132817fb Auto merge of #13052 - xFrednet:00000-lintcheck-warn-all, r=Alexendoo
Lintcheck: Add `--warn-all` and make it the CI default

This PR adds a new `--warn-all` flag to lintcheck. This is intended for our CI, as it currently doesn't detect changes of `nursery` and `restriction` lints.

I only made it the default for the CI, as `restriction` lints tend to generate A LOT of lint triggers. Looking at you [`clippy::implicit_return`](https://rust-lang.github.io/rust-clippy/master/index.html#/clippy::implicit_return)

That's it. Should hopefully be easy to review.

Also, a bit thanks again to `@Alexendoo` for adding this to our CI ❤️

---

r? `@Alexendoo`

changelog: none
2024-07-07 18:30:39 +00:00
xFrednet
93e74a4187
Lintcheck: Update lintcheck documentation 2024-07-07 18:42:09 +02:00
Maybe Waffle
791ff40337 Add support for mir::TerminatorKind::TailCall in clippy 2024-07-07 17:11:05 +02:00
bors
09c07ed63f Auto merge of #13048 - Jarcho:disallowed_methods, r=blyxyas
Refactor `disallowed_methods` and narrow span

Using the span of the call site just produces noisy diagnostics for long calls. Especially multi-line calls.

changelog: none
2024-07-07 14:28:44 +00:00
Jason Newcomb
d2ff2b9850 Move panicking_overflow_checks into correctness and clean up docs. 2024-07-07 10:24:46 -04:00
Jason Newcomb
23d96f65e4 Rename overflow_check_conditional to panicking_overflow_checks. 2024-07-07 10:24:42 -04:00
Jason Newcomb
aa371c37c2 Rewrite overflow_check_conditional 2024-07-07 10:22:29 -04:00
Lzu Tao
c46c1f6da6 Fix 13018: self should be T
with `Option::unwrap_or(self, T) -> T`.
2024-07-07 20:41:55 +07:00
bors
f2c74e220b Auto merge of #12966 - Rudxain:patch-1, r=dswij
Clarify that `modulo_one` only applies to ints

changelog: [`modulo_one`]: (docs) Clarify that it only applies to integers

This might be nitpicky, but it's more technically correct.

It also helps if a user skims through the docs, because they may believe it also applies to `{float}`s. This doc edit minimizes that possibility
2024-07-07 10:21:47 +00:00
John Arundel
5a9e5e4acf resolve code review comments 2024-07-07 10:49:26 +01:00
John Arundel
f7050b0c78 resolve code review comments 2024-07-07 10:44:27 +01:00
Michael Goulet
7ce4a49911 iter_identity is a better name 2024-07-07 00:12:35 -04:00
Lzu Tao
e864519fbc Add test for manual_unwrap_or in issue 13018 2024-07-07 03:34:38 +00:00
Jason Newcomb
0a25df87ef Refactor double_parens:
* Merge control flow before emission
* Check the AST before the macro check
2024-07-06 22:13:45 -04:00
Jason Newcomb
65b9fae565 Refactor checked_conversions:
* Check HIR tree before checking macros, msrv and constness
* Remove redundant HIR tree matching
2024-07-06 21:47:57 -04:00
lukas
e0f32e09de Mark format! with must_use hint 2024-07-06 14:24:20 +02:00
bors
0c9016aa1e Auto merge of #13055 - Jarcho:auto_derive, r=Alexendoo
Only check for `automatically_derived` on impl blocks

This brings us in line with how rustc checks for the attribute. Also note that `unused_attributes` will trigger if it's placed anywhere else.

See:
9a21ac8e7e/compiler/rustc_passes/src/dead.rs (L400-L403)
9a21ac8e7e/compiler/rustc_passes/src/liveness.rs (L143-L148)

changelog: none
2024-07-06 12:01:28 +00:00
Jason Newcomb
d8fb164a7c Rename any_parent_is_automatically_derived to in_automatically_derived. Only check for the attribute on an impl block. 2024-07-06 00:24:48 -04:00
y21
ecbb2d7ba9 remove internal compiler_lint_functions lint 2024-07-06 00:51:58 +02:00
bors
3ed690f07a Auto merge of #12974 - alex-semenyuk:rename_thread_local_initializer_can_be_made_const, r=Alexendoo
Rename thread_local_initializer_can_be_made_const to missing_const_for_thread_local

Close #12934
As discussed at #12934 name `thread_local_initializer_can_be_made_const` sounds against convention for other lints which describe the issue/wrong code but not suggestion and it is quite long. The new name take example from existing lint `missing_const_for_fn`

changelog: `thread_local_initializer_can_be_made_const` : Rename to [`missing_const_for_thread_local`]
2024-07-05 17:50:06 +00:00
xFrednet
25bb612538
Lintcheck: Add --warn-all and make it the CI default 2024-07-05 16:42:20 +02:00
Alexey Semenyuk
6621e6cbfa Rename thread_local_initializer_can_be_made_const to missing_const_for_thread_local 2024-07-05 19:40:37 +05:00
bors
94a000b613 Auto merge of #11293 - mrnossiom:11234, r=Jarcho
feat: add cfg_not_test lint

<!--
- \[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`
- \[ ] Added lint documentation
- \[x] Run `cargo dev fmt`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
-->

Fixes #11234

changelog: new lint: [`cfg_not_test`]

I don't know whether to lint only the `attr` or also the item associated to it. I guess this would mean putting the check in another place than `check_attribute` but I can't find a way to get the associated item to the attribute.

Also, I'm not sure how to document this lint, I feel like my explications are bad.
2024-07-05 11:42:47 +00:00
bors
3ef366705b Auto merge of #13049 - Jarcho:is_in_test, r=Alexendoo
Remove `is_in_test_module_or_function`

Uses are replaced with `is_in_test` for consistency with other lints and to simplify the implementation of the lints. This means the module name is no longer checked, but that was a horrible hack from a time when late passes couldn't see `#[cfg(..)]` attributes.

changelog: none
2024-07-05 11:33:46 +00:00
Milo Moisson
dd37441a64
test: add cfg_not_test tests 2024-07-05 10:28:26 +02:00
Milo Moisson
2c09ac3d39
feat: add cfg_not_test lint 2024-07-05 10:28:26 +02:00
Jason Newcomb
9f59e9a777 from_str_radix_10 : Reorder checks 2024-07-05 03:13:04 -04:00
Jason Newcomb
3fcac2cba8 from_over_into: Check HIR tree first. 2024-07-05 03:12:49 -04:00
Jason Newcomb
278e8371e6 float_literal: Check HIR tree before checking types. 2024-07-05 03:12:32 -04:00
Jason Newcomb
ca7e5c1353 exit: Use OwnerNode. 2024-07-05 03:12:19 -04:00
Jason Newcomb
5368895077 exhaustive_items: Don't check the item kind twice. 2024-07-05 03:11:32 -04:00
Jason Newcomb
5b0dac6fe2 error_impl_error: Get Error DefId after checking the HIR tree. 2024-07-05 03:10:37 -04:00
Jason Newcomb
672b8b512a Refactor empty_enums: Check the HIR tree before the feature check. 2024-07-05 03:10:07 -04:00
Jason Newcomb
d1dcd918e7 equatable_if_let: Check HIR tree before checking for macros. 2024-07-05 03:09:14 -04:00
Jason Newcomb
441500b55b Refactor else_if_without_else: Check the AST before the macro check. 2024-07-05 03:07:32 -04:00
Jason Newcomb
d15ec0ff85 Refactor crate_in_macro_def:
* Don't clone the token stream
* Check the HIR tree before reading attributes
2024-07-05 03:03:56 -04:00
Jason Newcomb
1f530ab7e2 Refactor collection_is_never_read: Check HIR tree before checking types. 2024-07-05 03:03:40 -04:00
Jason Newcomb
39cd58ee75 Refactor collapsible_if: Check AST before checking for macros 2024-07-05 03:03:29 -04:00
Jason Newcomb
01f53c2c16 Refactor borrow_deref_ref: Match HIR tree before checking for macros. 2024-07-05 03:03:01 -04:00
Jason Newcomb
dd9e8c835a Refactor arc_with_non_send_sync
* Check HIR beffore type checking
* Only lint when `Arc::new` is called
2024-07-05 03:02:00 -04:00
bors
e7f2952f7e Auto merge of #13047 - Jarcho:script, r=y21
Refactor `disallowed_script_idents`

Minor change to use `find_map` instead of a loop. Not important, but it's easier to read.

changelog: none
2024-07-05 06:47:49 +00:00
Jason Newcomb
6d61bdabea Use is_in_test in more places. 2024-07-05 02:42:58 -04:00
Jason Newcomb
60af2585f7 Refactor disallowed_methods:
* Simplify `def_id` extraction.
* Use the span of the method name instead of the call.
2024-07-05 02:37:09 -04:00
Jason Newcomb
4c44b4e3c8 Remove is_test_module_or_function and use is_in_test instead. 2024-07-05 02:17:24 -04:00
Jason Newcomb
ac939ad3a1 Refactor disallowed_script_idents: Simplify script checking loop. 2024-07-05 02:04:43 -04:00
bors
885f97e2ce Auto merge of #11656 - y21:unnecessary_string_from_utf8, r=Jarcho
[`unnecessary_to_owned`]: catch `to_owned` on byte slice to create temporary `&str`

Closes #11648

Detects the pattern `&String::from_utf8(bytes.to_vec()).unwrap()` and suggests `core::str::from_utf8(bytes).unwrap()`, which avoids the unnecessary intermediate allocation.

I decided to put this in the existing `unnecessary_to_owned` lint (rather than creating a new lint) for a few reasons:
- we get to use some of its logic (for example, recognizing any of the functions in the `to_owned` family, e.g. `to_vec`)
- the actual inefficient operation that can be avoided here is the call to `.to_vec()`, so this is in a way similar to the other cases caught by `unnecessary_to_owned`, just through a bunch of type conversions
- we can make this more "generic" later and catch other cases, so imo it's best not to tie this lint specifically to the `String` type

changelog: [`unnecessary_to_owned`]: catch `&String::from_utf8(bytes.to_vec()).unwrap()` and suggest `core::str::from_utf8(bytes).unwrap()`
2024-07-05 02:04:06 +00:00
Jason Newcomb
9d8a17794f Refactor bool_to_int_with_if:
* Check hir structure before macro checks
* Simplify constant checking
2024-07-04 21:52:46 -04:00
Jason Newcomb
d9ab0a70f6 Refactor assigning_clones:
* Merge some code paths
* Use `find` instead of a loop
* Move macro check to after hir pattern matching
2024-07-04 21:51:27 -04:00