If a function environment contains trait bounds other than `Sized`,
`const` cannot be used before Rust 1.61.
changelog: [`missing_const_for_fn`]: check MSRV before emitting lint on
function containing non-`Sized` trait bounds
Fixesrust-lang/rust-clippy#15079
r? Jarcho
Closesrust-lang/rust-clippy#8244Closesrust-lang/rust-clippy#15041
This feels like a bug with the compiler, because the panic happens when
`Diag` is getting unwinded. However, `drop()` is already called in
`.cancel()` so this should not happen.
In this PR, I find a workaround to just call `emit()`, since the
`DiagCtxt` here is just a `io::sink`, nothing will happen and the panic
just goes away.
changelog: [`needless_doctest_main`] fix panic when doctest is invalid
Closesrust-lang/rust-clippy#14692
The suggestion of `manual_flatten` does not includes the replacement of
`if let` so far despite of `.flatten()` suggestion.
This PR eliminates a redundant `if let`.
changelog: [`manual_flatten`] the suggestion removes `if let`
It doesn't seem to be load bearing for any clippy lints and the rustc
ones that no longer appear behave the same as they would for a `cargo
check`
r? @blyxyas
changelog: none
The suggestion of `manual_flatten` does not includes the replacement
of `if let` so far despite of `.flatten()` suggestion. This change
eliminates a redundant `if let`.
changelog: [`manual_flatten`] the suggestion removes `if let`
Add a new `mismatched-lifetime-syntaxes` lint
The lang-team [discussed this](https://hackmd.io/nf4ZUYd7Rp6rq-1svJZSaQ) and I attempted to [summarize](https://github.com/rust-lang/rust/pull/120808#issuecomment-2701863833) their decision. The summary-of-the-summary is:
- Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even [lead to unsound code](https://github.com/rust-lang/rust/issues/48686)! Some examples:
```rust
// Lint will warn about these
fn(v: ContainsLifetime) -> ContainsLifetime<'_>;
fn(&'static u8) -> &u8;
```
- Matching up references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule:
```rust
// Lint will not warn about these
fn(&u8) -> &'_ u8;
fn(&'_ u8) -> &u8;
fn(&u8) -> ContainsLifetime<'_>;
```
- Having a lint for consistent syntax of elided lifetimes will make the [future goal](https://github.com/rust-lang/rust/issues/91639) of warning-by-default for paths participating in elision much simpler.
---
This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing `elided-named-lifetimes` lint, which means it starts out life as warn-by-default.
Given a type alias as follows, clippy would detect a false positive for
`unused_unit`.
```rust
type UnusedParensButNoUnit = Box<dyn (Fn())>;
```
changelog: [`unused_unit`]: fix false positive for `Fn` bounds
`clippy_utils::ty::InteriorMut::interior_mut_ty_chain` must stop
recursing forever when types are chained indefinitely due to the use of
associated types in generics. A false negative is acceptable, and
documented here.
Should this situation be later identified specifically, a conversion of
`Option` to `Result` would allow separating the infinitely recursive
case from a negative one.
changelog: [`mutable_key_type`]: fix ICE when infinitely associated
generic types are used
Fixesrust-lang/rust-clippy#14935
This PR introduces a lint which detects when `&Box<dyn Any>` is coerced
to `&dyn Any`, which is usually a mistake where the intent was to
directly pass the `dyn Any` inside the box without coercion.
cc @llogiq
Remaining work:
- [x] Documentation
- [x] Generalize from Box to any implementer of `Deref<Target=dyn Any>`
----
changelog: add [`coerce_container_to_any`] lint
Fix false positives on broken link detection
Refactor variable names
Fix doc comment about broken link lint
Refactor, remove not used variable
Improve broken link to catch more cases and span point to whole link
Include reason why a link is considered broken
Drop some checker because rustdoc already warn about them
Refactor to use a single enum instead of multiple bool variables
Fix lint warnings
Rename function to collect broken links
Warn directly instead of collecting all entries first
Iterate directly rather than collecting
Temporary change to confirm with code reviewer the next steps
Handle broken links as part of the fake_broken_link_callback handler
Simplify broken link detection without state machine usage
Fix typos
Add url check to reduce false positives
Drop reason enum as there is only one reason
Fix duplicated diagnostics
Fix linter
Fixesrust-lang/rust-clippy#14958
`disallowed_names` was used to lint code generated by macros. This
behavior can confuse programmers who did not write the macro themselves.
This change suppresses lints for code originating from macros, including
external ones.
changelog: [`disallowed_names`] do not lint macro generated codes
Fixes https://github.com/rust-lang/rust-clippy/issues/11126
It avoids the ICE when the number of lints changes, this is only a
problem for clippy in development but cleaning the clippy dir requires a
lot of rebuilding
changelog: none
changelog: [`doc_suspicious_footnotes`]: lint for text that looks like a
footnote reference but has no definition
This is an alternative to https://github.com/rust-lang/rust/pull/137803,
meant to address the concerns about false positives.
This lint only fires when the apparent footnote reference has a name
that's made from pure ASCII digits. This choice is justified by running
lintcheck on the top 200 crates, plus the clippy default set:
1. [I ran
lintcheck](https://gist.github.com/notriddle/59072476c9c1fd569fee421270dad665)
with a modded version of this lint that didn't check for digits only. It
produced a false positive warning on a line in mdbook that had a regex,
and no true positives at all.
2. [I also ran
lintcheck](https://gist.github.com/notriddle/74eb8c9e1939b9f5c5549bf1d4fa238a)
with a custom lint that fired on any valid footnote reference with a
non-ascii-digit name. `cargo` uses one in its job_queue module, and
that's all it found.
cc @GuillaumeGomez
Closesrust-lang/rust-clippy#14952
The lint suggests using `.display()` on `Path`, which is actually
correct.
changelog: [`unnecessary_debug_formatting`] fix FP inside `Debug` impl
`disallowed_names` was used to lint code generated by macros.
This behavior can confuse programmers who did not write the macro
themselves. This change suppresses lints for code originating from
macros, including external ones.
changelog: [`disallowed_names`] do not lint macro generated codes
Fixes: rust-lang/rust-clippy#14930
changelog: Fix [`print_literal`] and [`write_literal`]'s
suggestion-causes-error when using format argument like `{0:2$.1$}`
`clippy_utils::ty::InteriorMut::interior_mut_ty_chain` must stop
recursing forever when types are chained indefinitely due to the use of
associated types in generics. A false negative is acceptable, and
documented here.
Should this situation be later identified specifically, a conversion of
`Option` to `Result` would allow separating the infinitely recursive
case from a negative one.