If a reborrow is itself borrowed mutably, do not propose to replace it
by the original reference.
Fixes: rust-lang/rust-clippy#14934
changelog: [`borrow_deref_ref`]: do not propose replacing a reborrow by
the original reference if the reborrow is itself mutably borrowed
For example, adding `*` in front of `*expression` is best shown as
`**expression` rather than `*(*expression)`.
This is not perfect, as it checks whether the operator is already a
prefix of the expression, but it is better than it was before. For
example, `&`+`&mut x` will get `&&mut x` but `&mut `+`&x` will get `&mut
(&x)` as it did before this change.
changelog: none
Optimize `needless_doctest_main`, make it short-circuit, make sure that
we don't spin up a new compiler on EVERY code block.
---
The old implementation was creating a new compiler, new parser, new
thread, new SessionGlobals, new everything for each code block. No
matter if they actually didn't even contain `fn main()` or anything
relevant.
On callgrind, seems that we're reducing about a 6.7242% de cycle count
(which turns out to be a 38 million instruction difference, great!).
Benchmarked in `bumpalo-3.16.0`. Also on bumpalo we spawn 78 less
threads. This moves `SessionGlobals::new` from the top time-consuming
function by itself in some benchmarks, into one not even in the top 500.
Also, populate the test files.
changelog:[`needless_doctest_main`]: Avoid spawning so many threads in
unnecessary circumstances
The lint will note `the end suggestion probably needs some adjustments
to use the expression result correctly` when the expr's is not unit. So
I extend this note to also appear when the expr is in an assignment.
changelog: [`branches_sharing_code`] fix misleading suggestions when in
assignment
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`
For example, adding `*` in front of `*expression` is best shown as
`**expression` rather than `*(*expression)`.
This is not perfect, as it checks whether the operator is already a prefix
of the expression, but it is better than it was before. For example,
`&`+`&mut x` will get `&&mut x` but `&mut `+`&x` will get `&mut (&x)`
as it did before this change.
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.