Commit graph

21132 commits

Author SHA1 Message Date
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
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
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
Philipp Krones
a28c44fc96
Merge pull request #13587 from Kobzol/ci-remove-bors
Switch CI from bors to merge queue
2024-11-07 17:42:31 +00:00
Jakub Beránek
843ef1b1f0
Remove path filter
It would cause issues with the required jobs, and it is probably useless anyway, the vast majority of PRs seem to change Rust source files.
2024-11-07 18:32:06 +01:00
Jakub Beránek
9ebe68d8c3
Add conclusion job to PR CI 2024-11-07 18:30:28 +01:00
Philipp Krones
d583df02cc
Remove ui/no_lints.rs test
This test was only meant for debugging purposes
2024-11-07 17:27:46 +01:00
Philipp Krones
a5d6100a10
Bump nightly version -> 2024-11-07 2024-11-07 17:27:46 +01:00
Philipp Krones
b27570b19b
Fix cargo dev update_lints
Now that lints can add @eval_always at the end of their definition, the lint
declaration might not end right after the description. The `update_lints`
command can skip everything that comes after that.
2024-11-07 17:27:46 +01:00
Philipp Krones
c64f1e3591
Fix lint_without_lint_pass internal lint 2024-11-07 17:27:46 +01:00
Philipp Krones
4f12b98654
Clean up declare_clippy_lint
The new @eval_always option should always follow after a comma for consistency
with the declare_tool_lint macro.

Rename $catergory->$level.
2024-11-07 17:22:32 +01:00
Philipp Krones
03daf7ccb2
Fix author lint and move it back to tests/ui
The author lint is not an internal lint, and should also be enabled, when Clippy
is distributed through rustup. This moves the author lint test cases back to
tests/ui.
2024-11-07 17:22:32 +01:00
Philipp Krones
b816d4ee4f
Merge remote-tracking branch 'upstream/master' into rustup 2024-11-07 17:22:32 +01:00
bors
ab560d88e9 Auto merge of #13661 - alex-semenyuk:doc_fix, r=Manishearth
Link fix

[`clippy::await_holding_lock`](https://rust-lang.github.io/rust-clippy/master/index.html#/await_holding_lock) has unformatted link

changelog: none
2024-11-06 17:06:44 +00:00
alexey semenyuk
7bcd578a02
Link fix 2024-11-06 18:23:01 +05:00
bors
f02a0208e5 Auto merge of #13659 - samueltardieu:push-twtxmtvopoxo, r=blyxyas
no_mangle_with_rust_abi: properly position the suggested ABI

Fix #13656

changelog: [`no_mangle_with_rust_abi`]: properly position the suggested ABI
2024-11-06 11:27:13 +00:00
Samuel Tardieu
c1ab18d1c0 no_mangle_with_rust_abi: properly position the suggested ABI 2024-11-05 23:10:41 +01:00
Jonathan Dönszelmann
c93109674f
collect attribute spans early for disallowed macros 2024-11-05 20:46:44 +01:00
Matthias Krüger
4847c40c8b Rollup merge of #132637 - blyxyas:lint-less-passes, r=flip1995
Do not filter empty lint passes & re-do CTFE pass

Some structs implement `LintPass` without having a `Lint` associated with them #125116 broke that behaviour by filtering them out. This PR ensures that lintless passes are not filtered out.
2024-11-05 20:10:53 +01:00
bors
6631a2c1b7 Auto merge of #13654 - GnomedDev:early-exit-visitors, r=Alexendoo
Swap Visitors to early exit, instead of storing poison flag

I noticed that a bunch of visitors had a `poison` or `success` field, when they could just be returning `ControlFlow`.

changelog: none
2024-11-05 17:39:32 +00:00
blyxyas
626406f1b3 Do not filter empty passes & Make CTFE Clippy into lintless pass 2024-11-05 15:27:09 +01:00