Skip to content

Commit db1bda3

Browse files
committed
Auto merge of #13286 - smoelius:elidable-impl-lifetimes, r=Alexendoo
Extend `needless_lifetimes` to suggest eliding `impl` lifetimes Example: ``` error: the following explicit lifetimes could be elided: 'a --> tests/ui/needless_lifetimes.rs:332:10 | LL | impl<'a> Foo for Baz<'a> {} | ^^ ^^ | help: elide the lifetimes | LL - impl<'a> Foo for Baz<'a> {} LL + impl Foo for Baz<'_> {} ``` The main change is in how `impl` lifetime uses are tracked. Previously, a hashmap was created, and lifetimes were removed from the hashmap as their uses were discovered. However, the uses are needed to generate elision suggestions. So, now, uses are added to the hashmap as they are discovered. The PR is currently organized as six commits, which I think are self-explanatory: - Extend `needless_lifetimes` to suggest eliding `impl` lifetimes - Reorder functions _[not strictly necessary, but IMHO, the code is better structured as a result]_ - Fix lifetime tests - Fix non-lifetime tests - Fix `clippy_lints` and `clippy_utils` - Fix typo in `needless_lifetimes` test r? `@Alexendoo` (I think you are `needless_lifetimes`' primary author? Sorry if I have this wrong.) --- changelog: Extend `needless_lifetimes` to suggest eliding `impl` lifetimes
2 parents 061004a + 54e4761 commit db1bda3

File tree

115 files changed

+796
-618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+796
-618
lines changed

clippy_lints/src/booleans.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct Hir2Qmm<'a, 'tcx, 'v> {
205205
cx: &'a LateContext<'tcx>,
206206
}
207207

208-
impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
208+
impl<'v> Hir2Qmm<'_, '_, 'v> {
209209
fn extract(&mut self, op: BinOpKind, a: &[&'v Expr<'_>], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
210210
for a in a {
211211
if let ExprKind::Binary(binop, lhs, rhs) = &a.kind {
@@ -292,7 +292,7 @@ struct SuggestContext<'a, 'tcx, 'v> {
292292
output: String,
293293
}
294294

295-
impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
295+
impl SuggestContext<'_, '_, '_> {
296296
fn recurse(&mut self, suggestion: &Bool) -> Option<()> {
297297
use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True};
298298
match suggestion {
@@ -475,7 +475,7 @@ fn terminal_stats(b: &Bool) -> Stats {
475475
stats
476476
}
477477

478-
impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
478+
impl<'tcx> NonminimalBoolVisitor<'_, 'tcx> {
479479
fn bool_expr(&self, e: &'tcx Expr<'_>) {
480480
let mut h2q = Hir2Qmm {
481481
terminals: Vec::new(),
@@ -582,7 +582,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
582582
}
583583
}
584584

585-
impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
585+
impl<'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'_, 'tcx> {
586586
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
587587
if !e.span.from_expansion() {
588588
match &e.kind {

clippy_lints/src/box_default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn is_local_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>, ref_expr: &Expr<'_>)
9191
#[derive(Default)]
9292
struct InferVisitor(bool);
9393

94-
impl<'tcx> Visitor<'tcx> for InferVisitor {
94+
impl Visitor<'_> for InferVisitor {
9595
fn visit_ty(&mut self, t: &Ty<'_>) {
9696
self.0 |= matches!(t.kind, TyKind::Infer | TyKind::OpaqueDef(..) | TyKind::TraitObject(..));
9797
if !self.0 {

clippy_lints/src/checked_conversions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl CheckedConversions {
4848

4949
impl_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]);
5050

51-
impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
51+
impl LateLintPass<'_> for CheckedConversions {
5252
fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) {
5353
if let ExprKind::Binary(op, lhs, rhs) = item.kind
5454
&& let (lt1, gt1, op2) = match op.node {

clippy_lints/src/default_numeric_fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'a, 'tcx> NumericFallbackVisitor<'a, 'tcx> {
119119
}
120120
}
121121

122-
impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
122+
impl<'tcx> Visitor<'tcx> for NumericFallbackVisitor<'_, 'tcx> {
123123
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
124124
match &expr.kind {
125125
ExprKind::Block(

clippy_lints/src/doc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ impl<'a, 'tcx> FindPanicUnwrap<'a, 'tcx> {
970970
}
971971
}
972972

973-
impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
973+
impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> {
974974
type NestedFilter = nested_filter::OnlyBodies;
975975

976976
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {

clippy_lints/src/empty_enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ declare_clippy_lint! {
6060

6161
declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]);
6262

63-
impl<'tcx> LateLintPass<'tcx> for EmptyEnum {
63+
impl LateLintPass<'_> for EmptyEnum {
6464
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
6565
if let ItemKind::Enum(..) = item.kind
6666
// Only suggest the `never_type` if the feature is enabled

clippy_lints/src/escape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn is_argument(tcx: TyCtxt<'_>, id: HirId) -> bool {
141141
matches!(tcx.parent_hir_node(id), Node::Param(_))
142142
}
143143

144-
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
144+
impl<'tcx> Delegate<'tcx> for EscapeDelegate<'_, 'tcx> {
145145
fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
146146
if cmt.place.projections.is_empty() {
147147
if let PlaceBase::Local(lid) = cmt.place.base {
@@ -188,7 +188,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
188188
fn fake_read(&mut self, _: &PlaceWithHirId<'tcx>, _: FakeReadCause, _: HirId) {}
189189
}
190190

191-
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {
191+
impl<'tcx> EscapeDelegate<'_, 'tcx> {
192192
fn is_large_box(&self, ty: Ty<'tcx>) -> bool {
193193
// Large types need to be boxed to avoid stack overflows.
194194
if let Some(boxed_ty) = ty.boxed_ty() {

clippy_lints/src/excessive_nesting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl NestingVisitor<'_, '_> {
135135
}
136136
}
137137

138-
impl<'conf, 'cx> Visitor<'_> for NestingVisitor<'conf, 'cx> {
138+
impl Visitor<'_> for NestingVisitor<'_, '_> {
139139
fn visit_block(&mut self, block: &Block) {
140140
if block.span.from_expansion() {
141141
return;

clippy_lints/src/extra_unused_type_parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn bound_to_trait_def_id(bound: &GenericBound<'_>) -> Option<LocalDefId> {
193193
bound.trait_ref()?.trait_def_id()?.as_local()
194194
}
195195

196-
impl<'cx, 'tcx> Visitor<'tcx> for TypeWalker<'cx, 'tcx> {
196+
impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
197197
type NestedFilter = nested_filter::OnlyBodies;
198198

199199
fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) {

clippy_lints/src/fallible_impl_from.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn lint_impl_body(cx: &LateContext<'_>, impl_span: Span, impl_items: &[hir::Impl
7373
result: Vec<Span>,
7474
}
7575

76-
impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
76+
impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> {
7777
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
7878
if let Some(macro_call) = root_macro_call_first_node(self.lcx, expr) {
7979
if is_panic(self.lcx, macro_call.def_id) {

0 commit comments

Comments
 (0)