Commit Graph

19582 Commits

Author SHA1 Message Date
Philipp Krones
23225e15d0
Consistent lint group table in book and README
The lint table and the restriction group description was improved in #10385,
but only in the README. Apply the same changes to the book.
2024-04-09 10:48:29 +02:00
bors
2202493a67 Auto merge of #12626 - folkertdev:incorrect-boolean-simplification, r=blyxyas
fix incorrect suggestion for `!(a as type >= b)`

fixes #12625

The expression  `!(a as type >= b)` got simplified to `a as type < b`, but because of rust's parsing rules that `<` is interpreted as a start of generic arguments for `type`.  This is fixed by recognizing this case and adding extra parens around the left-hand side of the comparison.

changelog: [`nonminimal_bool`]: fix incorrect suggestion for  `!(a as type >= b)`
2024-04-08 11:05:09 +00:00
bors
1c9e96536b Auto merge of #12610 - ARandomDev99:manual_unwrap_or_default-12564, r=dswij
[`manual_unwrap_or_default`]: Check for Default trait implementation in initial condition when linting and use `IfLetOrMatch`

Fixes #12564

changelog: Fix [`manual_unwrap_or_default`] false positive when initial `match`/`if let` condition doesn't implement `Default` but the return type does.
2024-04-08 07:24:17 +00:00
Folkert
6a2cb33029
fix incorrect suggestion for !(a as type >= b) 2024-04-07 19:17:49 +02:00
bors
367f7aac5a Auto merge of #12604 - xFrednet:00000-review-vacation, r=matthiaskrgr
Prevent PR assignments to `@matthiaskrgr`, `@giraffate`, and `@Centri3`

When commenting r? clippy, rustbot takes a random member from the team. I'm setting you kings and queen to be on vacation, so that rustbot doesn't target you.

---

changelog: none

cc: `@matthiaskrgr` `@giraffate` and `@Centri3`
2024-04-06 10:11:18 +00:00
xFrednet
2a34f231e9
Prevent PR assignments to @matthiaskrgr, @giraffate, and @Centri3 2024-04-06 12:08:55 +02:00
bors
eecff6d07b Auto merge of #12439 - Jacherr:issue-12185, r=blyxyas
fix ice reporting in lintcheck

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

This PR fixes the lack of reported ICEs within lintcheck by modifying the way in which data is collected from each crate being linted.

Instead of lintcheck only reading `stdout` for warnings, it now also reads `stderr` for any potential ICE (although admittedly, it is not the cleanest method of doing so). If it is detected, it parses the ICE into its message and backtrace separately, and then adds them to the list of outputs via clippy.

Once all outputs are collected, the formatter then proceeds to generate the file as normal.

Note that this PR also has a couple of side effects:
- When clippy fails to process a package, but said failure is not an ICE, the `stderr` will be sent to the console;
- Instead of `ClippyWarning` being the primary struct for everything reported, there is now `ClippyCheckOutput`, an enum which splits the outputs into warnings and ICEs.

changelog: none
2024-04-05 18:16:07 +00:00
Jacherr
42d09703b4 Add support for ICE reporting in lintcheck 2024-04-05 20:14:38 +02:00
bors
08dac852a5 Auto merge of #12631 - franciscoBSalgueiro:11738, r=blyxyas
Allow `cast` lints in macros

closes: #11738

Removed the `from_expansion` guard clause for cast lints, so that these warnings can be generated for internal macros.

changelog: allow `cast` lints in macros
2024-04-04 23:02:55 +00:00
bors
8253040b3f Auto merge of #12591 - y21:issue12585, r=Jarcho
type certainty: clear `DefId` when an expression's type changes to non-adt

Fixes #12585

The root cause of the ICE in the linked issue was in the expression `one.x`, in the array literal.

The type of `one` is the `One` struct: an adt with a DefId, so its certainty is `Certain(def_id_of_one)`. However, the field access `.x` can then change the type (to `i32` here) and that should update that `DefId` accordingly. It does do that correctly when `one.x` would be another adt with a DefId:

97ba291d5a/clippy_utils/src/ty/type_certainty/mod.rs (L90-L91)

but when it *isn't* an adt and there is no def id (which is the case in the linked issue: `one.x` is an i32), it keeps the `DefId` of `One`, even though that's the wrong type (which would then lead to a contradiction later when joining `Certainty`s):
97ba291d5a/clippy_utils/src/ty/type_certainty/mod.rs (L92-L93)

In particular, in the linked issue, `from_array([one.x, two.x])` would try to join the `Certainty` of the two array elements, which *should* have been `[Certain(None), Certain(None)]`, because `i32`s have no `DefId`, but instead it was `[Certain(One), Certain(Two)]`, because the DefId wasn't cleared from when it was visiting `one` and `two`. This is the "contradiction" that could be seen in the ICE message

... so this changes it to clear the `DefId` when it isn't an adt.

cc `@smoelius` you implemented this initially in #11135, does this change make sense to you?

changelog: none
2024-04-04 22:17:50 +00:00
bors
a73e751d19 Auto merge of #12609 - Alexendoo:arc-with-non-send-sync-message, r=Jarcho
Reword `arc_with_non_send_sync` note and help messages

Addresses https://github.com/rust-lang/rust-clippy/issues/12608#issuecomment-2029688054

Makes the note more concise and reframes the `Rc` suggestion around whether it crosses threads currently due to a manual `Send`/`Sync` impl or may do in the future

changelog: none
2024-04-04 21:59:21 +00:00
bors
9725c4a162 Auto merge of #12632 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2024-04-04 17:50:22 +00:00
Philipp Krones
bb023e90d8
Bump nightly version -> 2024-04-04 2024-04-04 19:48:53 +02:00
Philipp Krones
277303b210
Merge remote-tracking branch 'upstream/master' into rustup 2024-04-04 19:48:31 +02:00
bors
5a9e9b0e65 Auto merge of #12628 - franciscoBSalgueiro:fix-book-links, r=flip1995
Add missing links in the book

Added a few missing links marked with FIXME in the development book.

changelog: none
2024-04-04 11:39:45 +00:00
bors
398a52a8dc Auto merge of #12340 - not-elm:fix/issue-12334, r=llogiq
FIX(12334): manual_swap auto fix

Fixed: #12334

Initialization expressions are now generated as needed if the slice index is bound to a variable.

----

changelog: Fix [`manual_swap`]
2024-04-04 09:16:44 +00:00
Francisco Salgueiro
ac225a3b1f
Fix #11738: allow cast lints in macros
Removed the `from_expansion` guard clause for cast lints, so that these warnings can be generated for internal macros.
2024-04-03 21:43:06 +01:00
bors
e80ca2f381 Auto merge of #12615 - Kobzol:fix-recursive-clone-from, r=blyxyas
Do not suggest `assigning_clones` in `Clone` impl

This PR modifies `assigning_clones` to detect situations where the `clone` call is inside a `Clone` impl, and avoids suggesting the lint in such situations.

r? `@blyxyas`

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

changelog: Do not invoke `assigning_clones` inside `Clone` impl
2024-04-03 19:07:51 +00:00
Jakub Beránek
571118f4b0 Do not suggest assigning_clones in Clone impl 2024-04-03 20:55:34 +02:00
Francisco Salgueiro
b6486fae5c
add missing links in development guide 2024-04-03 17:07:12 +01:00
joboet
53e31dc45c rename expose_addr to expose_provenance 2024-04-03 16:00:38 +02:00
Jacob Pratt
e530b3d19c Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=Amanieu
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance

As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066).

The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".)

The new name nicely matches `ptr::without_provenance`.
2024-04-02 20:37:39 -04:00
Aneesh Kadiyala
ac18c24fe8 Use IfLetOrMatch to avoid repetition of code 2024-04-02 22:49:00 +05:30
bors
f9f854f428 Auto merge of #12617 - y21:issue-12616, r=Alexendoo
avoid an ICE in `ptr_as_ptr` when getting the def_id of a local

Fixes #12616

`Res::def_id` can panic, so avoid calling it in favor of `opt_def_id`, so we can gracefully handle resolutions that don't have a `DefId` (e.g. local variables) and get a false negative in the worst case, rather than an ICE

changelog: Fix ICE in [`ptr_as_ptr`] when the cast expression is a function call to a local variable
2024-04-02 13:40:00 +00:00
not-elm
0478d26c8b FIX(12334): manual_swap auto fix
Initialization expressions are now generated when index is bound to a variable.

FIX: Check to see if variables are used after swap

FIX:  rename StmtKind::Local to StmtKind::Let
2024-04-02 22:30:34 +09:00
y21
e575f05a8b avoid an ICE in ptr_as_ptr when getting the def_id of a local 2024-04-02 15:09:32 +02:00
bors
3b1b654f56 Auto merge of #12613 - y21:vacation, r=dswij
Pause review rotation for y21

Exams are coming up for me and I want to focus on that, so I'd like to pause PR assignments to me for a bit until that's over (will still continue to look at PRs that are assigned to me and might steal some PRs to review if I find the time). :)

--------------

changelog: none
2024-04-01 21:57:50 +00:00
bors
95c45be1ed Auto merge of #12603 - m-rph:12594, r=Manishearth
Elide unit variables linted by `let_unit` and use `()` directly instead

Situation: `let_unit` lints when an expression binds a unit (`()`) to a variable. In some cases this binding may be passed down to another function. Currently, the lint removes the binding without considering usage.

fixes: #12594

changelog: Suggestion Fix [`let_unit`]. Clippy will remove unit bindings and replace all their instances in the body with `()`.
2024-04-01 21:14:32 +00:00
y21
989f04d066 pause review rotation for y21 2024-04-01 22:35:54 +02:00
bors
2b30a5924e Auto merge of #11996 - J-ZhengLi:issue11992, r=xFrednet,ARandomDev99
fix suggestion for [`len_zero`] with macros

fixes: #11992

changelog: fix suggestion for [`len_zero`] with macros
2024-04-01 17:42:08 +00:00
J-ZhengLi
b456ed31e4 fix suggestion for [len_zero] with macros 2024-04-02 01:27:17 +08:00
bors
41e814a554 Auto merge of #12605 - xFrednet:00000-ignore-ice, r=y21
Ignore `rustc-ice-` files

When ui-test detects a crash, it writes it into a `rustc-ice-*` file. I find it a bit annoying that git always want's to add them. So this just adds these files to our `.gitignore` :D

---

changelog: none
2024-04-01 16:16:16 +00:00
xFrednet
24d20b4eae
Set RUSTC_ICE=0 in uitests and cargo dev lint 2024-04-01 17:05:55 +02:00
Aneesh Kadiyala
6a6a917fe4 Check for Default trait in initial expression 2024-04-01 20:18:03 +05:30
bors
c2681f2338 Auto merge of #12453 - y21:span_lint_into_diag, r=blyxyas
accept `String` in `span_lint*` functions directly to avoid unnecessary clones

context: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Accepting.20.60Into.3C.7BSub.7DdiagMessage.3E.60.20in.20.60span_lint*.60.20functions/near/425703273

tldr: the `span_lint*` functions now accept both `String`s, which are then reused and not recloned like before, and also `&'static str`, in which case it [doesn't need to allocate](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_error_messages/lib.rs.html#359).
Previously, it accepted `&str` and would always call `.to_string()`, which is worse in any case: it allocates for `&'static str` and forces a clone even if the caller already has a `String`.

---------

This PR has a massive diff, but the only interesting change is in the first commit, which changes the message/help/note parameter in the `span_lint*` functions to not take a `&str`, but an `impl Into<DiagMessage>`.

The second commit changes all of the errors that now occur:
- `&format!(...)` cannot be passed to `span_lint` anymore. Instead, we now simply pass `format!()` directly.
- `Into<DiagMessage>` can be `&'static str`, but not any `&str`. So this requires changing a bunch of other `&str` to `&'static str` at call sites as well.
- Added [`Sugg::into_string`](9fc88bc285/clippy_utils/src/sugg.rs (L362)), which, as opposed to `Sugg::to_string`, can take advantage of the fact that it takes ownership and is able to reuse the `String`

changelog: none
2024-04-01 14:10:40 +00:00
Alex Macleod
9d4a36841a Reword arc_with_non_send_sync note and help messages 2024-04-01 13:18:27 +00:00
y21
91f514cc83 fix fallout from previous commit 2024-04-01 15:04:45 +02:00
y21
bd4d456138 accept Into<{Sub}DiagMessage> in span_lint functions 2024-04-01 14:50:23 +02:00
Quinn Sinclair
eee4db928f Replace elided variable in let_unit with () when used
Situation: `let_unit` lints when an expression binds a unit (`()`)
to a variable. In some cases this binding may be passed down to
another function. Currently, the lint removes the binding without
considering usage.

Change: All usages of the elided variable are now replaced with `()`.

fixes: #12594
2024-04-01 13:40:36 +02:00
xFrednet
17a61b2610
Ignore rustc-ice- files 2024-04-01 12:03:16 +02:00
bors
cb87a574fd Auto merge of #12601 - Alexendoo:box-default-style, r=llogiq
Move `box_default` to style, do not suggest turbofishes

`Box::default()` [had its `#[rustc_box]` attribute removed](https://github.com/rust-lang/rust/pull/108476/files#r1120930164) in 1.69 so is no longer a perf related lint

The lint is moved to style but no longer produces suggestions containing turbofishes, as they're often longer/more annoying to type

changelog: [`box_default`]: Move to style

r? `@llogiq`
2024-04-01 07:57:26 +00:00
Alex Macleod
0f63fa8c33 Move box_default to style, do not suggest turbofishes
`Box::default()` had its `#[rustc_box]` attribute removed in 1.69 so is
no longer a perf related lint

The lint is moved to style but no longer produces suggestions containing
turbofishes, as they're often longer/more annoying to type
2024-03-31 16:46:44 +00:00
bors
797d50dfe6 Auto merge of #12562 - m-rph:12501, r=y21
Allow `filter_map_identity` when the closure is typed

This extends the `filter_map_identity` lint to support typed closures.

For untyped closures, we know that the program compiles, and therefore we can safely suggest using flatten.

For typed closures, they may participate in type resolution. In this case we use `Applicability::MaybeIncorrect`.

Details:
https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Should.20.60filter_map_identity.60.20lint.20when.20closures.20are.20typed.3F

changelog: `filter_map_identity` will now suggest using flatten for typed closures.

r? `@y21` && `@Centri3`
2024-03-31 12:16:01 +00:00
bors
3787a0ccb8 Auto merge of #11350 - y21:issue11349, r=xFrednet
[`type_id_on_box`]: lint on any `Box<dyn _>`

Closes #11349.

It now not only lints when calling `.type_id()` on the type `Box<dyn Any>`, but also on any `Box<dyn Trait>` where `Trait` is a subtrait of `Any`

changelog: FN: [`type_id_on_box`]: lint if `Any` is a sub trait
2024-03-30 21:26:36 +00:00
y21
f6c006364b split up tests into fixable and unfixable now and add annotations 2024-03-30 20:54:16 +01:00
y21
36e4c2083b lint on any Box<dyn _>, but provide a suggestion for subtypes of dyn Any 2024-03-30 20:52:53 +01:00
bors
cebf879de8 Auto merge of #12312 - pitaj:legacy_numeric_constants, r=xFrednet
new lint `legacy_numeric_constants`

Rework of #10997

- uses diagnostic items
- does not lint imports of the float modules (`use std::f32`)
- does not lint usage of float constants that look like `f32::MIN`

I chose to make the float changes because the following pattern is actually pretty useful
```rust
use std::f32;
let omega = freq * 2 * f32::consts::PI;
```
and the float modules are not TBD-deprecated like the integer modules.

Closes #10995

---

changelog: New lint [`legacy_numeric_constants`]
[#12312](https://github.com/rust-lang/rust-clippy/pull/12312)
2024-03-30 17:50:36 +00:00
bors
e0e7ee183f Auto merge of #12563 - J-ZhengLi:issue11513, r=Alexendoo
make sure checked type implements `Try` trait when linting [`question_mark`]

(indirectly) fixes: #12412 and fixes: #11983

---

changelog: make sure checked type implements `Try` trait when linting [`question_mark`]
2024-03-30 13:21:20 +00:00
bors
88d842ed29 Auto merge of #12579 - J-ZhengLi:issue12569, r=Alexendoo
fix [`manual_unwrap_or_default`] suggestion ignoring side-effects

fixes: #12569
closes: #12580

change applicability to `MaybeIncorrect` base on suggestion in [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.60manual_unwrap_or_default.60.20suggestion.20removes.20comments)

---

changelog: fix [`manual_unwrap_or_default`] suggestion ignoring side-effects, and adjust its applicability.
2024-03-30 12:32:38 +00:00
J-ZhengLi
5750e4670b fix [manual_unwrap_or_default] suggestion ignoring side-effects 2024-03-30 09:18:53 +08:00