Based on rust-lang/rust-clippy#13223
Various refactoring on `clippy_dev` before upgrading rename and
splitting `clippy_lints` into multiple crates.
Some improvements:
* The working directory is set to the root clippy directory. Running
from a subdirectory was kind of supported before sometimes. Now it just
works.
* File won't be written unless they're actually updated. Most of the
time they weren't written, but a few cases slipped through.
* Buffers are reused more for the negligible speed boost.
changelog: None
When a `non_std_lazy_statics` warning is generated about an item type
which can be replaced by a standard library one, ensure that the lint
happens on the item HIR node so that it can be expected.
changelog: [`non_std_lazy_statics`]: generate the warning onto the right
node
Fixesrust-lang/rust-clippy#14729
Note that this doesn't change anything on lints generated for the
`lazy_static::lazy_static` macro because the `expect` attribute cannot
be applied to a macro.
Adds an internal lint to check for `#[derive(serde::Deserialize)]`
without
[`#[serde(deny_unknown_fields)]`](https://serde.rs/container-attrs.html#deny_unknown_fields).
Today, if you run Clippy with the following clippy.toml, Clippy will
produce a warning, but there will be no accompanying note:
```toml
# In the following configuration, "recommendation" should be "reason" or "replacement".
disallowed-macros = [
{ path = "std::panic", recommendation = "return a `std::result::Result::Error` instead" },
]
```
```sh
$ cargo clippy
Checking a v0.1.0 (/home/smoelius/tmp/a)
warning: use of a disallowed macro `std::panic`
--> src/lib.rs:2:5
|
2 | panic!();
| ^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros
= note: `#[warn(clippy::disallowed_macros)]` on by default
```
The underlying problem is: the enum that derives `serde::Deserialize`
([`DisallowedPathEnum`](81643e297c/clippy_config/src/types.rs (L47)))
does not have the attribute `#[serde(deny_unknown_fields)]`.
This lint identifies such problems by checking trait `impl`s. An
alternative I considered was to walk `clippy_config::conf::Conf`
directly. However, that would not catch the `DisallowedPathEnum` case
because it [is not used in `Conf`
directly](81643e297c/clippy_config/src/types.rs (L31)).
Just to be clear, no one asked for this. So I hope the maintainers do
not mind.
changelog: none
Added lint for catching `&[foo.clone()]` where foo is a reference and
suggests `std::slice::from_ref(foo)`.
changelog: new lint: [`cloned_ref_to_slice_refs`]
changelog: [`type_repetition_in_bounds`]: include all generic bounds in
suggestion, clearer message which now includes the repeated type name
Fixesrust-lang/rust-clippy#14744
If an expression is not going to return from the current function of
closure, it should not get linted.
This also allows `return` expression to be linted, in addition to the
final expression. Those require blockification and proper indentation.
changelog: [`return_and_then`]: only lint returning expressions
Fixesrust-lang/rust-clippy#14781
relates to rust-lang/rust-clippy#14653
changelog: [`elidable_lifetime_names`]: Fix clippy version that this
lint was introduced in.
It might be good to have some automation to check that the version is
correct.
IIUC the version should be the current nightly version at the time a PR
is merged.
If a release happens while a PR is open, the version needs to be bumped
- this is easy to forget.
Fixes https://github.com/rust-lang/rust-clippy/issues/13973.
I don't think we can make `fn_to_numeric_cast_any` to be emitted in some
special cases. Its category cannot be changed at runtime.
I think in this case, the best might be a specialized new lint so we can
target exactly what we want.
----
changelog: Add new `confusing_method_to_numeric_cast` lint
`tempfile` has deprecated `TempDir::into_path()` (replacing it by
`TempDir::keep()` between version `3.3` which Clippy required and
version `3.20` which is the latest semver-compatible version. Since
Clippy doesn't use a `Cargo.lock` file, the latest version of `tempfile`
is used which leads to CI failure.
changelog: none
r? @flip1995
`tempfile` has deprecated `TempDir::into_path()` (replacing it by
`TempDir::keep()`) between version `3.3` which Clippy required and version
`3.20.0` which is the latest semver-compatible version. Since Clippy
doesn't use a `Cargo.lock` file, the latest version of `tempfile` is
used which leads to CI failure.
If an expression is not going to return from the current function of
closure, it should not get linted.
This also allows `return` expression to be linted, in addition to the
final expression. Those require blockification and proper indentation.
The `mir_drops_elaborated_and_const_checked` query result has been
stolen already and cannot be borrowed again. Use the `optimized_mir`
query result instead.
changelog: [`missing_const_for_fn`]: fix ICE with some compilation
options
Fixesrust-lang/rust-clippy#14774
r? @Jarcho
The `mir_drops_elaborated_and_const_checked` query result has been
stolen already and cannot be borrowed again. Use the `optimized_mir`
query result instead.
The problem is that `check_fn` is triggered by both function and
closure, and `visit_expr` can visit expressions in another closures
within a function or closure.
So just skip walking in a inner closure.
changelog: Fix [`unnecessary_unwrap`] emitted twice in closure which
inside in a function or another closure.
Fixes: rust-lang/rust-clippy#14763
The `to_digit_is_some()` lint suggests using `char::is_digit()`. It
should not trigger in const contexts before Rust 1.87.
changelog: [`to_digit_is_some`]: Do not lint in const contexts when MSRV
is below 1.87
This cleans up `unwrap.rs`:
- use interned symbols instead of strings
- update names to reflect the current implementation
- replaced a cascaded `if` by a shorter `match`
changelog: none
changelog: Fix [`unnecessary_unwrap`] false negative when any assignment
occurs in `if` branch (regardless of any variable).
Fixes: rust-lang/rust-clippy#14725