Commit Graph

1656 Commits

Author SHA1 Message Date
blyxyas
b21a91ae3a Replace local variables signifying "done" or "loop break", use ControlFlow #12830 2024-07-24 01:40:58 +02:00
Jason Newcomb
e34c6dbae5 Refactor for using config values:
* Construct lint passes by taking `Conf` by reference.
* Use `HashSet` configs in less places
* Move some `check_crate` code into the pass constructor when possible.
2024-07-17 14:05:49 -04:00
apoisternex
489a77831c fix [excessive_precision] suggestions on float literal written in scientific notation
fixes: #12954

changelog: fix [`excessive_precision`] suggestions on float literal written in scientific notation
2024-07-15 18:52:18 -03:00
bors
eb4d88e690 Auto merge of #13102 - tesuji:fix-needless_option_as_deref, r=Alexendoo
Fix `needless_option_as_deref` false-positive on struct literals

changelog: [`needless_option_as_deref`] Fix false-positive on struct literals.

Fixes #13077 .

r?  Alexendoo
2024-07-15 16:23:41 +00:00
Lzu Tao
dcee2e8a0f Dont stop find loop node at struct field node 2024-07-15 15:56:17 +00:00
Philipp Krones
1ced73e66a
Merge remote-tracking branch 'upstream/master' into rustup 2024-07-11 15:29:08 +02:00
bors
e82cfdc559 Auto merge of #127476 - jieyouxu:rollup-16wyb0b, r=jieyouxu
Rollup of 10 pull requests

Successful merges:

 - #126841 ([`macro_metavar_expr_concat`] Add support for literals)
 - #126881 (Make `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` a deny-by-default lint in edition 2024)
 - #126921 (Give VaList its own home)
 - #127367 (Run alloc sync tests)
 - #127431 (Use field ident spans directly instead of the full field span in diagnostics on local fields)
 - #127437 (Uplift trait ref is knowable into `rustc_next_trait_solver`)
 - #127439 (Uplift elaboration into `rustc_type_ir`)
 - #127451 (Improve `run-make/output-type-permutations` code and improve `filename_not_in_denylist` API)
 - #127452 (Fix intrinsic const parameter counting with `effects`)
 - #127459 (rustdoc-json: add type/trait alias tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-08 06:47:12 +00:00
Maybe Waffle
791ff40337 Add support for mir::TerminatorKind::TailCall in clippy 2024-07-07 17:11:05 +02:00
Michael Goulet
7ce4a49911 iter_identity is a better name 2024-07-07 00:12:35 -04: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
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
Jason Newcomb
6d61bdabea Use is_in_test in more places. 2024-07-05 02:42:58 -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
bors
0f4035fde3 Auto merge of #12976 - tesuji:fix-explicit_auto_deref, r=xFrednet
Fix some false-positive cases of `explicit_auto_deref`

changelog: [`explicit_auto_deref`] Fix some false-positive cases

Fix part of #9841
Fix  #12969

r? xFrednet
2024-07-03 18:24:23 +00:00
Lzu Tao
c4c41d1352 Fix 12969 and fix 9841 2024-07-03 21:25:43 +07:00
Astra Tsai
0dd8b27b6b Fix formatting 2024-07-01 19:10:10 -07:00
Astra Tsai
567bea29b1 Fix into_iter_without_iter false positive when the implementation is not within the first impl block 2024-07-01 18:57:24 -07:00
bors
c4125286ce Auto merge of #12840 - tesuji:const-asserts, r=llogiq
Don't lint `assertions_on_constants` on any const assertions

close #12816
close #12847
cc #12817

----

changelog: Fix false positives in consts for `assertions_on_constants` and `unnecessary_operation`.
2024-07-01 22:06:06 +00:00
Matthias Krüger
fb95df70a7 Rollup merge of #127058 - compiler-errors:tighten-async-spans, r=oli-obk
Tighten `fn_decl_span` for async blocks

Tightens the span of `async {}` blocks in diagnostics, and subsequently async closures and async fns, by actually setting the `fn_decl_span` correctly. This is kinda a follow-up on #125078, but it fixes the problem in a more general way.

I think the diagnostics are significantly improved, since we no longer have a bunch of overlapping spans. I'll point out one caveat where I think the diagnostic may get a bit more confusing, but where I don't think it matters.

r? ````@estebank```` or ````@oli-obk```` or someone else on wg-diag or compiler i dont really care lol
2024-06-28 08:34:10 +02:00
Michael Goulet
39a215531c Tighten spans for async blocks 2024-06-27 15:19:08 -04:00
Philipp Krones
abdd057163 Merge commit '68a799aea9b65e2444fbecfe32217ce7d5a3604f' into clippy-subtree-update 2024-06-27 18:56:04 +02:00
Philipp Krones
e9e7a815a7
Merge remote-tracking branch 'upstream/master' into rustup 2024-06-27 18:49:59 +02:00
xFrednet
1b4c281fe7 RFC 2383: Stabilize lint_reasons in Clippy 🖇️ 2024-06-25 17:50:48 +02:00
Michael Goulet
a155c38989 Split out IntoIterator and non-Iterator constructors for AliasTy/AliasTerm/TraitRef/projection 2024-06-24 11:28:21 -04:00
bors
26c556dd63 Auto merge of #12965 - KisaragiEffective:resolve-invalid-paths-on-bool-then, r=blyxyas
resolve `clippy::invalid_paths` on `bool::then`

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

changelog: none
2024-06-22 22:47:21 +00:00
Jason Newcomb
4baae5d8b3 Add new Span utils to avoid both allocating and
compressing/decompressing spans.
2024-06-21 03:23:06 -04:00
Michael Goulet
f6661f5b9b StaticForeignItem and StaticItem are the same 2024-06-20 19:51:09 -04:00
vohoanglong0107
2f9f204123 feat: unnecessary_min_max lint 2024-06-20 13:57:16 +00:00
Kisaragi Marine
9749d990ed
resolve clippy::invalid_paths on bool::then 2024-06-20 11:45:45 +09:00
y21
ed9ccf66e9 [unnecessary_to_owned]: catch to_owned from byte slice to string 2024-06-20 00:09:31 +02:00
Trevor Gross
8cde354f0b Resolve Clippy f16 and f128 unimplemented!/FIXMEs
This removes the ICE codepaths for `f16` and `f128` in Clippy.
`rustc_apfloat` is used as a dependency for the parsing of these types,
since their `FromStr` implementation will not be available in the
standard library for a while.
2024-06-19 13:30:21 -04:00
bors
29cc5c691c Auto merge of #12942 - Jarcho:ex_proc_macro, r=Manishearth
Add more types to `is_from_proc_macro`

I've been running through going through all the lint implementations to clean them up. I'll be separating out the changes into small PRs to make reviewing easier.

changelog: none
2024-06-18 23:45:47 +00:00
Michael Goulet
7218fdd2db Fix other tools 2024-06-17 22:35:25 -04:00
bors
2ad53f4e38 Auto merge of #12943 - Jarcho:range_sym, r=llogiq
Use symbols when raising range expressions.

----

changelog: none
2024-06-17 12:15:18 +00:00
Jason Newcomb
f09650b347 Use symbols when raising range expressions. 2024-06-16 20:24:43 -04:00
Jason Newcomb
e18b310874 Add more types to is_from_proc_macro 2024-06-16 20:15:09 -04:00
Jason Newcomb
22710f33a8 Add lint manual_inspect 2024-06-16 18:33:43 -04:00
Jason Newcomb
a002f93e51 expr_use_ctxt changes:
* Delay the parsing of the use node
* Mark when the `SyntaxContext` changes rather than return `None`
* Return a default value if the HIR tree is broken rather than `None`
2024-06-16 18:00:21 -04:00
bors
0dc265ff82 Auto merge of #12756 - y21:assigning_clones_lifetimes, r=Alexendoo
Avoid emitting `assigning_clones` when cloned data borrows from the place to clone into

Fixes #12444
Fixes #12460
Fixes #12749
Fixes #12757
Fixes #12929

I think the documentation for the function should describe what- and how this is fixing the issues well.
It avoids emitting a warning when the data being cloned borrows from the place to clone into, which is information that we can get from `PossibleBorrowerMap`. Unfortunately, it is a tiny bit tedious to match on the MIR like that and I'm not sure if this is possibly relying a bit too much on the exact MIR lowering for assignments.

Things left to do:
- [x] Handle place projections (or verify that they work as expected)
- [x] Handle non-`Drop` types

changelog: [`assigning_clones`]: avoid warning when the suggestion would lead to a borrow-check error
2024-06-15 18:25:42 +00:00
Philipp Krones
3bff119f63 Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
Philipp Krones
614966b0c3
Bump Clippy version -> 0.1.81 2024-06-13 12:24:14 +02:00
Philipp Krones
cc63143bbf
Merge remote-tracking branch 'upstream/master' into rustup 2024-06-13 12:24:08 +02:00
bors
38d12a9bc0 Auto merge of #12681 - y21:issue12677, r=Jarcho
Let `qualify_min_const_fn` deal with drop terminators

Fixes #12677

The `method_accepts_droppable` check that was there seemed overly conservative.
> Returns true if any of the method parameters is a type that implements `Drop`.
> The method can't be made const then, because `drop` can't be const-evaluated.

Accepting parameters that implement `Drop` should still be fine as long as the parameter isn't actually dropped, as is the case in the linked issue where the droppable is moved into the return place. This more accurate analysis ("is there a `drop` terminator") is already done by `qualify_min_const_fn` [here](f5e250180c/clippy_utils/src/qualify_min_const_fn.rs (L298)), so I don't think this additional check is really necessary?

Fixing the other, second case in the linked issue was only slightly more involved, since `Vec::new()` is a function call that has the ability to panic, so there must be a `drop()` terminator for cleanup, however we should be able to freely ignore that. [Const checking ignores cleanup blocks](https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/transform/check_consts/check.rs#L382-L388), so we should, too?

r? `@Jarcho`

----

changelog: [`missing_const_for_fn`]: continue linting on fns with parameters implementing `Drop` if they're not actually dropped
2024-06-11 22:38:52 +00:00
AurelienFT
c86b19f1ef Add lint to check manual pattern char comparison and merge its code with single_char_pattern lint 2024-06-11 21:56:14 +02:00
Ralf Jung
8c1f953772 ScalarInt: size mismatches are a bug, do not delay the panic 2024-06-10 13:43:16 +02:00
Lzu Tao
b161dc659c add utils is_inside_always_const_context 2024-06-08 16:50:25 +07:00
bors
d553ebef57 Auto merge of #12851 - samueltardieu:issue12846, r=y21
Add required parentheses around method receiver

Fix #12846

changelog: [`needless_bool`]: Add missing parentheses around method receiver
2024-06-07 21:27:46 +00:00
y21
973f318514 qualify_min_const_fn: ignore cleanup bbs 2024-06-07 20:56:22 +02:00
bors
0f87a81882 Auto merge of #12822 - Alexendoo:for-each-expr, r=dswij
Make `for_each_expr` visit closures by default, rename the old version `for_each_expr_without_closures`

A lot of the time `for_each_expr` is picked when closures should be visited so I think it makes sense for this to be the default with the alternative available for when you don't need to visit them.

The first commit renames `for_each_expr` to `for_each_expr_without_closures` and `for_each_expr_with_closures` to `for_each_expr`

The second commit switches a few uses that I caught over to include closures to fix a few bugs

changelog: none
2024-06-07 09:42:37 +00:00
bors
0b441d5ac5 Auto merge of #12877 - y21:const_host_ice, r=dswij
Handle const effects inherited from parent correctly in `type_certainty`

This fixes a (debug) ICE in `type_certainty` that happened in the [k256 crate]. (I'm sure you can also specifically construct an edge test case that will run into type_certainty false positives visible outside of debug builds from this bug)

<details>
<summary>Minimal ICE repro</summary>

```rs
use std::ops::Add;
Add::add(1_i32, 1).add(i32::MIN);
```
</details>

The subtraction here overflowed:
436675b477/clippy_utils/src/ty/type_certainty/mod.rs (L209)

... when we have something like `Add::add` where `add` fn has 0 generic params but the `host_effect_index` is `Some(2)` (inherited from the parent generics, the const trait `Add`), and we end up executing `0 - 1`.

(Even if the own generics weren't empty and we didn't overflow, this would still be wrong because it would assume that a trait method with 1 generic parameter didn't have any generics).

So, *only* exclude the "host" generic parameter if it's actually bound by the own generics

changelog: none

[k256 crate]: https://github.com/RustCrypto/elliptic-curves/tree/master/k256
2024-06-07 09:33:48 +00:00