Skip to content

Commit 7cf2e9a

Browse files
committed
Add support for tail calls in clippy
1 parent cd7742c commit 7cf2e9a

File tree

8 files changed

+24
-9
lines changed

8 files changed

+24
-9
lines changed

src/tools/clippy/clippy_lints/src/loops/never_loop.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ fn never_loop_expr(expr: &Expr<'_>, ignore_ids: &mut Vec<HirId>, main_loop_id: H
206206
NeverLoopResult::AlwaysBreak,
207207
)
208208
}),
209+
ExprKind::Become(e) => {
210+
combine_seq(
211+
never_loop_expr(e, ignore_ids, main_loop_id),
212+
NeverLoopResult::AlwaysBreak,
213+
)
214+
}
209215
ExprKind::InlineAsm(asm) => asm
210216
.operands
211217
.iter()

src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SigDropHelper<'a, 'tcx> {
329329
ExprKind::Field(..) |
330330
ExprKind::Index(..) |
331331
ExprKind::Ret(..) |
332+
ExprKind::Become(..) |
332333
ExprKind::Repeat(..) |
333334
ExprKind::Yield(..) => walk_expr(self, ex),
334335
ExprKind::AddrOf(_, _, _) |

src/tools/clippy/clippy_lints/src/utils/author.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,11 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
559559
kind!("Ret({value})");
560560
value.if_some(|e| self.expr(e));
561561
},
562+
ExprKind::Become(value) => {
563+
bind!(self, value);
564+
kind!("Become({value})");
565+
self.expr(value);
566+
},
562567
ExprKind::InlineAsm(_) => {
563568
kind!("InlineAsm(_)");
564569
out!("// unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment");

src/tools/clippy/clippy_utils/src/eager_or_lazy.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
152152
self.eagerness |= NoChange;
153153
return;
154154
},
155+
ExprKind::Become(..) => {
156+
self.eagerness = ForceNoChange;
157+
return;
158+
}
155159
ExprKind::Path(ref path) => {
156160
if res_has_significant_drop(self.cx.qpath_res(path, e.hir_id), self.cx, e) {
157161
self.eagerness = ForceNoChange;

src/tools/clippy/clippy_utils/src/hir_utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
845845
self.hash_expr(e);
846846
}
847847
},
848+
ExprKind::Become(f) => {
849+
self.hash_expr(f);
850+
}
848851
ExprKind::Path(ref qpath) => {
849852
self.hash_qpath(qpath);
850853
},

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,8 @@ fn check_terminator<'tcx>(
314314
Err((span, "const fn generators are unstable".into()))
315315
},
316316

317-
TerminatorKind::Call {
318-
func,
319-
args,
320-
from_hir_call: _,
321-
destination: _,
322-
target: _,
323-
unwind: _,
324-
fn_span: _,
325-
} => {
317+
TerminatorKind::Call { func, args, .. }
318+
| TerminatorKind::TailCall { func, args, .. } => {
326319
let fn_ty = func.ty(body, tcx);
327320
if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() {
328321
if !is_const_fn(tcx, fn_def_id, msrv) {

src/tools/clippy/clippy_utils/src/sugg.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl<'a> Sugg<'a> {
147147
| hir::ExprKind::Path(..)
148148
| hir::ExprKind::Repeat(..)
149149
| hir::ExprKind::Ret(..)
150+
| hir::ExprKind::Become(..)
150151
| hir::ExprKind::Struct(..)
151152
| hir::ExprKind::Tup(..)
152153
| hir::ExprKind::Err(_) => Sugg::NonParen(get_snippet(expr.span)),
@@ -211,6 +212,7 @@ impl<'a> Sugg<'a> {
211212
| ast::ExprKind::Path(..)
212213
| ast::ExprKind::Repeat(..)
213214
| ast::ExprKind::Ret(..)
215+
| ast::ExprKind::Become(..)
214216
| ast::ExprKind::Yeet(..)
215217
| ast::ExprKind::FormatArgs(..)
216218
| ast::ExprKind::Struct(..)

src/tools/clippy/clippy_utils/src/visitors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ pub fn for_each_unconsumed_temporary<'tcx, B>(
651651
// Either drops temporaries, jumps out of the current expression, or has no sub expression.
652652
ExprKind::DropTemps(_)
653653
| ExprKind::Ret(_)
654+
| ExprKind::Become(_)
654655
| ExprKind::Break(..)
655656
| ExprKind::Yield(..)
656657
| ExprKind::Block(..)

0 commit comments

Comments
 (0)