Skip to content

Commit d3492a0

Browse files
committed
author: check block.expr: None
1 parent afe5962 commit d3492a0

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

clippy_lints/src/utils/author.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
554554
self.current = self.next("trailing_expr");
555555
println!(" if let Some({}) = &{}.expr;", self.current, block_name);
556556
self.visit_expr(expr);
557+
} else {
558+
println!(" if {}.expr.is_none();", block_name);
557559
}
558560
}
559561

tests/ui/author/blocks.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if_chain! {
1111
if let ExprKind::Unary(UnOp::Neg, ref inner) = e.kind;
1212
if let ExprKind::Path(ref path) = inner.kind;
1313
if match_qpath(path, &["x"]);
14+
if block.expr.is_none();
1415
then {
1516
// report your lint here
1617
}

tests/ui/author/for_loop.stdout

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ if_chain! {
5454
if match_qpath(path9, &["y"]);
5555
if let PatKind::Binding(BindingAnnotation::Unannotated, _, name2, None) = local2.pat.kind;
5656
if name2.as_str() == "z";
57+
if block.expr.is_none();
58+
if body.expr.is_none();
5759
if let PatKind::Binding(BindingAnnotation::Mutable, _, name3, None) = arms[0].pat.kind;
5860
if name3.as_str() == "iter";
5961
then {

tests/ui/author/if.stdout

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if_chain! {
1111
if let LitKind::Int(2, _) = lit.node;
1212
if let ExprKind::Lit(ref lit1) = right.kind;
1313
if let LitKind::Int(2, _) = lit1.node;
14+
if block.expr.is_none();
1415
if let ExprKind::Lit(ref lit2) = cond.kind;
1516
if let LitKind::Bool(true) = lit2.node;
1617
if let ExprKind::Block(ref block1) = then.kind;
@@ -22,6 +23,7 @@ if_chain! {
2223
if let LitKind::Int(1, _) = lit3.node;
2324
if let ExprKind::Lit(ref lit4) = right1.kind;
2425
if let LitKind::Int(1, _) = lit4.node;
26+
if block1.expr.is_none();
2527
if let PatKind::Wild = local.pat.kind;
2628
then {
2729
// report your lint here

0 commit comments

Comments
 (0)