Commit graph

12173 commits

Author SHA1 Message Date
Michael Howell
418dfb2257
Add Known problems section 2024-11-24 11:23:14 -07: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
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
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
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
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
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
overlookmotel
d8423ca28c missing_safety_doc accept capitalized "SAFETY" 2024-11-18 14:03: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
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
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
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
c166ee1fc8
Merge remote-tracking branch 'upstream/master' into rustup 2024-11-14 18:27:35 +01:00
Jacherr
89210d7c5a new lint unnecessary_map_or 2024-11-12 23:00:26 +00:00
Boxy
e5b1caef85 Consolidate type system const evaluation under traits::evaluate_const
mew
2024-11-12 02:54:03 +00: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
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
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
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
b816d4ee4f
Merge remote-tracking branch 'upstream/master' into rustup 2024-11-07 17:22:32 +01:00
alexey semenyuk
7bcd578a02
Link fix 2024-11-06 18:23:01 +05: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
blyxyas
626406f1b3 Do not filter empty passes & Make CTFE Clippy into lintless pass 2024-11-05 15:27:09 +01:00
bors
d8a3fcc792 Auto merge of #132580 - compiler-errors:globs, r=Noratrieb
Remove unnecessary pub enum glob-imports from `rustc_middle::ty`

We used to have an idiom in the compiler where we'd prefix or suffix all the variants of an enum, for example `BoundRegionKind`, with something like `Br`, and then *glob-import* that enum variant directly.

`@noratrieb` brought this up, and I think that it's easier to read when we just use the normal style `EnumName::Variant`.

This PR is a bit large, but it's just naming.

The only somewhat opinionated change that this PR does is rename `BorrowKind::Imm` to `BorrowKind::Immutable` and same for the other variants. I think these enums are used sparingly enough that the extra length is fine.

r? `@noratrieb` or reassign
2024-11-05 08:30:56 +00:00
TheSlapstickDictator
1b7239d954 Fixing a missed check for needs_parenthesis in division 2024-11-04 19:19:58 -08:00
GnomedDev
44c2a82972
Swap Visitors to early exit, instead of storing poison flag 2024-11-04 23:49:25 +00:00
Jonathan Dönszelmann
63d0ba9de9 Move two attribute lints to be early pass (post expansion) 2024-11-04 22:47:22 +01:00
Michael Goulet
efeed550c4 Remove BorrowKind glob, make names longer 2024-11-04 04:45:52 +00:00
Michael Goulet
b14362f665 ty::KContainer -> ty::AssocItemContainer::K 2024-11-04 04:45:52 +00:00
bors
ccf7c88386 Auto merge of #13648 - samueltardieu:push-rpxvoukpolvm, r=Centri3
needless_continue: check labels consistency before warning

changelog: [`needless_continue`]: check labels before warning about `continue` as the last statement in a loop body

Fix #13641
2024-11-03 23:17:36 +00:00
bors
a1a9aaef87 Auto merge of #13631 - samueltardieu:push-uoowutzkvsrk, r=Centri3
no_mangle attribute requires unsafe in Rust 2024

Tests without unsafe must not run in edition 2024. Also, error messages have been modified to include the full attribute, so that a use of `#[unsafe(no_mangle)]` does not produce an error message containing `#[no_mangle]`.

changelog: [`no_mangle_attribute`]: handle `#[unsafe(no_mangle)]` as well
2024-11-03 19:43:19 +00:00
TheSlapstickDictator
6d738f6bc0 Fix parens getting removed for non-associative operators 2024-11-03 09:23:03 -08:00
Samuel Tardieu
2f1b7b64fb needless_continue: check labels consistency before warning 2024-11-03 16:49:15 +01:00