1
Fork 0
Commit graph

21189 commits

Author SHA1 Message Date
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
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
boyned//Kampfkarren
f0bb475f80
Remove incorrect "no default" text from trivial_copy_size_limit 2024-11-22 10:16:46 -08:00
Scott Gerring
9f7fb41272 fix: multipart suggestions for derivable_impls 2024-11-22 14:17:45 +01:00
xFrednet
70d53bb364
Changelog for Clippy 1.83 🤖 2024-11-22 11:09:50 +00:00
Alejandra González
8298da72e7
Add new lint doc_include_without_cfg (#13625)
It's becoming more and more common to see people including markdown
files in their code using `doc = include_str!("...")`, which is great.
However, often there is no condition on this include, which is not great
because it slows down compilation and might trigger recompilation if
these files are updated.

This lint aims at fixing this situation.

changelog: Add new lint `doc_include_without_cfg`
2024-11-21 21:48:57 +00:00
Guillaume Gomez
404e47aa84 Add new lint doc_include_without_cfg 2024-11-21 22:43:55 +01:00
xFrednet
78d0a2aaac
Update version attributes for 1.83 lints 2024-11-21 13:50:31 +00:00
Ding Xiang Fei
ff6c4b731b reduce false positives of tail-expr-drop-order from consumed values
take 2

open up coroutines

tweak the wordings

the lint works up until 2021

We were missing one case, for ADTs, which was
causing `Result` to yield incorrect results.

only include field spans with significant types

deduplicate and eliminate field spans

switch to emit spans to impl Drops

Co-authored-by: Niko Matsakis <nikomat@amazon.com>

collect drops instead of taking liveness diff

apply some suggestions and add explantory notes

small fix on the cache

let the query recurse through coroutine

new suggestion format with extracted variable name

fine-tune the drop span and messages

bugfix on runtime borrows

tweak message wording

filter out ecosystem types earlier

apply suggestions

clippy

check lint level at session level

further restrict applicability of the lint

translate bid into nop for stable mir

detect cycle in type structure
2024-11-20 20:53:11 +08:00
Alejandra González
a19d69d273
Sync and Release automation (#13694)
Based on https://github.com/rust-lang/rust-clippy/pull/13693

Adds 2 subcommands to `cargo dev`:

- `cargo dev sync update_nightly`: Which updates the nightly versions in
`rust-toolchain` and `clippy_utils/README.md`
- `cargo dev release bump_version`: Bumps the version in all relevant
`Cargo.toml` files

Those are pulled out of
https://github.com/rust-lang/rust-clippy/pull/12759, which I'll rebase
on this.

Next step is to update the documentation, which I'll partly pull out of
https://github.com/rust-lang/rust-clippy/pull/12762

r? @blyxyas (as you reviewed the first PR in the chain and were assigned
to the second one)

cc https://github.com/rust-lang/rust-clippy/issues/13556

changelog: none
2024-11-19 22:43:56 +00:00
Timo
cfd17d4fe1
Use a better message for unnecessary_map_or lint (#13708)
Suggested by, and closes #13704.

changelog: [`unnecessary_map_or`]: use a clearer lint message
2024-11-19 22:15:25 +00:00
Samuel Tardieu
425346a1bc Use a better message for unnecessary_map_or lint
Suggested by @smoelius.
2024-11-19 21:44:29 +01:00
lcnr
c783d1e387 InterpCx store TypingEnv instead of a ParamEnv 2024-11-19 21:36:23 +01:00
lcnr
d8e5f7ad8a remove TypingMode::from_param_env in clippy 2024-11-19 19:31:02 +01:00
lcnr
809b420e16 move fn is_item_raw to TypingEnv 2024-11-19 18:06:20 +01:00
Philipp Krones
93d5ccdba7
Add cargo dev release subcommand
Currently this only provides the feature to auto-update the versions in the
`Cargo.toml` files. With the move to Josh, a command to get beta and stable
release commits will be added.
2024-11-19 17:59:33 +01:00
Philipp Krones
66715532ab
Add cargo dev sync subcommand
Currently this only provides the feature to auto-update the nightly version in
the `rust-toolchain` file and the `clippy_utils/README.md` file. The actual sync
to and from the Rust repo will be added with the move to Josh.
2024-11-19 17:59:33 +01:00
Alex Macleod
10677c3a19
Don't consider lifetimes in bounded types unused (fix extra_unused_lifetimes FP) (#13583)
Fixes #13578

r? @Alexendoo

changelog: don't consider lifetimes in bounded types unused (fix
`extra_unused_lifetimes` FP #13578)
2024-11-19 15:58:25 +00:00
Samuel Moelius
eaec0cab7e Fix 13578 (#13583)
changelog: don't consider lifetimes in bounded types unused (fix `extra_unused_lifetimes` FP #13578)
2024-11-18 20:20:19 -05:00
Manish Goregaokar
53994bda92
Remove extern vectorcall tests (#13702)
On arm64 I get

```
error[E0570]: `"vectorcall"` is not a supported ABI for the current target
```

We don't seem to be doing any ABI specific handling so it seems fine to
just remove this one since there are other tests

changelog: none
2024-11-18 19:00:14 +00:00
Manish Goregaokar
7a1e9f28ad
missing_safety_doc accept uppercase "SAFETY" (#13701)
changelog: [`missing_safety_doc`]: accept uppercase "SAFETY"

In [Oxc](https://github.com/oxc-project/oxc)'s codebase, we try to draw
attention as clearly as possible to the safety constraints of unsafe
code by including an uppercase `# SAFETY` doc comment.

Clippy's `missing_safety_doc` lint does not recognise "SAFETY" in upper
case, so we also need to include `#[expect(clippy::missing_safety_doc)]`
on every unsafe function, to avoid a false positive. Unfortunately this
defeats the purpose of the lint, as if someone later removes the safety
docs, the lint rule does not trigger.

I don't know how common this style of documenting unsafe functions is,
but I don't imagine also supporting `# SAFETY` would disturb other users
who prefer `# Safety`.
2024-11-18 18:59:13 +00:00
Catherine Flores
d3edd057b9
Handle Option::map_or(true, …) in unnecessary_map_or lint (#13653)
changelog: [`unnecessary_map_or`]: handle `Option::map_or(true, …)`
2024-11-18 17:33:42 +00:00
Alex Macleod
90de44ab26 Remove extern vectorcall tests 2024-11-18 16:31:10 +00:00
overlookmotel
d8423ca28c missing_safety_doc accept capitalized "SAFETY" 2024-11-18 14:03:16 +00:00
lcnr
bb93c23c08 use TypingEnv when no infcx is available
the behavior of the type system not only depends on the current
assumptions, but also the currentnphase of the compiler. This is
mostly necessary as we need to decide whether and how to reveal
opaque types. We track this via the `TypingMode`.
2024-11-18 10:38:56 +01:00
Philipp Krones
9c8d9504ce
Introduce utils mod in clippy_dev
There was some dependence between the different subcommands of clippy_dev. And
this dependence will increased with the introduction of the sync and release
subcommands. This moves the common functions to a `utils` module, to decouple
the other modules.
2024-11-18 10:04:27 +01:00