Commit graph

21223 commits

Author SHA1 Message Date
Jason Newcomb
19426bfdfb
doc_lazy_continuation: Correctly count indent with backslashes (#13742)
changelog: [`doc_lazy_continuation`]: correctly count indent with
backslashes

Fixes #13705
2024-12-03 15:53:46 +00:00
Michael Howell
d3a7fb140c doc_lazy_continuation: Correctly count indent with backslashes
changelog: [`doc_lazy_continuation`]: correctly count indent with backslashes
2024-12-02 19:05:36 -07:00
Alejandra González
646d72a01d
Correct report_elidable_impl_lifetimes comment following #13752 (#13771)
Tiny change to make `report_elidable_impl_lifetimes`'s doc comment
consistent with #13752. (cc: @samueltardieu)

---

changelog: none
2024-12-02 20:04:47 +00:00
Samuel Moelius
4a342df09b Correct report_elidable_impl_lifetimes comment following #13752 2024-12-02 14:26:31 -05:00
Jason Newcomb
66b15ad853
doc_nested_refdefs: new lint for suspicious list syntax (#13707)
https://github.com/rust-lang/rust/issues/133150

This is more likely to be intended as an intra-doc link than it is to be
intended as a refdef. If a refdef is intended, it does not need to be
nested within a list item.

```markdown
- [`LONG_INTRA_DOC_LINK`]: this
  looks like an intra-doc link,
  but is actually a refdef.
  The first line will seem to
  disappear when rendered as HTML.
```

> - [`LONG_INTRA_DOC_LINK`]: this
>   looks like an intra-doc link,
>   but is actually a refdef.
>   The first line will seem to
>   disappear when rendered as HTML.

changelog: [`doc_nested_refdefs`]: add suspicious lint for link def at
start of list items and block quotes
2024-12-02 18:51:02 +00:00
Manish Goregaokar
df46e4cf13
add targeted help messages to zombie_processes diagnostic (#13760)
Fixes #13748

Diagnostic for that issue with this change:
```
warning: spawned process is not `wait()`ed on in all code paths
   --> x.rs:167:19
    |
167 |     let mut cmd = cmd.unwrap();
    |                   ^^^^^^^^^^^^
    |
note: no `wait()` call exists on the code path to this early return
   --> x.rs:178:47
    |
178 |             std::io::ErrorKind::BrokenPipe => return Some(0),
    |                                               ^^^^^^^^^^^^^^
note: `wait()` call exists, but it is unreachable due to the early return
   --> x.rs:185:10
    |
185 |     Some(cmd.wait().unwrap().code().unwrap()) // <-- wait()!
    |          ^^^
    = help: consider calling `.wait()` in all code paths
    = note: not doing so might leave behind zombie processes
    = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning
```
Instead of saying "wait() is **never** called", it now says it's not
called by all code paths and points out the early return in particular.

changelog: none
2024-12-02 18:42:42 +00:00
Manish Goregaokar
74dd50c653
Fix lifetimes elision suggestion in where clauses (#13752)
Fix #13749

changelog: [`needless_lifetimes`]: do not suggest using `'_` in `where`
clauses
2024-12-02 18:42:13 +00:00
Alejandra González
2ddfc92ea2
Add more cases to the useless_conversion lint (#13756)
The new cases are the application of `Into::into` or `From::from`
through the following functions with no effect:
- `Option::map()`
- `Result::map()` and `Result::map_err()`
- `ControlFlow::map_break()` and `ControlFlow::map_err()`
- `Iterator::map()`

changelog: [`useless_conversion`]: detect useless calls to `Into::into`
and `From::from` application through `map*` methods
2024-12-02 15:41:25 +00:00
Jason Newcomb
0a07dc5d8c
typing_env_env_for_derived_eq -> typing_env_for_derived_eq (#13769)
I'm assuming the duplicated `env` was a typo. Apologies if I've made a
mistake. (cc: @lcnr)

---

changelog: none
2024-12-02 15:30:30 +00:00
Samuel Tardieu
ab5d55c996 Add more receivers to useless_conversion
- `ControlFlow::map_break()`
- `ControlFlow::map_continue()`
- `Iterator::map()`
2024-12-02 16:26:51 +01:00
Catherine Flores
278e316d67
Fix needless_match FP on if-lets (#13646)
Closes #13574

Make sure that `needless_match` doesn't simplify:

```
if let Some(_) = a() {
// ..
} else let Some(_) = b() {
// ..
}
```

to:

```
a()
```

changelog: [`needless_match`]: Fix false-positive on if lets
2024-12-02 02:51:48 +00:00
Samuel Moelius
92badb3d19 typing_env_env_for_derived_eq -> typing_env_for_derived_eq 2024-12-01 11:07:56 -05:00
Timo
0a1ba2ca07
Mention string_slice in indexing_slicing documentation (#13763)
Close #13703

changelog: none
2024-12-01 15:34:22 +00:00
Fridtjof Stoldt
1f966e98db
Add new literal_string_with_formatting_args lint (#13410)
Fixes #10195.

changelog: Added new [`literal_string_with_formatting_args`] `pedantic`
lint
[#13410](https://github.com/rust-lang/rust-clippy/pull/13410)
2024-12-01 11:46:18 +00:00
Samuel Tardieu
2b0e7bb4a7 Fix lifetimes elision suggestion in where clauses 2024-11-30 21:57:16 +01:00
Samuel Tardieu
9a692ec8cd Add more cases to the useless_conversion lint
The new cases are `x.map(f)` and `x.map_err(f)` when `f` is `Into::into`
or `From::from` with the same input and output types.
2024-11-30 21:57:16 +01:00
Samuel Tardieu
ce9c4f8dd1 Mention string_slice in indexing_slicing documentation 2024-11-30 21:57:16 +01:00
Jason Newcomb
650e0c8d3d
Fix shadow_unrelated's behaviour with closures (#13677)
Fixes https://github.com/rust-lang/rust-clippy/issues/10780

We correctly no longer give a warning when a closure is passed to a
method, where one of the arguments to that method uses the variable
which would be shadowed by an argument to that closure.
Uses is defined loosely as any expression used in the calling expression
mentions the shadowee binding (except for the closure itself):

```rust
#![deny(clippy::shadow_unrelated)]
let x = Some(1);
let y = x.map(|x| x + 1);
```
will now succeed.

See https://github.com/linebender/xilem/pull/745 - without this change,
all of the `expect(shadow_unrelated)` in the repository are met; with
it, none of them are.

changelog: [`shadow_unrelated`]: Don't treat closures arguments as
unrelated when the calling function uses them
2024-11-30 17:08:08 +00:00
y21
1329547367 add targetted help messages to zombie_processes diagnostic 2024-11-30 00:38:13 +00:00
Philipp Krones
af1f78af05
Update backport, release and sync documentation (#13700)
This updates the documentation after #13694. It is not based on that PR
chain and can be merged independently, but should be merged after that
PR.

This is partly pulled from #12762, but removing the Josh parts.

This includes instructions on how to publish `clippy_utils`.

Closes https://github.com/rust-lang/rust-clippy/issues/13556 (yes, this
is the final PR 🙂)

r? @blyxyas

changelog: `clippy_utils` is now published to crates.io
2024-11-29 09:27:21 +00:00
Philipp Krones
f5f2c51e70
Update backport, release and sync documentation 2024-11-29 10:16:46 +01:00
Philipp Krones
ff4a26d442
Rustup (#13746)
r? @ghost

changelog: none
2024-11-28 18:03:28 +00:00
Philipp Krones
5fb924f334
Bump Clippy version -> 0.1.85 2024-11-28 18:57:52 +01:00
Philipp Krones
3c9daca1d1
Bump nightly version -> 2024-11-28 2024-11-28 18:57:00 +01:00
Philipp Krones
b24360aa87
Merge remote-tracking branch 'upstream/master' into rustup 2024-11-28 18:56:49 +01:00
Fridtjof Stoldt
5dc5842573
Changelog for Clippy 1.83 🤖 (#13716)
This is in honor of `@bors` who is no longer used in this repo. I've
been saving this poem for a special PR, but it just seems fitting to use
it now:

Bors the bot,
Handsome and strong!
Will you go with me,
To prom?

---

### The cat of this release is Abu nominated by @jdonszelmann :

<img height=700
src="https://github.com/user-attachments/assets/414f24a1-8bbf-4fed-bcbc-acc5ca6a1353"
alt="The cats of this Clippy release" />

Cats for the next release can be nominated in the comments :D

---

changelog: none
2024-11-28 12:39:57 +00:00
Michael Howell
8dd45f18b3 doc_nested_refdefs: apply suggestions
Co-Authored-By: Jason Newcomb <jsnewcomb@pm.me>
2024-11-27 13:51:31 -07:00
Michael Howell
44feca7f3f doc_nested_refdefs: new lint for suspicious refdef syntax
This is more likely to be intended as an intra-doc link than it is
to be intended as a refdef. If a refdef is intended, it does not
need to be nested within a list item or quote.

```markdown
- [`LONG_INTRA_DOC_LINK`]: this
  looks like an intra-doc link,
  but is actually a refdef.
  The first line will seem to
  disappear when rendered as HTML.
```
2024-11-27 13:42:04 -07:00
Jason Newcomb
b4163f08c7
[bad_bit_mask] Fix FP on proc macros (#13736)
`clap-3.1.6` was not compiling on the rustc-perf benchmarks because of
this lint. Also, the user could not allow the lint on the macro itself
because it was checking Exprs, not whatever the input of `bitflags!` is.

```
error: &-masking with zero
   --> src/build/arg_settings.rs:197:1
    |
            (#[allow] here)
197 | / bitflags! {
198 | |     struct Flags: u32 {
199 | |         const REQUIRED         ...
200 | |         const MULTIPLE_OCC     ...
...   |
226 | |     }
227 | | }
    | |_^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
    = note: this error originates in the macro `__impl_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)
```

changelog:  [`bad_bit_mask`]: Fix FP on procedural macros
2024-11-27 20:31:29 +00:00
Timo
67657da671
Handle repetition of associated constant constraint as well (#13723)
changelog: [`trait_duplication_in_bounds`]: trigger on duplicate const
associated constraint as well

~~The first commit is part of #13722 which must be merged first.~~
2024-11-27 20:23:54 +00:00
Philipp Krones
9b0597d78a
Fix: Use multipart_suggestion for derivable_impls (#13717)
This should address #13099 for the `derivable_impls` test. As I've not
contributed to clippy before, I'd like to make sure i'm on the right
track before doing more :)

changelog: [`derivable_impls`]: Use multipart_suggestion to aggregate
feedback
2024-11-27 17:07:51 +00:00
Catherine Flores
8bc1a9e49a
unnecessary_map_or: fix version for lint addition (#13733)
Fix #13730

changelog: none
2024-11-26 17:46:12 +00:00
Michael Goulet
b73a71c6b4 Rollup merge of #133140 - dtolnay:precedence, r=fmease
Inline ExprPrecedence::order into Expr::precedence

The representation of expression precedence in rustc_ast has been an obstacle to further improvements in the pretty-printer (continuing from #119105 and #119427).

Previously the operation of *"does this expression have lower precedence than that one"* (relevant for parenthesis insertion in macro-generated syntax trees) consisted of 3 steps:

1. Convert `Expr` to `ExprPrecedence` using `.precedence()`
2. Convert `ExprPrecedence` to `i8` using `.order()`
3. Compare using `<`

As far as I can guess, the reason for the separation between `precedence()` and `order()` was so that both `rustc_ast::Expr` and `rustc_hir::Expr` could convert as straightforwardly as possible to the same `ExprPrecedence` enum, and then the more finicky logic performed by `order` could be present just once.

The mapping between `Expr` and `ExprPrecedence` was intended to be as straightforward as possible:

```rust
match self.kind {
    ExprKind::Closure(..) => ExprPrecedence::Closure,
    ...
}
```

although there were exceptions of both many-to-one, and one-to-many:

```rust
    ExprKind::Underscore => ExprPrecedence::Path,
    ExprKind::Path(..) => ExprPrecedence::Path,
    ...
    ExprKind::Match(_, _, MatchKind::Prefix) => ExprPrecedence::Match,
    ExprKind::Match(_, _, MatchKind::Postfix) => ExprPrecedence::PostfixMatch,
```

Where the nature of `ExprPrecedence` becomes problematic is when a single expression kind might be associated with multiple different precedence levels depending on context (outside the expression) and contents (inside the expression). For example consider what is the precedence of an ExprKind::Closure `$closure`. Well, on the left-hand side of a binary operator it would need parentheses in order to avoid the trailing binary operator being absorbed into the closure body: `($closure) + Rhs`, so the precedence is something lower than that of `+`. But on the right-hand side of a binary operator, a closure is just a straightforward prefix expression like a unary op, which is a relatively high precedence level, higher than binops but lower than method calls: `Lhs + $closure` is fine without parens but `($closure).method()` needs them. But as a third case, if the closure contains an explicit return type, then the precedence is an even higher level than that, never needing parenthesization even in a binop left-hand side or method call: `|| -> bool { false } + Rhs` or `|| -> bool { false }.method()`.

You can see that trying to capture all of this resolution about expressions into `ExprPrecedence` violates the intention of `ExprPrecedence` being a straightforward one-to-one correspondence from each AST and HIR `ExprKind` variant. It would be possible to attempt that by doing stuff like `ExprPrecedence::Closure(Side::Leading, ReturnType::No)`, but I don't foresee the original envisioned benefit of the `precedence()`/`order()` distinction being retained in this approach. Instead I want to move toward a model that Syn has been using successfully. In Syn, there is a Precedence enum but it differs from rustc in the following ways:

- There are [relatively few variants](https://github.com/dtolnay/syn/blob/2.0.87/src/precedence.rs#L11-L47) compared to rustc's `ExprPrecedence`. For example there is no distinction at the precedence level between returns and closures, or between loops and method calls.

- We distinguish between [leading](https://github.com/dtolnay/syn/blob/2.0.87/src/fixup.rs#L293) and [trailing](https://github.com/dtolnay/syn/blob/2.0.87/src/fixup.rs#L309) precedence, taking into account an expression's context such as what token follows it (for various syntactic bail-outs in Rust's grammar, like ambiguities around break-with-value) and how it relates to operators from the surrounding syntax tree.

- There are no hardcoded mysterious integer quantities like rustc's `PREC_CLOSURE = -40`. All precedence comparisons are performed via PartialOrd on a C-like enum.

This PR is just a first step in these changes. As you can tell from Syn, I definitely think there is value in having a dedicated type to represent precedence, instead of what `order()` is doing with `i8`. But that is a whole separate adventure because rustc_ast doesn't even agree consistently on `i8` being the type for precedence order; `AssocOp::precedence` instead uses `usize` and there are casts in both directions. It is likely that a type called `ExprPrecedence` will re-appear, but it will look substantially different from the one that existed before this PR.
2024-11-26 12:03:41 -05:00
blyxyas
17fb5adf58 [] Fix FP on proc macros 2024-11-26 17:36:12 +01:00
Samuel Tardieu
6dcac6e2bf unnecessary_map_or: fix version for lint addition 2024-11-26 11:12:07 +01:00
Samuel Tardieu
2bf03f19e2 Handle repetition of associated constant constraint as well 2024-11-25 23:24:51 +01:00
llogiq
d49501c818
Use a better description of an internal function (#13721)
Found while reading code: the comment was incorrect as it stops counting
as soon as two elements are different.

changelog: none
2024-11-25 20:25:27 +00:00
llogiq
3d881e1e59
Prevent ICE in case of a bound constraint on generic argument (#13722)
Fix #13706

changelog: [`trait_duplication_in_bounds`]: fix ICE on duplicate type or
constant bound
2024-11-25 20:24:39 +00:00
Fridtjof Stoldt
d070402440
Remove incorrect "default there is no limit" documentation from trivial_copy_size_limit (#13719)
Remove the documentation incorrectly saying there is no default,
followed by the default.

![image](https://github.com/user-attachments/assets/eab54c81-945d-4ce2-b9fb-5cc84f01e68c)

changelog: [`trivially_copy_pass_by_ref`]: Removed incorrect
documentation suggesting the default has no limit.
2024-11-25 10:28:44 +00:00
Frank King
945ccbd063 Refactor where predicates, and reserve for attributes support 2024-11-25 16:38:35 +08:00
Kampfkarren
671183a41f Bless 2024-11-24 23:16:27 -08:00
Alex Macleod
479e1fc7c0
Add note about caveat for cfg(doc) (#13724)
For example, we definitely wouldn't want to do this in libcore.

changelog: none
2024-11-24 19:05:22 +00:00
Michael Howell
418dfb2257
Add Known problems section 2024-11-24 11:23:14 -07:00
Matthias Krüger
728826fe00 Rollup merge of #133371 - RalfJung:is_trivially_const_drop, r=compiler-errors
remove is_trivially_const_drop

I'm not sure this still brings any perf benefits, so let's benchmark this.

r? `@compiler-errors`
2024-11-24 11:08:19 +01:00
Michael Howell
943c3bc3db
Add note about caveat for cfg(doc)
For example, we definitely wouldn't want to do this in libcore.
2024-11-23 17:10:08 -07:00
Samuel Tardieu
9fd8e99d91 Prevent ICE in case of a bound constraint on generic argument 2024-11-23 21:25:34 +01:00
Samuel Tardieu
80df2c4ced Use a better description of an internal function 2024-11-23 20:38:20 +01:00
lcnr
78fa111a48 no more Reveal :( 2024-11-23 13:52:54 +01:00
Ralf Jung
1931fb825b remove is_trivially_const_drop 2024-11-23 08:41:06 +01:00
Fridtjof Stoldt
45e1a3a6f4
Update CHANGELOG.md
Co-authored-by: Philipp Krones <hello@philkrones.com>
2024-11-22 20:47:47 +00:00