Commit graph

21150 commits

Author SHA1 Message Date
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
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
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
Alejandra González
0712689aae
Prepare clippy_utils README and Cargo.toml for publishing (#13693)
Follow up to https://github.com/rust-lang/rust-clippy/pull/13691

Adds metadata to the `clippy_utils/Cargo.toml`, which is mostly copied
from the root `Cargo.toml`.
Adds a `README.md` file listing the nightly version `clippy_utils` can
be used with, mentions that there are no stability guarantees and the
license.

The next PR will add automation to update the nightly toolchains in
those files and the versions in the `Cargo.toml`s.

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

changelog: none
2024-11-17 22:49:16 +00:00
Timo
97b9e4af17
Do not trigger if_let_mutex starting from Edition 2024 (#13695)
Close #13679

changelog: [`if_let_mutex`]: disable lint from Edition 2024 since
[stabilized if_let_rescope
](https://github.com/rust-lang/rust/issues/131154)
2024-11-17 18:10:29 +00:00
Alexey Semenyuk
ef42a66afe Do not trigger if_let_mutex strating from Edition 2024 2024-11-17 22:49:17 +05:00
Philipp Krones
74b95f2e65
Prepare clippy_utils for publishing
- Add metadata to clippy_utils/Cargo.toml file
- Add clippy_utils README.md file
2024-11-17 18:16:13 +01:00
Catherine Flores
8698c31f88
Don't lint CStr literals, do lint float literals in redundant_guards (#13698)
Two changes to `redundant_guards`:

- Lint float literals. We used to do that before but that was changed in
#11305 because at the time there was a future compat warning and it was
planned to make pattern matching floats a hard error.

In rust-lang/rust#116284 it was decided to actually remove the lint and
only make matching `NAN` specifically a hard error. The `NAN` part isn't
relevant/important here because this PR only changes what literals are
warned and `f64::NAN` isn't a literal, but I've added a test anyway to
make sure we continue to not lint there.
- Don't lint CStr literals because that can't be a pattern right now
(fixes #13681)

changelog: none
2024-11-17 04:24:43 +00:00
y21
8859847373 redundant_guards: lint float literals, don't lint cstr literals 2024-11-17 04:14:27 +01:00
Alex Macleod
5f05ce4c70
Support user format-like macros (#9948)
Add support for `#[clippy::format_args]` attribute that can be attached
to any macro to indicate that it functions the same as the built-in
format macros like `format!`, `println!` and `write!`

---

changelog: Enhancement: [`format_in_format_args`],
[`recursive_format_impl`], [`to_string_in_format_args`],
[`uninlined_format_args`], [`unused_format_specs`]: Recognizes
`#[clippy::format_args]` to support custom 3rs party format macros.
2024-11-16 02:59:26 +00:00
Samuel Tardieu
de03a05bc8 unnecessary_map_or: lint .map_or(true, …) as well 2024-11-16 00:12:41 +01:00
Samuel Tardieu
ca963b653e Simplify instances of Option::map_or(true, …) in Clippy sources 2024-11-16 00:12:41 +01:00
Samuel Tardieu
d1688b53f1 unnecessary_map_or: add non-comparaison tests 2024-11-15 23:56:19 +01:00
Yuri Astrakhan
81dceed8ba Support user format-like macros
Add support for `#[clippy::format_args]` attribute that can be attached to any macro to indicate that it functions the same as the built-in format macros like `format!`, `println!` and `write!`
2024-11-15 15:26:48 -05:00
Alejandra González
627363e811
Reverse dependency between clippy_utils and clippy_config (#13691)
In preparation of #13556, I want to remove the dependency on
`clippy_config`, as I don't think that we want to publish that for
outside consumers. To do this the 2 dependecies on `clippy_config` had
to be removed:

1. The MSRV implementation was in `clippy_config`, but was required in
`qualify_min_const`. I think exposing the MSRV infrastructure and the
MSRVs we defined might also be helpful for `clippy_utils` users. I don't
see why it should not be able to live in `clippy_utils` from a technical
point of few.
2. The `create_disallowed_map` function that took in a
`clippy_utils::types::DisallowedPath` is moved to the `DisallowedPath`
implementation. This also fits there and is only useful for Clippy and
not in `clippy_utils` for external consumers.

`clippy_config` now depends in `clippy_utils`, so the dependecy just got
reversed. But having the `clippy_utils` crate as the base of the
dependency tree in Clippy makes sense.

changelog: none
2024-11-15 20:08:03 +00:00
Alex Macleod
83f7526cf0
Allow conditional Send futures in future_not_send (#13590)
Closes #6947

This changes the lint to allow futures which are not `Send` as a result
of a generic type parameter not having a `Send` bound and only lint
futures that are always `!Send` for any type, which I believe is the
more useful behavior (like the comments in the linked issue explain).

This is still only a heuristic (I'm not sure if there's a more general
way to do this), but it should cover the common cases I could think of
(including the code examples in the linked issue)

changelog: [`future_not_send`]: allow conditional `Send` futures
2024-11-15 19:23:58 +00:00
Philipp Krones
5c1811ab94
Rename all clippy_config::msrvs -> clippy_utils::msrvs 2024-11-15 19:38:09 +01:00
Philipp Krones
81483d4a6c
Move create_disallowed_map to clippy_config 2024-11-15 19:30:29 +01:00
Philipp Krones
4460db0850
Move MSRV implementation to clippy_utils 2024-11-15 19:26:39 +01:00
Philipp Krones
786fbd6d68
Rustup (#13687)
r? @ghost

changelog: none
2024-11-14 17:32:56 +00:00
Philipp Krones
99ef36938a
Bump nightly version -> 2024-11-14 2024-11-14 18:27:46 +01:00
Philipp Krones
c166ee1fc8
Merge remote-tracking branch 'upstream/master' into rustup 2024-11-14 18:27:35 +01:00
Catherine Flores
b829d53c19
New lint: unnecessary_map_or (#11796)
Closes https://github.com/rust-lang/rust-clippy/issues/10118

This lint checks `map_or` method calls to check if they can be
consolidated down to something simpler and/or more readable.

For example, the code
```rs
let x = Some(5);
x.map_or(false, |n| n == 5)
```

can be rewritten as
```rs
let x = Some(5);
x == Some(5)
```

In addition, when the closure is more complex, the code can be altered
from, say,
```rs
let x = Ok::<Vec<i32>, i32>(vec![5]);
x.map_or(false, |n| n == [5])
```
into
```rs
let x = Ok::<Vec<i32>, i32>(vec![5]);
x.is_some_and(|n| n == [5])
```

This lint also considers cases where the `map_or` can be chained with
other method calls, and accommodates accordingly by adding extra
parentheses as needed to the suggestion.

changelog: add new lint `unnecessary_map_or`
2024-11-13 00:08:36 +00:00
Jacherr
89210d7c5a new lint unnecessary_map_or 2024-11-12 23:00:26 +00:00
Matthias Krüger
2285535d04 Rollup merge of #132541 - RalfJung:const-stable-extern-crate, r=compiler-errors
Proper support for cross-crate recursive const stability checks

~~Stacked on top of https://github.com/rust-lang/rust/pull/132492; only the last three commits are new.~~

In a crate without `staged_api` but with `-Zforce-unstable-if-unmarked`, we now subject all functions marked with `#[rustc_const_stable_indirect]` to recursive const stability checks. We require an opt-in so that by default, a crate can be built with `-Zforce-unstable-if-unmarked` and use nightly features as usual. This property is recorded in the crate metadata so when a `staged_api` crate calls such a function, it sees the `#[rustc_const_stable_indirect]` and allows it to be exposed on stable. This, finally, will let us expose `const fn` from hashbrown on stable.

The second commit makes const stability more like regular stability: via `check_missing_const_stability`, we ensure that all publicly reachable functions have a const stability attribute -- both in  `staged_api` crates and `-Zforce-unstable-if-unmarked` crates. To achieve this, we move around the stability computation so that const stability is computed after regular stability is done. This lets us access the final result of the regular stability computation, which we use so that `const fn` can inherit the regular stability (but only if that is "unstable"). Fortunately, this lets us get rid of an `Option` in `ConstStability`.

This is the last PR that I have planned in this series.

r? `@compiler-errors`
2024-11-12 18:11:04 +01:00
Boxy
e5b1caef85 Consolidate type system const evaluation under traits::evaluate_const
mew
2024-11-12 02:54:03 +00:00
bors
e2962cc079 Auto merge of #126597 - estebank:unicode-output, r=fmease
Add Unicode block-drawing compiler output support

Add nightly-only theming support to rustc output using Unicode box
drawing characters instead of ASCII-art to draw the terminal UI.

In order to enable, the flags `-Zunstable-options=yes --error-format=human-unicode` must be passed in.

After:

```
error: foo
  ╭▸ test.rs:3:3
  │
3 │       X0 Y0 Z0
  │   ┌───╿──│──┘
  │  ┌│───│──┘
  │ ┏││━━━┙
  │ ┃││
4 │ ┃││   X1 Y1 Z1
5 │ ┃││   X2 Y2 Z2
  │ ┃│└────╿──│──┘ `Z` label
  │ ┃└─────│──┤
  │ ┗━━━━━━┥  `Y` is a good letter too
  │        `X` is a good letter
  ╰╴
note: bar
  ╭▸ test.rs:4:3
  │
4 │ ┏   X1 Y1 Z1
5 │ ┃   X2 Y2 Z2
6 │ ┃   X3 Y3 Z3
  │ ┗━━━━━━━━━━┛
  ├ note: bar
  ╰ note: baz
note: qux
  ╭▸ test.rs:4:3
  │
4 │   X1 Y1 Z1
  ╰╴  ━━━━━━━━
```

Before:

```
error: foo
 --> test.rs:3:3
  |
3 |       X0 Y0 Z0
  |    ___^__-__-
  |   |___|__|
  |  ||___|
  | |||
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
  |
note: bar
 --> test.rs:4:3
  |
4 | /   X1 Y1 Z1
5 | |   X2 Y2 Z2
6 | |   X3 Y3 Z3
  | |__________^
  = note: bar
  = note: baz
note: qux
 --> test.rs:4:3
  |
4 |   X1 Y1 Z1
  |   ^^^^^^^^
```

After:

![rustc output with unicode box drawing characters](https://github.com/rust-lang/rust/assets/1606434/d210b79a-6579-4407-9706-ba8edc6e9f25)

Before:
![current rustc output with ASCII art](https://github.com/rust-lang/rust/assets/1606434/5aecccf8-a6ee-4469-8b39-72fb0d979a9f)
2024-11-11 00:00:58 +00:00
Esteban Küber
da93d78049 Add Unicode block-drawing compiler output support
Add nightly-only theming support to rustc output using Unicode box
drawing characters instead of ASCII-art to draw the terminal UI:

After:

```
error: foo
  ╭▸ test.rs:3:3
  │
3 │       X0 Y0 Z0
  │   ┌───╿──│──┘
  │  ┌│───│──┘
  │ ┏││━━━┙
  │ ┃││
4 │ ┃││   X1 Y1 Z1
5 │ ┃││   X2 Y2 Z2
  │ ┃│└────╿──│──┘ `Z` label
  │ ┃└─────│──┤
  │ ┗━━━━━━┥  `Y` is a good letter too
  │        `X` is a good letter
  ╰╴
note: bar
  ╭▸ test.rs:4:3
  │
4 │ ┏   X1 Y1 Z1
5 │ ┃   X2 Y2 Z2
6 │ ┃   X3 Y3 Z3
  │ ┗━━━━━━━━━━┛
  ├ note: bar
  ╰ note: baz
note: qux
  ╭▸ test.rs:4:3
  │
4 │   X1 Y1 Z1
  ╰╴  ━━━━━━━━
```

Before:

```
error: foo
 --> test.rs:3:3
  |
3 |       X0 Y0 Z0
  |    ___^__-__-
  |   |___|__|
  |  ||___|
  | |||
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
  |
note: bar
 --> test.rs:4:3
  |
4 | /   X1 Y1 Z1
5 | |   X2 Y2 Z2
6 | |   X3 Y3 Z3
  | |__________^
  = note: bar
  = note: baz
note: qux
 --> test.rs:4:3
  |
4 |   X1 Y1 Z1
  |   ^^^^^^^^
```
2024-11-10 23:57:18 +01:00
y21
1309e8f3f3 allow conditional Send futures in future_not_send 2024-11-10 19:58:11 +01:00
Timo
f58088b23e
Add match-based manual try to clippy::question_mark (#13627)
Closes #10.

changelog: [`question_mark`]: Now lints for match-based manual try
2024-11-10 16:26:56 +00:00
Ralf Jung
353f8e1323 ensure that all publicly reachable const fn have const stability info 2024-11-10 10:16:26 +01:00
Manish Goregaokar
4f0e46b74d
Fix large_include_file lint being triggered all the time by doc comments (#13672)
Fixes #13670.

Bug was that I forgot to add the comparison with the included file
content length...

changelog: Fix `large_include_file` lint being triggered all the time by
doc comments
2024-11-09 16:01:12 +00:00
Guillaume Gomez
223bffd0d2 Fix large_include_file lint being triggered all the time by doc comments 2024-11-09 13:55:20 +01:00
Jason Newcomb
8cfb95959b
fix: identity_op suggestions use correct parenthesis (#13647)
The `identity_op` lint was suggesting code fixes that resulted in
incorrect or broken code, due to missing parenthesis in the fix that
changed the semantics of the code.

For a binary expression, `left op right`, if the `left` was redundant,
it would check if the right side needed parenthesis, but if the `right`
was redundant, it would just assume that the left side did not need
parenthesis.

This can result in rustfix generating broken code and failing, or
generating code that has different behavior than before the fix. e.g.
`-(x + y + 0)` would turn into `-x + y`, changing the behavior, and
`1u64 + (x + y + 0i32) as u64` where `x: i32` and `y: i32` would turn
into `1u64 + x + y as u64`, creating an error where `x` cannot be added
to the other values, as it was never cast to `u64`.

This commit fixes both of these problems by always checking the
non-redundant child of a binary expression for needed parenthesis.

fixes #13470

changelog: [`identity_op`]: Fix suggested code that is broken or has
changed behavior
2024-11-09 05:03:10 +00:00
Philipp Krones
c21c781a4e Clippy: cfg out validate_diag on release builds 2024-11-08 10:49:54 +01:00
TheSlapstickDictator
ef0f1cad59 Remove check for duplicate parenthesis
It was an incorrect, and could lead to behavior changes in the
suggested code
2024-11-07 20:45:15 -08:00
Philipp Krones
6ced8c33c0 Merge commit 'f712eb5cdccd121d0569af12f20e6a0fabe4364d' into clippy-subtree-update 2024-11-07 22:37:01 +01:00
Philipp Krones
f712eb5cdc
Merge pull request #13657 from jdonszelmann/disallowed-macros-to-early
collect attribute spans early for disallowed macros
2024-11-07 19:23:20 +00:00
Philipp Krones
3518178443
Merge pull request #13639 from flip1995/rustup
Rustup
2024-11-07 18:02:25 +00:00
Philipp Krones
b1166963aa
Remove CI badge from README and book 2024-11-07 18:57:29 +01:00