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

115 files changed

Lines changed: 796 additions & 618 deletions

File tree

Some content is hidden

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

‎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:&'aLateContext<'tcx>,
206206
}
207207

208-
impl<'a,'tcx,'v>Hir2Qmm<'a,'tcx,'v>{
208+
impl<'v>Hir2Qmm<'_,'_,'v>{
209209
fnextract(&mutself,op:BinOpKind,a:&[&'vExpr<'_>],mutv:Vec<Bool>) -> Result<Vec<Bool>,String>{
210210
for a in a {
211211
ifletExprKind::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+
implSuggestContext<'_,'_,'_>{
296296
fnrecurse(&mutself,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
fnbool_expr(&self,e:&'tcxExpr<'_>){
480480
letmut 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>forNonminimalBoolVisitor<'a,'tcx>{
585+
impl<'tcx>Visitor<'tcx>forNonminimalBoolVisitor<'_,'tcx>{
586586
fnvisit_expr(&mutself,e:&'tcxExpr<'_>){
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
structInferVisitor(bool);
9393

94-
impl<'tcx>Visitor<'tcx>forInferVisitor{
94+
implVisitor<'_>forInferVisitor{
9595
fnvisit_ty(&mutself,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>forCheckedConversions{
51+
implLateLintPass<'_>forCheckedConversions{
5252
fncheck_expr(&mutself,cx:&LateContext<'_>,item:&Expr<'_>){
5353
ifletExprKind::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>forNumericFallbackVisitor<'a,'tcx>{
122+
impl<'tcx>Visitor<'tcx>forNumericFallbackVisitor<'_,'tcx>{
123123
fnvisit_expr(&mutself,expr:&'tcxExpr<'_>){
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>forFindPanicUnwrap<'a,'tcx>{
973+
impl<'tcx>Visitor<'tcx>forFindPanicUnwrap<'_,'tcx>{
974974
typeNestedFilter = nested_filter::OnlyBodies;
975975

976976
fnvisit_expr(&mutself,expr:&'tcxExpr<'_>){

‎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>forEmptyEnum{
63+
implLateLintPass<'_>forEmptyEnum{
6464
fncheck_item(&mutself,cx:&LateContext<'_>,item:&Item<'_>){
6565
ifletItemKind::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>forEscapeDelegate<'a,'tcx>{
144+
impl<'tcx>Delegate<'tcx>forEscapeDelegate<'_,'tcx>{
145145
fnconsume(&mutself,cmt:&PlaceWithHirId<'tcx>, _:HirId){
146146
if cmt.place.projections.is_empty(){
147147
ifletPlaceBase::Local(lid) = cmt.place.base{
@@ -188,7 +188,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
188188
fnfake_read(&mutself, _:&PlaceWithHirId<'tcx>, _:FakeReadCause, _:HirId){}
189189
}
190190

191-
impl<'a,'tcx>EscapeDelegate<'a,'tcx>{
191+
impl<'tcx>EscapeDelegate<'_,'tcx>{
192192
fnis_large_box(&self,ty:Ty<'tcx>) -> bool{
193193
// Large types need to be boxed to avoid stack overflows.
194194
ifletSome(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<'_>forNestingVisitor<'conf,'cx>{
138+
implVisitor<'_>forNestingVisitor<'_,'_>{
139139
fnvisit_block(&mutself,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>forTypeWalker<'cx,'tcx>{
196+
impl<'tcx>Visitor<'tcx>forTypeWalker<'_,'tcx>{
197197
typeNestedFilter = nested_filter::OnlyBodies;
198198

199199
fnvisit_ty(&mutself,t:&'tcxTy<'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>forFindPanicUnwrap<'a,'tcx>{
76+
impl<'tcx>Visitor<'tcx>forFindPanicUnwrap<'_,'tcx>{
7777
fnvisit_expr(&mutself,expr:&'tcxExpr<'_>){
7878
ifletSome(macro_call) = root_macro_call_first_node(self.lcx, expr){
7979
ifis_panic(self.lcx, macro_call.def_id){

0 commit comments

Comments
 (0)