`cargo dev fmt` seems to not work for some reason (possibly because of
all the comments in the let-chain), so I formatted it manually -- I hope
it's right
changelog: none
`ptr_eq` was recently enhanced to lint on more cases of raw pointers
comparison:
- lint on all raw pointer comparison, by proposing to use
`[core|std]::ptr::eq(lhs, rhs)` instead of `lhs == rhs`;
- removing one symetric `as usize` on each size if needed
- peeling any level of `as *[const|mut] _` if the remaining expression
can still be coerced into the original one (i.e., is a ref or raw
pointer to the same type as before)
The current change restricts the lint to the cases where at least one
level of symetric `as usize`, or any conversion to a raw pointer, could
be removed. For example, a direct comparaison of two raw pointers will
not trigger the lint anymore.
changelog: [`ptr_eq`]: do not lint when comparing two raw pointers
directly with no casts involved
Fixesrust-lang/rust-clippy#14525
Closes#9191Closes#14444Closes#8055
Adds a new helper to partly check for side effects by recursively
checking if the iterator type contains closures with mutable captures.
changelog: [`double_ended_iterator_last`] fix FP when iter has side
effects
changelog: [`needless_collect`] fix lint not consider side effects
While I like replacing `&x` by `&raw const x` and `&mut x` by `&raw mut
x`, I'm less sure I like the suggested reborrows such as `&raw const
*p`. There was one in Clippy sources, see the PR diff.
@RalfJung, any opinion on this?
Fix#14406
changelog: [`borrow_as_ptr`]: lint implicit casts as well
Fixes#12551
changelog: [`empty_enum_variants_with_brackets`]: Do not lint reachable
enums or enums which are used as functions within the same crate.
r? @xFrednet
deref patterns: implement implicit deref patterns
This implements implicit deref patterns (per https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg#Implicit-deref-patterns) and adds tests and an unstable book chapter.
Best reviewed commit-by-commit. Overall there's a lot of additions, but a lot of that is tests, documentation, and simple(?) refactoring.
Tracking issue: #87121
r? ``@Nadrieril``
The `BodyLifetimeChecker` which checks for the use of any non-anonymous
non-static lifetime did not recurse into closures, missing lifetime
uses. This would lead to a bogus elision suggestion.
The `BodyLifetimeChecker` is not refined enough to avoid false
positives, as any conforming lifetime, including one coming from the
outer context, would be considered a hit. The number of false positives
might increase now that we check closures as well, in case those
closures define and use lifetimes themselves.
changelog: [`needless_lifetimes`]: do not suggest removing a lifetime
which is later used in a closure
Fixesrust-lang/rust-clippy#14607
This lint detects inefficient or useless `{std,core}::mem::swap()` calls
such as:
```rust
// Should be `a = temp();`
swap(&mut a, &mut temp());
// Should be `*b = temp();`
swap(b, &mut temp());
// Should be `temp1(); temp2();` if we want to keep the side effects
swap(&mut temp1(), &mut temp2());
```
It also takes care of using a form appropriate for a `()` context if
`swap()` is part of a larger expression (don't ask me why this wouldn't
happen, I have no idea), by suggesting `{ x = y; }` (statement in block)
or `{std,core}::mem::drop((temp1(), temp2())`.
changelog: [`swap_with_temporary`]: new lint
Close#1968
Limit the recursion depth, as each level of nesting adds another deeper
projection.
There might be a more complex way of handling the problem, but infinite
recursions are bad, and don't allow Clippy to terminate properly.
changelog: [`significant_drop_tightening`]: do not recurse forever when
checking for attribute on type or its constituent
Fixesrust-lang/rust-clippy#13544
@rustbot label +L-nursery
- Do not replace macro results in then/else branches
- Extract condition snippet from the right context
- Make suggestion `MaybeIncorrect` if it would lead to losing comments
changelog: [`bool_to_int_with_if`]: properly handle macros
Fixesrust-lang/rust-clippy#14628
Instead of looking for angle brackets in the source code, use the HIR
and Ty interfaces to either copy the original type, or complete it with
`_` placeholders if all type and const generic arguments are inferred.
Fixesrust-lang/rust-clippy#14581
changelog: [`from_iter_instead_of_collect`]: show correct type in
suggestion
I'm removing empty identifiers everywhere, because in practice they
always mean "no identifier" rather than "empty identifier". (An empty
identifier is impossible.) It's better to use `Option` to mean "no
identifier" because you then can't forget about the "no identifier"
possibility.
Some specifics:
- When testing an attribute for a single name, the commit uses the
`has_name` method.
- When testing an attribute for multiple names, the commit uses the new
`has_any_name` method.
- When using `match` on an attribute, the match arms now have `Some` on
them.
In the tests, we now avoid printing empty identifiers by not printing
the identifier in the `error:` line at all, instead letting the carets
point out the problem.