Commit Graph

19316 Commits

Author SHA1 Message Date
Guillaume Gomez
98ac5f1e8c Rename into manual_unwrap_or_default 2024-03-10 01:23:28 +01:00
Guillaume Gomez
b0f358fd3c Update ui test 2024-03-10 01:23:28 +01:00
Guillaume Gomez
fadb254073 Add new ui test for match_option_and_default 2024-03-10 01:15:23 +01:00
Guillaume Gomez
1abf4418f8 Add new match_option_and_default lint 2024-03-10 01:15:22 +01:00
bors
7ee75f896f Auto merge of #12447 - MarcusGrass:mg/fix-12438-regression, r=y21
Fix #12438 std_instead_of_core regression

Fixes #12438.

Boy-scouting removed two paths that checks for duplication since I thought they were unused. However, that's just because I didn't spot it in the diff.

I installed [difftastic](https://github.com/Wilfred/difftastic) and ran it on the old one:

![image](https://github.com/rust-lang/rust-clippy/assets/34198073/5c51276c-055a-49a3-9425-6f7da0590fb0)

And the new one (fixed):

![image](https://github.com/rust-lang/rust-clippy/assets/34198073/6e10f29c-6d6b-4f64-893f-de526424f1cd)

New one (stderr):
![image](https://github.com/rust-lang/rust-clippy/assets/34198073/c4c07776-ee0f-47ba-996f-6b632de47c81)

Good teachings for the future when inspecting diffs with a lot of line changes, should've thought of that before, sorry for the trouble!

changelog: [`std_instead_of_core`] Fix false positive for crates that are in `std` but not `core`
2024-03-09 21:23:38 +00:00
bors
d8a9068e83 Auto merge of #12449 - Jacherr:issue-6439, r=llogiq
Add new lint `zero_repeat_side_effects`

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

Adds a new `suspicious` lint zero_repeat_side_effects. This lint warns the user when initializing an array or `Vec` using the `Repeat` syntax, i.e., `[x; y]`. If `x` is an `Expr::Call/MethodCall` or contains an `Expr::Call/MethodCall` and `y` is zero, then there is a chance that the internal call can produce side effects, such as printing to console, which is not very obvious.

This lint warns against this and instead suggests to separate out the function call and the array/Vec initialization.

changelog: Add new lint `zero_repeat_side_effects`
2024-03-09 20:15:02 +00:00
Jacherr
0c82fd01c7 fix example code 2024-03-09 19:04:35 +00:00
Jacherr
0e59259add add new lint zero_repeat_side_effects 2024-03-09 18:53:14 +00:00
MarcusGrass
b44ab66156
Fix #12438 false positive regression 2024-03-09 18:37:18 +01:00
bors
c173ea64b7 Auto merge of #12446 - y21:check_fn_span_lint, r=xFrednet
use `span_lint_hir` instead of `span_lint` in more lints

Decided to grep for `check_(fn|block)` and look where `span_lint` is used, since some lints lint will then emit a lint on a statement or expression in that function, which would use the wrong lint level attributes

The `LintContext` keeps track of the last entered HIR node that had any attributes, and uses those (and its parents) for figuring out the lint level when a lint is emitted

However, this only works when we actually emit a lint at the same node as the `check_*` function we are in.
If we're in `check_fn` and we emit a lint on a statement within that function, then there is no way to allow the lint only for that one statement (if `span_lint` is used). It would only count allow attributes on the function

changelog: [`needless_return`]: [`useless_let_if_seq`]: [`mut_mut`]: [`read_zero_byte_vec`]: [`unused_io_amount`]: [`unused_peekable`]: now respects `#[allow]` attributes on the affected statement instead of only on the enclosing block or function
2024-03-09 17:01:03 +00:00
y21
ced8bc5b8f use span_lint_hir instead of span_lint in more lints 2024-03-09 17:43:04 +01:00
bors
b2f9c4cbc7 Auto merge of #12442 - cookie-s:fix-mutmut-duplicate-diags, r=y21
[`mut_mut`]: Fix duplicate diags

Relates to #12379

The `mut_mut` lint produced two diagnostics for each `mut mut` pattern in `ty` inside  `block`s because `MutVisitor::visit_ty` was called from `MutMut::check_ty` and  `MutMut::check_block` independently. This PR fixes the issue.

---

changelog: [`mut_mut`]: Fix duplicate diagnostics
2024-03-09 13:13:28 +00:00
bors
099e2c0033 Auto merge of #12443 - cookie-s:noeffectreoplace-fix-dup-diags, r=Alexendoo
[`no_effect_replace`]: Fix duplicate diagnostics

Relates to #12379

Fixes `no_effect_replace` duplicate diagnostics

---

changelog: [`no_effect_replace`]: Fix duplicate diagnostics
2024-03-09 13:02:47 +00:00
bors
453242cbde Auto merge of #12310 - samueltardieu:issue-12307, r=xFrednet
New lint `const_is_empty`

This lint detects calls to `.is_empty()` on an entity initialized from a string literal and flag them as suspicious. To avoid triggering on macros called from generated code, it checks that the `.is_empty()` receiver, the call itself and the initialization come from the same context.

Fixes #12307

changelog: [`const_is_empty`]: new lint
2024-03-09 09:56:37 +00:00
kcz
7473f0522c
[no_effect_replace]: Fix duplicate diagnostics 2024-03-08 23:05:16 -05:00
kcz
4e95b4a026
[mut_mut]: Fix duplicate diags 2024-03-08 22:39:36 -05:00
bors
0b4b684b46 Auto merge of #12433 - J-ZhengLi:issue12197, r=dswij
fix [`missing_docs_in_private_items`] on some proc macros

fixes: #12197

---

changelog: [`missing_docs_in_private_items`] support manually search for docs as fallback method
2024-03-08 11:05:50 +00:00
J-ZhengLi
adc91e4913 support manually search for docs in case attr was removed by proc macros 2024-03-08 16:32:47 +08:00
J-ZhengLi
3a6cac7c06 add rewrite_struct proc-macro and test case 2024-03-08 09:32:38 +08:00
bors
93f0a9a91f Auto merge of #12431 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2024-03-07 16:16:36 +00:00
Philipp Krones
1d65642a1f
Bump nightly version -> 2024-03-07 2024-03-07 17:14:39 +01:00
Philipp Krones
a6df0277ea
Merge remote-tracking branch 'upstream/master' into rustup 2024-03-07 17:14:36 +01:00
bors
ba80e06537 Auto merge of #12429 - Alexendoo:redundant-field-names-macro-ctxt, r=Manishearth
Don't lint `redundant_field_names` across macro boundaries

Fixes #12426

The `field.span.eq_ctxt(field.ident.span)` addition is the relevant line for the bugfix

The current implementation checks that the field's name and the path are in the same context by comparing the idents, but not that the two are in the same context as the entire field itself, so in local macros `SomeStruct { $ident: $ident }` would get linted

changelog: none
2024-03-07 13:56:36 +00:00
Alex Macleod
ac643a278b Don't lint redundant_field_names across macro boundaries 2024-03-07 12:21:16 +00:00
bors
a79db2aa51 Auto merge of #12401 - MarcusGrass:dedup-nonminimal-bool, r=blyxyas
Remove double expr lint

Related to #12379.

Previously the code manually checked nested binop exprs in unary exprs, but those were caught anyway by `check_expr`. Removed that code path, the path is used in the tests.

---

changelog: [`nonminimal_bool`] Remove duplicate output on nested Binops in Unary exprs.
2024-03-06 13:32:53 +00:00
Jason Newcomb
0901b9fecf Convert TypeVisitor and DefIdVisitor to use VisitorResult 2024-03-05 13:28:15 -05:00
bors
e485a02ef2 Auto merge of #12077 - Kobzol:assigning-clones, r=blyxyas
Add `assigning_clones` lint

This PR is a "revival" of https://github.com/rust-lang/rust-clippy/pull/10613 (with `@kpreid's` permission).

I tried to resolve most of the unresolved things from the mentioned PR:
1) The lint now checks properly if we indeed call the functions `std::clone::Clone::clone` or `std::borrow::ToOwned::to_owned`.
2) It now supports both method and function (UFCS) calls.
3) A heuristic has been added to decide if the lint should apply. It will only apply if the type on which the method is called has a custom implementation of `clone_from/clone_into`. Notably, it will not trigger for types that use `#[derive(Clone)]`.
4) `Deref` handling has been (hopefully) a bit improved, but I'm not sure if it's ideal yet.

I also added a bunch of additional tests.

There are a few things that could be improved, but shouldn't be blockers:
1) When the right-hand side is a function call, it is transformed into e.g. `::std::clone::Clone::clone(...)`. It would be nice to either auto-import the `Clone` trait or use the original path and modify it (e.g. `clone::Clone::clone` -> `clone::Clone::clone_from`). I don't know how to modify the `QPath` to do that though.
2) The lint currently does not trigger when the left-hand side is a local variable without an initializer. This is overly conservative, since it could trigger when the variable has no initializer, but it has been already initialized at the moment of the function call, e.g.
```rust
let mut a;
...
a = Foo;
...
a = b.clone(); // Here the lint should trigger, but currently doesn't
```
These cases probably won't be super common, but it would be nice to make the lint more precise. I'm not sure how to do that though, I'd need access to some dataflow analytics or something like that.

changelog: new lint [`assigning_clones`]
2024-03-05 15:26:57 +00:00
bors
2d9d404448 Auto merge of #12413 - high-cloud:fix_assign_ops2, r=flip1995
[`misrefactored_assign_op`]: Fix duplicate diagnostics

Relate to #12379

The following diagnostics appear twice
```
  --> tests/ui/assign_ops2.rs:26:5
   |
LL |     a *= a * a;
   |     ^^^^^^^^^^
   |
help: did you mean `a = a * a` or `a = a * a * a`? Consider replacing it with
```

because `a` (lhs) appears in both left operand and right operand in the right hand side.
This PR fixes the issue so that if a diagnostic is created for an operand, the check of the other operand will be skipped. It's fine because the result is always the same in the affected operators.

changelog: [`misrefactored_assign_op`]: Fix duplicate diagnostics
2024-03-05 14:34:56 +00:00
bors
21efd39b04 Auto merge of #12423 - GuillaumeGomez:code-wrapped-element, r=Alexendoo
Don't emit "missing backticks" lint if the element is wrapped in `<code>` HTML tags

Fixes #9473.

changelog: Don't emit "missing backticks" lint if the element is wrapped in `<code>` HTML tags
2024-03-05 14:02:54 +00:00
Yaodong Yang
3c5008e8de [misrefactored_assign_op]: Fix duplicate diagnostics 2024-03-05 19:53:26 +08:00
Guillaume Gomez
bd9b9ffa04 Add regression test for #9473 2024-03-05 12:07:37 +01:00
Guillaume Gomez
ee375e48be Don't emit "missing backticks" lint if the element is wrapped in <code> HTML tags 2024-03-05 12:06:51 +01:00
bors
eb4a441c09 Auto merge of #12419 - smoelius:plural-acronyms, r=dswij
Handle plural acronyms in `doc_markdown`

Prevent `doc_markdown` from triggering on words like `OSes` and `UXes`.

changelog: handle plural acronyms in `doc_markdown`
2024-03-05 10:47:40 +00:00
bors
193456e0a5 Auto merge of #12288 - PartiallyTyped:trait-type-checking-documentation, r=flip1995
Add documentation on trait checking and type construction

Changes:

Added documentation on how to create types via `Ty` and how to check specific trait implementations.

changelog: none

r? `@blyxyas`
2024-03-05 09:38:45 +00:00
bors
ae710de635 Auto merge of #121780 - nnethercote:diag-renaming2, r=davidtwco
Diagnostic renaming 2

A sequel to #121489.

r? `@davidtwco`
2024-03-05 02:58:34 +00:00
Nicholas Nethercote
ec920ce096 Rename DiagnosticExt as DiagExt. 2024-03-05 12:14:49 +11:00
Nicholas Nethercote
dc37dddeb5 Rename DiagnosticMessage as DiagMessage. 2024-03-05 12:14:49 +11:00
bors
415b1f1fa7 Auto merge of #120675 - oli-obk:intrinsics3.0, r=pnkfelix
Add a scheme for moving away from `extern "rust-intrinsic"` entirely

All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic.

cc https://github.com/rust-lang/rust/issues/63585

follow-up to #120500

MCP at https://github.com/rust-lang/compiler-team/issues/720
2024-03-05 00:13:01 +00:00
Samuel Moelius
cc4c8db0fd Handle plural acronyms in doc_markdown 2024-03-04 22:00:24 +00:00
Nicholas Nethercote
b74b4b09d1 Rename all ParseSess variables/fields/lifetimes as psess.
Existing names for values of this type are `sess`, `parse_sess`,
`parse_session`, and `ps`. `sess` is particularly annoying because
that's also used for `Session` values, which are often co-located, and
it can be difficult to know which type a value named `sess` refers to.
(That annoyance is the main motivation for this change.) `psess` is nice
and short, which is good for a name used this much.

The commit also renames some `parse_sess_created` values as
`psess_created`.
2024-03-05 08:11:45 +11:00
bors
5214ab557f Auto merge of #12416 - Veykril:patch-2, r=blyxyas
Add missing header for `manual_is_variant_and`

Noticed this while generating our lint completions failed in rust-analyzer (separate PR from https://github.com/rust-lang/rust-clippy/pull/12415 as I made these via the github interface quickly)
changelog: none
2024-03-04 16:27:23 +00:00
bors
1cb39050bf Auto merge of #12415 - Veykril:patch-1, r=blyxyas
Add missing header for `manual_c_str_literals`

Noticed this while generating our lint completions failed in rust-analyzer
changelog: none
2024-03-04 16:16:46 +00:00
Oli Scherer
ea92548c56 Add is_intrinsic helper 2024-03-04 16:13:50 +00:00
Lukas Wirth
7322fa0235
Add missing header for manual_is_variant_and 2024-03-04 17:09:49 +01:00
Lukas Wirth
c5c14773fd
Add missing header for manual_c_str_literals 2024-03-04 17:07:31 +01:00
bors
c0939b18b8 Auto merge of #12409 - cookie-s:fix-identityop-duplicate-errors, r=Alexendoo
[`identity_op`]: Fix duplicate diagnostics

Relates to #12379

In the `identity_op` lint, the following diagnostic was emitted two times

```
  --> tests/ui/identity_op.rs:156:5
   |
LL |     1 * 1;
   |     ^^^^^ help: consider reducing it to: `1`
   |
```

because both of the left operand and the right operand are the identity element of the multiplication.

This PR fixes the issue so that if a diagnostic is created for an operand, the check of the other operand will be skipped. It's fine because the result is always the same in the affected operators.

---

changelog: [`identity_op`]: Fix duplicate diagnostics
2024-03-04 14:43:38 +00:00
bors
e970fa52e7 Auto merge of #12341 - y21:issue12337, r=dswij
Check for try blocks in `question_mark` more consistently

Fixes #12337

I split this PR up into two commits since this moves a method out of an `impl`, which makes for a pretty bad diff (the `&self` parameter is now unused, and there isn't a reason for that function to be part of the `impl` now).

The first commit is the actual relevant change and the 2nd commit just moves stuff (github's "hide whitespace" makes the diff easier to look at)

------------
Now for the actual issue:

`?` within `try {}` blocks desugars to a `break` to the block, rather than a `return`, so that changes behavior in those cases.

The lint has multiple patterns to look for and in *some* of them it already does correctly check whether we're in a try block, but this isn't done for all of its patterns.

We could add another `self.inside_try_block()` check to the function that looks for `let-else-return`, but I chose to actually just move those checks out and instead have them in `LintPass::check_{stmt,expr}`. This has the advantage that we can't (easily) accidentally forget to add that check in new patterns that might be added in the future.

(There's also a bit of a subtle interaction between two lints, where `question_mark`'s LintPass calls into `manual_let_else`, so I added a check to make sure we don't avoid linting for something that doesn't have anything to do with `?`)

changelog: [`question_mark`]: avoid linting on try blocks in more cases
2024-03-04 14:34:56 +00:00
bors
f75d8c7f1b Auto merge of #12393 - J-ZhengLi:issue9413, r=dswij
fix [`derive_partial_eq_without_eq`] FP on trait projection

fixes: #9413 #9319

---

changelog: fix [`derive_partial_eq_without_eq`] FP on trait projection

Well, this is awkward, it works but I don't understand why, why `clippy_utils::ty::implements_trait` couldn't detects the existance of `Eq` trait, even thought it's obviously present in the derive attribute.
2024-03-04 06:43:59 +00:00
kcz
3b9939e83b
[identity_op]: Fix duplicate errors 2024-03-03 19:25:51 -05:00
bors
c2dd413c79 Auto merge of #12403 - samueltardieu:issue-12402, r=blyxyas
Pointers cannot be converted to integers at compile time

Fix #12402

changelog: [`transmutes_expressible_as_ptr_casts`]: do not suggest invalid const casts
2024-03-03 23:09:54 +00:00