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

Diff for: clippy_lints/src/booleans.rs

+4-4
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 {

Diff for: clippy_lints/src/box_default.rs

+1-1
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 {

Diff for: clippy_lints/src/checked_conversions.rs

+1-1
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 {

Diff for: clippy_lints/src/default_numeric_fallback.rs

+1-1
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(

Diff for: clippy_lints/src/doc/mod.rs

+1-1
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<'_>) {

Diff for: clippy_lints/src/empty_enum.rs

+1-1
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

Diff for: clippy_lints/src/escape.rs

+2-2
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() {

Diff for: clippy_lints/src/excessive_nesting.rs

+1-1
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;

Diff for: clippy_lints/src/extra_unused_type_parameters.rs

+1-1
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>) {

Diff for: clippy_lints/src/fallible_impl_from.rs

+1-1
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) {

Diff for: clippy_lints/src/format_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ struct FormatArgsExpr<'a, 'tcx> {
219219
ignore_mixed: bool,
220220
}
221221

222-
impl<'a, 'tcx> FormatArgsExpr<'a, 'tcx> {
222+
impl FormatArgsExpr<'_, '_> {
223223
fn check_templates(&self) {
224224
for piece in &self.format_args.template {
225225
if let FormatArgsPiece::Placeholder(placeholder) = piece

Diff for: clippy_lints/src/format_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct FormatImplExpr<'a, 'tcx> {
148148
format_trait_impl: FormatTraitNames,
149149
}
150150

151-
impl<'a, 'tcx> FormatImplExpr<'a, 'tcx> {
151+
impl FormatImplExpr<'_, '_> {
152152
fn check_to_string_in_display(&self) {
153153
if self.format_trait_impl.name == sym::Display
154154
&& let ExprKind::MethodCall(path, self_arg, ..) = self.expr.kind

Diff for: clippy_lints/src/from_over_into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct SelfFinder<'a, 'tcx> {
126126
invalid: bool,
127127
}
128128

129-
impl<'a, 'tcx> Visitor<'tcx> for SelfFinder<'a, 'tcx> {
129+
impl<'tcx> Visitor<'tcx> for SelfFinder<'_, 'tcx> {
130130
type NestedFilter = OnlyBodies;
131131

132132
fn nested_visit_map(&mut self) -> Self::Map {

Diff for: clippy_lints/src/implicit_hasher.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<'a, 'tcx> ImplicitHasherTypeVisitor<'a, 'tcx> {
281281
}
282282
}
283283

284-
impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> {
284+
impl<'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'_, 'tcx> {
285285
fn visit_ty(&mut self, t: &'tcx hir::Ty<'_>) {
286286
if let Some(target) = ImplicitHasherType::new(self.cx, t) {
287287
self.found.push(target);
@@ -318,7 +318,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
318318
}
319319
}
320320

321-
impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
321+
impl<'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'_, '_, 'tcx> {
322322
type NestedFilter = nested_filter::OnlyBodies;
323323

324324
fn visit_body(&mut self, body: &Body<'tcx>) {

Diff for: clippy_lints/src/index_refutable_slice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ struct SliceIndexLintingVisitor<'a, 'tcx> {
226226
max_suggested_slice: u64,
227227
}
228228

229-
impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> {
229+
impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> {
230230
type NestedFilter = nested_filter::OnlyBodies;
231231

232232
fn nested_visit_map(&mut self) -> Self::Map {

0 commit comments

Comments
 (0)