Skip to content

Commit 9fc717d

Browse files
committed
add test for macro-in-loop
1 parent eb6fb18 commit 9fc717d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

tests/ui/author/macro_in_loop.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(stmt_expr_attributes)]
2+
3+
fn main() {
4+
#[clippy::author]
5+
for i in 0..1 {
6+
println!("{}", i);
7+
}
8+
}

tests/ui/author/macro_in_loop.stdout

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
2+
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind
3+
&& name.as_str() == "i"
4+
&& let ExprKind::Struct(qpath, fields, None) = arg.kind
5+
&& matches!(qpath, QPath::LangItem(LangItem::Range, _))
6+
&& fields.len() == 2
7+
&& fields[0].ident.as_str() == "start"
8+
&& let ExprKind::Lit(ref lit) = fields[0].expr.kind
9+
&& let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
10+
&& fields[1].ident.as_str() == "end"
11+
&& let ExprKind::Lit(ref lit1) = fields[1].expr.kind
12+
&& let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node
13+
&& let ExprKind::Block(block, None) = body.kind
14+
&& block.stmts.len() == 1
15+
&& let StmtKind::Semi(e) = block.stmts[0].kind
16+
&& let ExprKind::Block(block1, None) = e.kind
17+
&& block1.stmts.len() == 1
18+
&& let StmtKind::Semi(e1) = block1.stmts[0].kind
19+
&& let ExprKind::Call(func, args) = e1.kind
20+
&& let ExprKind::Path(ref qpath1) = func.kind
21+
&& match_qpath(qpath1, &["$crate", "io", "_print"])
22+
&& args.len() == 1
23+
&& let ExprKind::Call(func1, args1) = args[0].kind
24+
&& let ExprKind::Path(ref qpath2) = func1.kind
25+
&& args1.len() == 2
26+
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = args1[0].kind
27+
&& let ExprKind::Array(elements) = inner.kind
28+
&& elements.len() == 2
29+
&& let ExprKind::Lit(ref lit2) = elements[0].kind
30+
&& let LitKind::Str(s, _) = lit2.node
31+
&& s.as_str() == ""
32+
&& let ExprKind::Lit(ref lit3) = elements[1].kind
33+
&& let LitKind::Str(s1, _) = lit3.node
34+
&& s1.as_str() == "\n"
35+
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner1) = args1[1].kind
36+
&& let ExprKind::Array(elements1) = inner1.kind
37+
&& elements1.len() == 1
38+
&& let ExprKind::Call(func2, args2) = elements1[0].kind
39+
&& let ExprKind::Path(ref qpath3) = func2.kind
40+
&& args2.len() == 1
41+
&& let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner2) = args2[0].kind
42+
&& let ExprKind::Path(ref qpath4) = inner2.kind
43+
&& match_qpath(qpath4, &["i"])
44+
&& block1.expr.is_none()
45+
&& block.expr.is_none()
46+
{
47+
// report your lint here
48+
}

0 commit comments

Comments
 (0)