Auto merge of #9595 - Alexendoo:author-let-chains, r=Jarcho

Replace if_chain with let chains in `clippy::author` output

Should help nudge new contributors towards let chains

changelog: none
This commit is contained in:
bors 2022-10-07 02:52:47 +00:00
commit 65ae6666c8
10 changed files with 387 additions and 420 deletions

View File

@ -12,6 +12,7 @@ use rustc_hir::{
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::{Ident, Symbol}; use rustc_span::symbol::{Ident, Symbol};
use std::cell::Cell;
use std::fmt::{Display, Formatter, Write as _}; use std::fmt::{Display, Formatter, Write as _};
declare_clippy_lint! { declare_clippy_lint! {
@ -37,15 +38,13 @@ declare_clippy_lint! {
/// ///
/// ```rust,ignore /// ```rust,ignore
/// // ./tests/ui/new_lint.stdout /// // ./tests/ui/new_lint.stdout
/// if_chain! { /// if ExprKind::If(ref cond, ref then, None) = item.kind
/// if let ExprKind::If(ref cond, ref then, None) = item.kind, /// && let ExprKind::Binary(BinOp::Eq, ref left, ref right) = cond.kind
/// if let ExprKind::Binary(BinOp::Eq, ref left, ref right) = cond.kind, /// && let ExprKind::Path(ref path) = left.kind
/// if let ExprKind::Path(ref path) = left.kind, /// && let ExprKind::Lit(ref lit) = right.kind
/// if let ExprKind::Lit(ref lit) = right.kind, /// && let LitKind::Int(42, _) = lit.node
/// if let LitKind::Int(42, _) = lit.node, /// {
/// then { /// // report your lint here
/// // report your lint here
/// }
/// } /// }
/// ``` /// ```
pub LINT_AUTHOR, pub LINT_AUTHOR,
@ -91,15 +90,16 @@ macro_rules! field {
}; };
} }
fn prelude() { /// Print a condition of a let chain, `chain!(self, "let Some(x) = y")` will print
println!("if_chain! {{"); /// `if let Some(x) = y` on the first call and ` && let Some(x) = y` thereafter
} macro_rules! chain {
($self:ident, $($t:tt)*) => {
fn done() { if $self.first.take() {
println!(" then {{"); println!("if {}", format_args!($($t)*));
println!(" // report your lint here"); } else {
println!(" }}"); println!(" && {}", format_args!($($t)*));
println!("}}"); }
}
} }
impl<'tcx> LateLintPass<'tcx> for Author { impl<'tcx> LateLintPass<'tcx> for Author {
@ -149,9 +149,10 @@ fn check_item(cx: &LateContext<'_>, hir_id: HirId) {
fn check_node(cx: &LateContext<'_>, hir_id: HirId, f: impl Fn(&PrintVisitor<'_, '_>)) { fn check_node(cx: &LateContext<'_>, hir_id: HirId, f: impl Fn(&PrintVisitor<'_, '_>)) {
if has_attr(cx, hir_id) { if has_attr(cx, hir_id) {
prelude();
f(&PrintVisitor::new(cx)); f(&PrintVisitor::new(cx));
done(); println!("{{");
println!(" // report your lint here");
println!("}}");
} }
} }
@ -195,7 +196,9 @@ struct PrintVisitor<'a, 'tcx> {
cx: &'a LateContext<'tcx>, cx: &'a LateContext<'tcx>,
/// Fields are the current index that needs to be appended to pattern /// Fields are the current index that needs to be appended to pattern
/// binding names /// binding names
ids: std::cell::Cell<FxHashMap<&'static str, u32>>, ids: Cell<FxHashMap<&'static str, u32>>,
/// Currently at the first condition in the if chain
first: Cell<bool>,
} }
#[allow(clippy::unused_self)] #[allow(clippy::unused_self)]
@ -203,7 +206,8 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn new(cx: &'a LateContext<'tcx>) -> Self { fn new(cx: &'a LateContext<'tcx>) -> Self {
Self { Self {
cx, cx,
ids: std::cell::Cell::default(), ids: Cell::default(),
first: Cell::new(true),
} }
} }
@ -226,10 +230,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn option<T: Copy>(&self, option: &Binding<Option<T>>, name: &'static str, f: impl Fn(&Binding<T>)) { fn option<T: Copy>(&self, option: &Binding<Option<T>>, name: &'static str, f: impl Fn(&Binding<T>)) {
match option.value { match option.value {
None => out!("if {option}.is_none();"), None => chain!(self, "{option}.is_none()"),
Some(value) => { Some(value) => {
let value = &self.bind(name, value); let value = &self.bind(name, value);
out!("if let Some({value}) = {option};"); chain!(self, "let Some({value}) = {option}");
f(value); f(value);
}, },
} }
@ -237,9 +241,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn slice<T>(&self, slice: &Binding<&[T]>, f: impl Fn(&Binding<&T>)) { fn slice<T>(&self, slice: &Binding<&[T]>, f: impl Fn(&Binding<&T>)) {
if slice.value.is_empty() { if slice.value.is_empty() {
out!("if {slice}.is_empty();"); chain!(self, "{slice}.is_empty()");
} else { } else {
out!("if {slice}.len() == {};", slice.value.len()); chain!(self, "{slice}.len() == {}", slice.value.len());
for (i, value) in slice.value.iter().enumerate() { for (i, value) in slice.value.iter().enumerate() {
let name = format!("{slice}[{i}]"); let name = format!("{slice}[{i}]");
f(&Binding { name, value }); f(&Binding { name, value });
@ -254,23 +258,23 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
} }
fn ident(&self, ident: &Binding<Ident>) { fn ident(&self, ident: &Binding<Ident>) {
out!("if {ident}.as_str() == {:?};", ident.value.as_str()); chain!(self, "{ident}.as_str() == {:?}", ident.value.as_str());
} }
fn symbol(&self, symbol: &Binding<Symbol>) { fn symbol(&self, symbol: &Binding<Symbol>) {
out!("if {symbol}.as_str() == {:?};", symbol.value.as_str()); chain!(self, "{symbol}.as_str() == {:?}", symbol.value.as_str());
} }
fn qpath(&self, qpath: &Binding<&QPath<'_>>) { fn qpath(&self, qpath: &Binding<&QPath<'_>>) {
if let QPath::LangItem(lang_item, ..) = *qpath.value { if let QPath::LangItem(lang_item, ..) = *qpath.value {
out!("if matches!({qpath}, QPath::LangItem(LangItem::{lang_item:?}, _));"); chain!(self, "matches!({qpath}, QPath::LangItem(LangItem::{lang_item:?}, _))");
} else { } else {
out!("if match_qpath({qpath}, &[{}]);", path_to_string(qpath.value)); chain!(self, "match_qpath({qpath}, &[{}])", path_to_string(qpath.value));
} }
} }
fn lit(&self, lit: &Binding<&Lit>) { fn lit(&self, lit: &Binding<&Lit>) {
let kind = |kind| out!("if let LitKind::{kind} = {lit}.node;"); let kind = |kind| chain!(self, "let LitKind::{kind} = {lit}.node");
macro_rules! kind { macro_rules! kind {
($($t:tt)*) => (kind(format_args!($($t)*))); ($($t:tt)*) => (kind(format_args!($($t)*)));
} }
@ -298,7 +302,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
LitKind::ByteStr(ref vec) => { LitKind::ByteStr(ref vec) => {
bind!(self, vec); bind!(self, vec);
kind!("ByteStr(ref {vec})"); kind!("ByteStr(ref {vec})");
out!("if let [{:?}] = **{vec};", vec.value); chain!(self, "let [{:?}] = **{vec}", vec.value);
}, },
LitKind::Str(s, _) => { LitKind::Str(s, _) => {
bind!(self, s); bind!(self, s);
@ -311,15 +315,15 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn arm(&self, arm: &Binding<&hir::Arm<'_>>) { fn arm(&self, arm: &Binding<&hir::Arm<'_>>) {
self.pat(field!(arm.pat)); self.pat(field!(arm.pat));
match arm.value.guard { match arm.value.guard {
None => out!("if {arm}.guard.is_none();"), None => chain!(self, "{arm}.guard.is_none()"),
Some(hir::Guard::If(expr)) => { Some(hir::Guard::If(expr)) => {
bind!(self, expr); bind!(self, expr);
out!("if let Some(Guard::If({expr})) = {arm}.guard;"); chain!(self, "let Some(Guard::If({expr})) = {arm}.guard");
self.expr(expr); self.expr(expr);
}, },
Some(hir::Guard::IfLet(let_expr)) => { Some(hir::Guard::IfLet(let_expr)) => {
bind!(self, let_expr); bind!(self, let_expr);
out!("if let Some(Guard::IfLet({let_expr}) = {arm}.guard;"); chain!(self, "let Some(Guard::IfLet({let_expr}) = {arm}.guard");
self.pat(field!(let_expr.pat)); self.pat(field!(let_expr.pat));
self.expr(field!(let_expr.init)); self.expr(field!(let_expr.init));
}, },
@ -331,9 +335,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn expr(&self, expr: &Binding<&hir::Expr<'_>>) { fn expr(&self, expr: &Binding<&hir::Expr<'_>>) {
if let Some(higher::While { condition, body }) = higher::While::hir(expr.value) { if let Some(higher::While { condition, body }) = higher::While::hir(expr.value) {
bind!(self, condition, body); bind!(self, condition, body);
out!( chain!(
"if let Some(higher::While {{ condition: {condition}, body: {body} }}) \ self,
= higher::While::hir({expr});" "let Some(higher::While {{ condition: {condition}, body: {body} }}) \
= higher::While::hir({expr})"
); );
self.expr(condition); self.expr(condition);
self.expr(body); self.expr(body);
@ -347,9 +352,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
}) = higher::WhileLet::hir(expr.value) }) = higher::WhileLet::hir(expr.value)
{ {
bind!(self, let_pat, let_expr, if_then); bind!(self, let_pat, let_expr, if_then);
out!( chain!(
"if let Some(higher::WhileLet {{ let_pat: {let_pat}, let_expr: {let_expr}, if_then: {if_then} }}) \ self,
= higher::WhileLet::hir({expr});" "let Some(higher::WhileLet {{ let_pat: {let_pat}, let_expr: {let_expr}, if_then: {if_then} }}) \
= higher::WhileLet::hir({expr})"
); );
self.pat(let_pat); self.pat(let_pat);
self.expr(let_expr); self.expr(let_expr);
@ -359,9 +365,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
if let Some(higher::ForLoop { pat, arg, body, .. }) = higher::ForLoop::hir(expr.value) { if let Some(higher::ForLoop { pat, arg, body, .. }) = higher::ForLoop::hir(expr.value) {
bind!(self, pat, arg, body); bind!(self, pat, arg, body);
out!( chain!(
"if let Some(higher::ForLoop {{ pat: {pat}, arg: {arg}, body: {body}, .. }}) \ self,
= higher::ForLoop::hir({expr});" "let Some(higher::ForLoop {{ pat: {pat}, arg: {arg}, body: {body}, .. }}) \
= higher::ForLoop::hir({expr})"
); );
self.pat(pat); self.pat(pat);
self.expr(arg); self.expr(arg);
@ -369,7 +376,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
return; return;
} }
let kind = |kind| out!("if let ExprKind::{kind} = {expr}.kind;"); let kind = |kind| chain!(self, "let ExprKind::{kind} = {expr}.kind");
macro_rules! kind { macro_rules! kind {
($($t:tt)*) => (kind(format_args!($($t)*))); ($($t:tt)*) => (kind(format_args!($($t)*)));
} }
@ -383,7 +390,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
// if it's a path // if it's a path
if let Some(TyKind::Path(ref qpath)) = let_expr.value.ty.as_ref().map(|ty| &ty.kind) { if let Some(TyKind::Path(ref qpath)) = let_expr.value.ty.as_ref().map(|ty| &ty.kind) {
bind!(self, qpath); bind!(self, qpath);
out!("if let TyKind::Path(ref {qpath}) = {let_expr}.ty.kind;"); chain!(self, "let TyKind::Path(ref {qpath}) = {let_expr}.ty.kind");
self.qpath(qpath); self.qpath(qpath);
} }
self.expr(field!(let_expr.init)); self.expr(field!(let_expr.init));
@ -419,7 +426,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
ExprKind::Binary(op, left, right) => { ExprKind::Binary(op, left, right) => {
bind!(self, op, left, right); bind!(self, op, left, right);
kind!("Binary({op}, {left}, {right})"); kind!("Binary({op}, {left}, {right})");
out!("if BinOpKind::{:?} == {op}.node;", op.value.node); chain!(self, "BinOpKind::{:?} == {op}.node", op.value.node);
self.expr(left); self.expr(left);
self.expr(right); self.expr(right);
}, },
@ -438,7 +445,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
kind!("Cast({expr}, {cast_ty})"); kind!("Cast({expr}, {cast_ty})");
if let TyKind::Path(ref qpath) = cast_ty.value.kind { if let TyKind::Path(ref qpath) = cast_ty.value.kind {
bind!(self, qpath); bind!(self, qpath);
out!("if let TyKind::Path(ref {qpath}) = {cast_ty}.kind;"); chain!(self, "let TyKind::Path(ref {qpath}) = {cast_ty}.kind");
self.qpath(qpath); self.qpath(qpath);
} }
self.expr(expr); self.expr(expr);
@ -485,7 +492,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
bind!(self, fn_decl, body_id); bind!(self, fn_decl, body_id);
kind!("Closure(CaptureBy::{capture_clause:?}, {fn_decl}, {body_id}, _, {movability})"); kind!("Closure(CaptureBy::{capture_clause:?}, {fn_decl}, {body_id}, _, {movability})");
out!("if let {ret_ty} = {fn_decl}.output;"); chain!(self, "let {ret_ty} = {fn_decl}.output");
self.body(body_id); self.body(body_id);
}, },
ExprKind::Yield(sub, source) => { ExprKind::Yield(sub, source) => {
@ -509,7 +516,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
ExprKind::AssignOp(op, target, value) => { ExprKind::AssignOp(op, target, value) => {
bind!(self, op, target, value); bind!(self, op, target, value);
kind!("AssignOp({op}, {target}, {value})"); kind!("AssignOp({op}, {target}, {value})");
out!("if BinOpKind::{:?} == {op}.node;", op.value.node); chain!(self, "BinOpKind::{:?} == {op}.node", op.value.node);
self.expr(target); self.expr(target);
self.expr(value); self.expr(value);
}, },
@ -573,10 +580,10 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
kind!("Repeat({value}, {length})"); kind!("Repeat({value}, {length})");
self.expr(value); self.expr(value);
match length.value { match length.value {
ArrayLen::Infer(..) => out!("if let ArrayLen::Infer(..) = length;"), ArrayLen::Infer(..) => chain!(self, "let ArrayLen::Infer(..) = length"),
ArrayLen::Body(anon_const) => { ArrayLen::Body(anon_const) => {
bind!(self, anon_const); bind!(self, anon_const);
out!("if let ArrayLen::Body({anon_const}) = {length};"); chain!(self, "let ArrayLen::Body({anon_const}) = {length}");
self.body(field!(anon_const.body)); self.body(field!(anon_const.body));
}, },
} }
@ -600,12 +607,12 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
fn body(&self, body_id: &Binding<hir::BodyId>) { fn body(&self, body_id: &Binding<hir::BodyId>) {
let expr = self.cx.tcx.hir().body(body_id.value).value; let expr = self.cx.tcx.hir().body(body_id.value).value;
bind!(self, expr); bind!(self, expr);
out!("let {expr} = &cx.tcx.hir().body({body_id}).value;"); chain!(self, "{expr} = &cx.tcx.hir().body({body_id}).value");
self.expr(expr); self.expr(expr);
} }
fn pat(&self, pat: &Binding<&hir::Pat<'_>>) { fn pat(&self, pat: &Binding<&hir::Pat<'_>>) {
let kind = |kind| out!("if let PatKind::{kind} = {pat}.kind;"); let kind = |kind| chain!(self, "let PatKind::{kind} = {pat}.kind");
macro_rules! kind { macro_rules! kind {
($($t:tt)*) => (kind(format_args!($($t)*))); ($($t:tt)*) => (kind(format_args!($($t)*)));
} }
@ -688,7 +695,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
} }
fn stmt(&self, stmt: &Binding<&hir::Stmt<'_>>) { fn stmt(&self, stmt: &Binding<&hir::Stmt<'_>>) {
let kind = |kind| out!("if let StmtKind::{kind} = {stmt}.kind;"); let kind = |kind| chain!(self, "let StmtKind::{kind} = {stmt}.kind");
macro_rules! kind { macro_rules! kind {
($($t:tt)*) => (kind(format_args!($($t)*))); ($($t:tt)*) => (kind(format_args!($($t)*)));
} }

View File

@ -1,14 +1,12 @@
if_chain! { if let StmtKind::Local(local) = stmt.kind
if let StmtKind::Local(local) = stmt.kind; && let Some(init) = local.init
if let Some(init) = local.init; && let ExprKind::Cast(expr, cast_ty) = init.kind
if let ExprKind::Cast(expr, cast_ty) = init.kind; && let TyKind::Path(ref qpath) = cast_ty.kind
if let TyKind::Path(ref qpath) = cast_ty.kind; && match_qpath(qpath, &["char"])
if match_qpath(qpath, &["char"]); && let ExprKind::Lit(ref lit) = expr.kind
if let ExprKind::Lit(ref lit) = expr.kind; && let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node
if let LitKind::Int(69, LitIntType::Unsuffixed) = lit.node; && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind
if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind; && name.as_str() == "x"
if name.as_str() == "x"; {
then { // report your lint here
// report your lint here
}
} }

View File

@ -1,64 +1,58 @@
if_chain! { if let ExprKind::Block(block, None) = expr.kind
if let ExprKind::Block(block, None) = expr.kind; && block.stmts.len() == 3
if block.stmts.len() == 3; && let StmtKind::Local(local) = block.stmts[0].kind
if let StmtKind::Local(local) = block.stmts[0].kind; && let Some(init) = local.init
if let Some(init) = local.init; && let ExprKind::Lit(ref lit) = init.kind
if let ExprKind::Lit(ref lit) = init.kind; && let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node
if let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node; && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind
if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind; && name.as_str() == "x"
if name.as_str() == "x"; && let StmtKind::Local(local1) = block.stmts[1].kind
if let StmtKind::Local(local1) = block.stmts[1].kind; && let Some(init1) = local1.init
if let Some(init1) = local1.init; && let ExprKind::Lit(ref lit1) = init1.kind
if let ExprKind::Lit(ref lit1) = init1.kind; && let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node
if let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node; && let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local1.pat.kind
if let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local1.pat.kind; && name1.as_str() == "_t"
if name1.as_str() == "_t"; && let StmtKind::Semi(e) = block.stmts[2].kind
if let StmtKind::Semi(e) = block.stmts[2].kind; && let ExprKind::Unary(UnOp::Neg, inner) = e.kind
if let ExprKind::Unary(UnOp::Neg, inner) = e.kind; && let ExprKind::Path(ref qpath) = inner.kind
if let ExprKind::Path(ref qpath) = inner.kind; && match_qpath(qpath, &["x"])
if match_qpath(qpath, &["x"]); && block.expr.is_none()
if block.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let ExprKind::Block(block, None) = expr.kind
if let ExprKind::Block(block, None) = expr.kind; && block.stmts.len() == 1
if block.stmts.len() == 1; && let StmtKind::Local(local) = block.stmts[0].kind
if let StmtKind::Local(local) = block.stmts[0].kind; && let Some(init) = local.init
if let Some(init) = local.init; && let ExprKind::Call(func, args) = init.kind
if let ExprKind::Call(func, args) = init.kind; && let ExprKind::Path(ref qpath) = func.kind
if let ExprKind::Path(ref qpath) = func.kind; && match_qpath(qpath, &["String", "new"])
if match_qpath(qpath, &["String", "new"]); && args.is_empty()
if args.is_empty(); && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind
if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind; && name.as_str() == "expr"
if name.as_str() == "expr"; && let Some(trailing_expr) = block.expr
if let Some(trailing_expr) = block.expr; && let ExprKind::Call(func1, args1) = trailing_expr.kind
if let ExprKind::Call(func1, args1) = trailing_expr.kind; && let ExprKind::Path(ref qpath1) = func1.kind
if let ExprKind::Path(ref qpath1) = func1.kind; && match_qpath(qpath1, &["drop"])
if match_qpath(qpath1, &["drop"]); && args1.len() == 1
if args1.len() == 1; && let ExprKind::Path(ref qpath2) = args1[0].kind
if let ExprKind::Path(ref qpath2) = args1[0].kind; && match_qpath(qpath2, &["expr"])
if match_qpath(qpath2, &["expr"]); {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kind
if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kind; && let FnRetTy::DefaultReturn(_) = fn_decl.output
if let FnRetTy::DefaultReturn(_) = fn_decl.output; && expr1 = &cx.tcx.hir().body(body_id).value
let expr1 = &cx.tcx.hir().body(body_id).value; && let ExprKind::Call(func, args) = expr1.kind
if let ExprKind::Call(func, args) = expr1.kind; && let ExprKind::Path(ref qpath) = func.kind
if let ExprKind::Path(ref qpath) = func.kind; && matches!(qpath, QPath::LangItem(LangItem::FromGenerator, _))
if matches!(qpath, QPath::LangItem(LangItem::FromGenerator, _)); && args.len() == 1
if args.len() == 1; && let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind
if let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind; && let FnRetTy::DefaultReturn(_) = fn_decl1.output
if let FnRetTy::DefaultReturn(_) = fn_decl1.output; && expr2 = &cx.tcx.hir().body(body_id1).value
let expr2 = &cx.tcx.hir().body(body_id1).value; && let ExprKind::Block(block, None) = expr2.kind
if let ExprKind::Block(block, None) = expr2.kind; && block.stmts.is_empty()
if block.stmts.is_empty(); && block.expr.is_none()
if block.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }

View File

@ -1,16 +1,14 @@
if_chain! { if let StmtKind::Local(local) = stmt.kind
if let StmtKind::Local(local) = stmt.kind; && let Some(init) = local.init
if let Some(init) = local.init; && let ExprKind::Call(func, args) = init.kind
if let ExprKind::Call(func, args) = init.kind; && let ExprKind::Path(ref qpath) = func.kind
if let ExprKind::Path(ref qpath) = func.kind; && match_qpath(qpath, &["{{root}}", "std", "cmp", "min"])
if match_qpath(qpath, &["{{root}}", "std", "cmp", "min"]); && args.len() == 2
if args.len() == 2; && let ExprKind::Lit(ref lit) = args[0].kind
if let ExprKind::Lit(ref lit) = args[0].kind; && let LitKind::Int(3, LitIntType::Unsuffixed) = lit.node
if let LitKind::Int(3, LitIntType::Unsuffixed) = lit.node; && let ExprKind::Lit(ref lit1) = args[1].kind
if let ExprKind::Lit(ref lit1) = args[1].kind; && let LitKind::Int(4, LitIntType::Unsuffixed) = lit1.node
if let LitKind::Int(4, LitIntType::Unsuffixed) = lit1.node; && let PatKind::Wild = local.pat.kind
if let PatKind::Wild = local.pat.kind; {
then { // report your lint here
// report your lint here
}
} }

View File

@ -1,50 +1,46 @@
if_chain! { if let StmtKind::Local(local) = stmt.kind
if let StmtKind::Local(local) = stmt.kind; && let Some(init) = local.init
if let Some(init) = local.init; && let ExprKind::If(cond, then, Some(else_expr)) = init.kind
if let ExprKind::If(cond, then, Some(else_expr)) = init.kind; && let ExprKind::DropTemps(expr) = cond.kind
if let ExprKind::DropTemps(expr) = cond.kind; && let ExprKind::Lit(ref lit) = expr.kind
if let ExprKind::Lit(ref lit) = expr.kind; && let LitKind::Bool(true) = lit.node
if let LitKind::Bool(true) = lit.node; && let ExprKind::Block(block, None) = then.kind
if let ExprKind::Block(block, None) = then.kind; && block.stmts.len() == 1
if block.stmts.len() == 1; && let StmtKind::Semi(e) = block.stmts[0].kind
if let StmtKind::Semi(e) = block.stmts[0].kind; && let ExprKind::Binary(op, left, right) = e.kind
if let ExprKind::Binary(op, left, right) = e.kind; && BinOpKind::Eq == op.node
if BinOpKind::Eq == op.node; && let ExprKind::Lit(ref lit1) = left.kind
if let ExprKind::Lit(ref lit1) = left.kind; && let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node; && let ExprKind::Lit(ref lit2) = right.kind
if let ExprKind::Lit(ref lit2) = right.kind; && let LitKind::Int(1, LitIntType::Unsuffixed) = lit2.node
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit2.node; && block.expr.is_none()
if block.expr.is_none(); && let ExprKind::Block(block1, None) = else_expr.kind
if let ExprKind::Block(block1, None) = else_expr.kind; && block1.stmts.len() == 1
if block1.stmts.len() == 1; && let StmtKind::Semi(e1) = block1.stmts[0].kind
if let StmtKind::Semi(e1) = block1.stmts[0].kind; && let ExprKind::Binary(op1, left1, right1) = e1.kind
if let ExprKind::Binary(op1, left1, right1) = e1.kind; && BinOpKind::Eq == op1.node
if BinOpKind::Eq == op1.node; && let ExprKind::Lit(ref lit3) = left1.kind
if let ExprKind::Lit(ref lit3) = left1.kind; && let LitKind::Int(2, LitIntType::Unsuffixed) = lit3.node
if let LitKind::Int(2, LitIntType::Unsuffixed) = lit3.node; && let ExprKind::Lit(ref lit4) = right1.kind
if let ExprKind::Lit(ref lit4) = right1.kind; && let LitKind::Int(2, LitIntType::Unsuffixed) = lit4.node
if let LitKind::Int(2, LitIntType::Unsuffixed) = lit4.node; && block1.expr.is_none()
if block1.expr.is_none(); && let PatKind::Wild = local.pat.kind
if let PatKind::Wild = local.pat.kind; {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind
if let ExprKind::If(cond, then, Some(else_expr)) = expr.kind; && let ExprKind::Let(let_expr) = cond.kind
if let ExprKind::Let(let_expr) = cond.kind; && let PatKind::Lit(lit_expr) = let_expr.pat.kind
if let PatKind::Lit(lit_expr) = let_expr.pat.kind; && let ExprKind::Lit(ref lit) = lit_expr.kind
if let ExprKind::Lit(ref lit) = lit_expr.kind; && let LitKind::Bool(true) = lit.node
if let LitKind::Bool(true) = lit.node; && let ExprKind::Path(ref qpath) = let_expr.init.kind
if let ExprKind::Path(ref qpath) = let_expr.init.kind; && match_qpath(qpath, &["a"])
if match_qpath(qpath, &["a"]); && let ExprKind::Block(block, None) = then.kind
if let ExprKind::Block(block, None) = then.kind; && block.stmts.is_empty()
if block.stmts.is_empty(); && block.expr.is_none()
if block.expr.is_none(); && let ExprKind::Block(block1, None) = else_expr.kind
if let ExprKind::Block(block1, None) = else_expr.kind; && block1.stmts.is_empty()
if block1.stmts.is_empty(); && block1.expr.is_none()
if block1.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }

View File

@ -1,14 +1,12 @@
if_chain! { if let StmtKind::Local(local) = stmt.kind
if let StmtKind::Local(local) = stmt.kind; && let Some(init) = local.init
if let Some(init) = local.init; && let ExprKind::Call(func, args) = init.kind
if let ExprKind::Call(func, args) = init.kind; && let ExprKind::Path(ref qpath) = func.kind
if let ExprKind::Path(ref qpath) = func.kind; && match_qpath(qpath, &["std", "mem", "transmute"])
if match_qpath(qpath, &["std", "mem", "transmute"]); && args.len() == 1
if args.len() == 1; && let ExprKind::Path(ref qpath1) = args[0].kind
if let ExprKind::Path(ref qpath1) = args[0].kind; && match_qpath(qpath1, &["ZPTR"])
if match_qpath(qpath1, &["ZPTR"]); && let PatKind::Wild = local.pat.kind
if let PatKind::Wild = local.pat.kind; {
then { // report your lint here
// report your lint here
}
} }

View File

@ -1,113 +1,101 @@
if_chain! { if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr); && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind
if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = pat.kind; && name.as_str() == "y"
if name.as_str() == "y"; && let ExprKind::Struct(qpath, fields, None) = arg.kind
if let ExprKind::Struct(qpath, fields, None) = arg.kind; && matches!(qpath, QPath::LangItem(LangItem::Range, _))
if matches!(qpath, QPath::LangItem(LangItem::Range, _)); && fields.len() == 2
if fields.len() == 2; && fields[0].ident.as_str() == "start"
if fields[0].ident.as_str() == "start"; && let ExprKind::Lit(ref lit) = fields[0].expr.kind
if let ExprKind::Lit(ref lit) = fields[0].expr.kind; && let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node; && fields[1].ident.as_str() == "end"
if fields[1].ident.as_str() == "end"; && let ExprKind::Lit(ref lit1) = fields[1].expr.kind
if let ExprKind::Lit(ref lit1) = fields[1].expr.kind; && let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node
if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node; && let ExprKind::Block(block, None) = body.kind
if let ExprKind::Block(block, None) = body.kind; && block.stmts.len() == 1
if block.stmts.len() == 1; && let StmtKind::Local(local) = block.stmts[0].kind
if let StmtKind::Local(local) = block.stmts[0].kind; && let Some(init) = local.init
if let Some(init) = local.init; && let ExprKind::Path(ref qpath1) = init.kind
if let ExprKind::Path(ref qpath1) = init.kind; && match_qpath(qpath1, &["y"])
if match_qpath(qpath1, &["y"]); && let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind
if let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind; && name1.as_str() == "z"
if name1.as_str() == "z"; && block.expr.is_none()
if block.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr); && let PatKind::Wild = pat.kind
if let PatKind::Wild = pat.kind; && let ExprKind::Struct(qpath, fields, None) = arg.kind
if let ExprKind::Struct(qpath, fields, None) = arg.kind; && matches!(qpath, QPath::LangItem(LangItem::Range, _))
if matches!(qpath, QPath::LangItem(LangItem::Range, _)); && fields.len() == 2
if fields.len() == 2; && fields[0].ident.as_str() == "start"
if fields[0].ident.as_str() == "start"; && let ExprKind::Lit(ref lit) = fields[0].expr.kind
if let ExprKind::Lit(ref lit) = fields[0].expr.kind; && let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node; && fields[1].ident.as_str() == "end"
if fields[1].ident.as_str() == "end"; && let ExprKind::Lit(ref lit1) = fields[1].expr.kind
if let ExprKind::Lit(ref lit1) = fields[1].expr.kind; && let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node
if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node; && let ExprKind::Block(block, None) = body.kind
if let ExprKind::Block(block, None) = body.kind; && block.stmts.len() == 1
if block.stmts.len() == 1; && let StmtKind::Semi(e) = block.stmts[0].kind
if let StmtKind::Semi(e) = block.stmts[0].kind; && let ExprKind::Break(destination, None) = e.kind
if let ExprKind::Break(destination, None) = e.kind; && destination.label.is_none()
if destination.label.is_none(); && block.expr.is_none()
if block.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr)
if let Some(higher::ForLoop { pat: pat, arg: arg, body: body, .. }) = higher::ForLoop::hir(expr); && let PatKind::Wild = pat.kind
if let PatKind::Wild = pat.kind; && let ExprKind::Struct(qpath, fields, None) = arg.kind
if let ExprKind::Struct(qpath, fields, None) = arg.kind; && matches!(qpath, QPath::LangItem(LangItem::Range, _))
if matches!(qpath, QPath::LangItem(LangItem::Range, _)); && fields.len() == 2
if fields.len() == 2; && fields[0].ident.as_str() == "start"
if fields[0].ident.as_str() == "start"; && let ExprKind::Lit(ref lit) = fields[0].expr.kind
if let ExprKind::Lit(ref lit) = fields[0].expr.kind; && let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit.node; && fields[1].ident.as_str() == "end"
if fields[1].ident.as_str() == "end"; && let ExprKind::Lit(ref lit1) = fields[1].expr.kind
if let ExprKind::Lit(ref lit1) = fields[1].expr.kind; && let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node
if let LitKind::Int(10, LitIntType::Unsuffixed) = lit1.node; && let ExprKind::Block(block, None) = body.kind
if let ExprKind::Block(block, None) = body.kind; && block.stmts.len() == 1
if block.stmts.len() == 1; && let StmtKind::Semi(e) = block.stmts[0].kind
if let StmtKind::Semi(e) = block.stmts[0].kind; && let ExprKind::Break(destination, None) = e.kind
if let ExprKind::Break(destination, None) = e.kind; && let Some(label) = destination.label
if let Some(label) = destination.label; && label.ident.as_str() == "'label"
if label.ident.as_str() == "'label"; && block.expr.is_none()
if block.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr)
if let Some(higher::While { condition: condition, body: body }) = higher::While::hir(expr); && let ExprKind::Path(ref qpath) = condition.kind
if let ExprKind::Path(ref qpath) = condition.kind; && match_qpath(qpath, &["a"])
if match_qpath(qpath, &["a"]); && let ExprKind::Block(block, None) = body.kind
if let ExprKind::Block(block, None) = body.kind; && block.stmts.len() == 1
if block.stmts.len() == 1; && let StmtKind::Semi(e) = block.stmts[0].kind
if let StmtKind::Semi(e) = block.stmts[0].kind; && let ExprKind::Break(destination, None) = e.kind
if let ExprKind::Break(destination, None) = e.kind; && destination.label.is_none()
if destination.label.is_none(); && block.expr.is_none()
if block.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr)
if let Some(higher::WhileLet { let_pat: let_pat, let_expr: let_expr, if_then: if_then }) = higher::WhileLet::hir(expr); && let PatKind::Lit(lit_expr) = let_pat.kind
if let PatKind::Lit(lit_expr) = let_pat.kind; && let ExprKind::Lit(ref lit) = lit_expr.kind
if let ExprKind::Lit(ref lit) = lit_expr.kind; && let LitKind::Bool(true) = lit.node
if let LitKind::Bool(true) = lit.node; && let ExprKind::Path(ref qpath) = let_expr.kind
if let ExprKind::Path(ref qpath) = let_expr.kind; && match_qpath(qpath, &["a"])
if match_qpath(qpath, &["a"]); && let ExprKind::Block(block, None) = if_then.kind
if let ExprKind::Block(block, None) = if_then.kind; && block.stmts.len() == 1
if block.stmts.len() == 1; && let StmtKind::Semi(e) = block.stmts[0].kind
if let StmtKind::Semi(e) = block.stmts[0].kind; && let ExprKind::Break(destination, None) = e.kind
if let ExprKind::Break(destination, None) = e.kind; && destination.label.is_none()
if destination.label.is_none(); && block.expr.is_none()
if block.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let ExprKind::Loop(body, None, LoopSource::Loop, _) = expr.kind
if let ExprKind::Loop(body, None, LoopSource::Loop, _) = expr.kind; && body.stmts.len() == 1
if body.stmts.len() == 1; && let StmtKind::Semi(e) = body.stmts[0].kind
if let StmtKind::Semi(e) = body.stmts[0].kind; && let ExprKind::Break(destination, None) = e.kind
if let ExprKind::Break(destination, None) = e.kind; && destination.label.is_none()
if destination.label.is_none(); && body.expr.is_none()
if body.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }

View File

@ -1,38 +1,36 @@
if_chain! { if let StmtKind::Local(local) = stmt.kind
if let StmtKind::Local(local) = stmt.kind; && let Some(init) = local.init
if let Some(init) = local.init; && let ExprKind::Match(scrutinee, arms, MatchSource::Normal) = init.kind
if let ExprKind::Match(scrutinee, arms, MatchSource::Normal) = init.kind; && let ExprKind::Lit(ref lit) = scrutinee.kind
if let ExprKind::Lit(ref lit) = scrutinee.kind; && let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node
if let LitKind::Int(42, LitIntType::Unsuffixed) = lit.node; && arms.len() == 3
if arms.len() == 3; && let PatKind::Lit(lit_expr) = arms[0].pat.kind
if let PatKind::Lit(lit_expr) = arms[0].pat.kind; && let ExprKind::Lit(ref lit1) = lit_expr.kind
if let ExprKind::Lit(ref lit1) = lit_expr.kind; && let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node
if let LitKind::Int(16, LitIntType::Unsuffixed) = lit1.node; && arms[0].guard.is_none()
if arms[0].guard.is_none(); && let ExprKind::Lit(ref lit2) = arms[0].body.kind
if let ExprKind::Lit(ref lit2) = arms[0].body.kind; && let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node
if let LitKind::Int(5, LitIntType::Unsuffixed) = lit2.node; && let PatKind::Lit(lit_expr1) = arms[1].pat.kind
if let PatKind::Lit(lit_expr1) = arms[1].pat.kind; && let ExprKind::Lit(ref lit3) = lit_expr1.kind
if let ExprKind::Lit(ref lit3) = lit_expr1.kind; && let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node
if let LitKind::Int(17, LitIntType::Unsuffixed) = lit3.node; && arms[1].guard.is_none()
if arms[1].guard.is_none(); && let ExprKind::Block(block, None) = arms[1].body.kind
if let ExprKind::Block(block, None) = arms[1].body.kind; && block.stmts.len() == 1
if block.stmts.len() == 1; && let StmtKind::Local(local1) = block.stmts[0].kind
if let StmtKind::Local(local1) = block.stmts[0].kind; && let Some(init1) = local1.init
if let Some(init1) = local1.init; && let ExprKind::Lit(ref lit4) = init1.kind
if let ExprKind::Lit(ref lit4) = init1.kind; && let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node
if let LitKind::Int(3, LitIntType::Unsuffixed) = lit4.node; && let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local1.pat.kind
if let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local1.pat.kind; && name.as_str() == "x"
if name.as_str() == "x"; && let Some(trailing_expr) = block.expr
if let Some(trailing_expr) = block.expr; && let ExprKind::Path(ref qpath) = trailing_expr.kind
if let ExprKind::Path(ref qpath) = trailing_expr.kind; && match_qpath(qpath, &["x"])
if match_qpath(qpath, &["x"]); && let PatKind::Wild = arms[2].pat.kind
if let PatKind::Wild = arms[2].pat.kind; && arms[2].guard.is_none()
if arms[2].guard.is_none(); && let ExprKind::Lit(ref lit5) = arms[2].body.kind
if let ExprKind::Lit(ref lit5) = arms[2].body.kind; && let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit5.node; && let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind
if let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local.pat.kind; && name1.as_str() == "a"
if name1.as_str() == "a"; {
then { // report your lint here
// report your lint here
}
} }

View File

@ -1,12 +1,10 @@
if_chain! { if let ExprKind::Repeat(value, length) = expr.kind
if let ExprKind::Repeat(value, length) = expr.kind; && let ExprKind::Lit(ref lit) = value.kind
if let ExprKind::Lit(ref lit) = value.kind; && let LitKind::Int(1, LitIntType::Unsigned(UintTy::U8)) = lit.node
if let LitKind::Int(1, LitIntType::Unsigned(UintTy::U8)) = lit.node; && let ArrayLen::Body(anon_const) = length
if let ArrayLen::Body(anon_const) = length; && expr1 = &cx.tcx.hir().body(anon_const.body).value
let expr1 = &cx.tcx.hir().body(anon_const.body).value; && let ExprKind::Lit(ref lit1) = expr1.kind
if let ExprKind::Lit(ref lit1) = expr1.kind; && let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node
if let LitKind::Int(5, LitIntType::Unsuffixed) = lit1.node; {
then { // report your lint here
// report your lint here
}
} }

View File

@ -1,64 +1,56 @@
if_chain! { if let ExprKind::Struct(qpath, fields, None) = expr.kind
if let ExprKind::Struct(qpath, fields, None) = expr.kind; && match_qpath(qpath, &["Test"])
if match_qpath(qpath, &["Test"]); && fields.len() == 1
if fields.len() == 1; && fields[0].ident.as_str() == "field"
if fields[0].ident.as_str() == "field"; && let ExprKind::If(cond, then, Some(else_expr)) = fields[0].expr.kind
if let ExprKind::If(cond, then, Some(else_expr)) = fields[0].expr.kind; && let ExprKind::DropTemps(expr1) = cond.kind
if let ExprKind::DropTemps(expr1) = cond.kind; && let ExprKind::Lit(ref lit) = expr1.kind
if let ExprKind::Lit(ref lit) = expr1.kind; && let LitKind::Bool(true) = lit.node
if let LitKind::Bool(true) = lit.node; && let ExprKind::Block(block, None) = then.kind
if let ExprKind::Block(block, None) = then.kind; && block.stmts.is_empty()
if block.stmts.is_empty(); && let Some(trailing_expr) = block.expr
if let Some(trailing_expr) = block.expr; && let ExprKind::Lit(ref lit1) = trailing_expr.kind
if let ExprKind::Lit(ref lit1) = trailing_expr.kind; && let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit1.node; && let ExprKind::Block(block1, None) = else_expr.kind
if let ExprKind::Block(block1, None) = else_expr.kind; && block1.stmts.is_empty()
if block1.stmts.is_empty(); && let Some(trailing_expr1) = block1.expr
if let Some(trailing_expr1) = block1.expr; && let ExprKind::Lit(ref lit2) = trailing_expr1.kind
if let ExprKind::Lit(ref lit2) = trailing_expr1.kind; && let LitKind::Int(0, LitIntType::Unsuffixed) = lit2.node
if let LitKind::Int(0, LitIntType::Unsuffixed) = lit2.node; {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind
if let PatKind::Struct(ref qpath, fields, false) = arm.pat.kind; && match_qpath(qpath, &["Test"])
if match_qpath(qpath, &["Test"]); && fields.len() == 1
if fields.len() == 1; && fields[0].ident.as_str() == "field"
if fields[0].ident.as_str() == "field"; && let PatKind::Lit(lit_expr) = fields[0].pat.kind
if let PatKind::Lit(lit_expr) = fields[0].pat.kind; && let ExprKind::Lit(ref lit) = lit_expr.kind
if let ExprKind::Lit(ref lit) = lit_expr.kind; && let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node; && arm.guard.is_none()
if arm.guard.is_none(); && let ExprKind::Block(block, None) = arm.body.kind
if let ExprKind::Block(block, None) = arm.body.kind; && block.stmts.is_empty()
if block.stmts.is_empty(); && block.expr.is_none()
if block.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind
if let PatKind::TupleStruct(ref qpath, fields, None) = arm.pat.kind; && match_qpath(qpath, &["TestTuple"])
if match_qpath(qpath, &["TestTuple"]); && fields.len() == 1
if fields.len() == 1; && let PatKind::Lit(lit_expr) = fields[0].kind
if let PatKind::Lit(lit_expr) = fields[0].kind; && let ExprKind::Lit(ref lit) = lit_expr.kind
if let ExprKind::Lit(ref lit) = lit_expr.kind; && let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node
if let LitKind::Int(1, LitIntType::Unsuffixed) = lit.node; && arm.guard.is_none()
if arm.guard.is_none(); && let ExprKind::Block(block, None) = arm.body.kind
if let ExprKind::Block(block, None) = arm.body.kind; && block.stmts.is_empty()
if block.stmts.is_empty(); && block.expr.is_none()
if block.expr.is_none(); {
then { // report your lint here
// report your lint here
}
} }
if_chain! { if let ExprKind::MethodCall(method_name, receiver, args, _) = expr.kind
if let ExprKind::MethodCall(method_name, receiver, args, _) = expr.kind; && method_name.ident.as_str() == "test"
if method_name.ident.as_str() == "test"; && let ExprKind::Path(ref qpath) = receiver.kind
if let ExprKind::Path(ref qpath) = receiver.kind; && match_qpath(qpath, &["test_method_call"])
if match_qpath(qpath, &["test_method_call"]); && args.is_empty()
if args.is_empty(); {
then { // report your lint here
// report your lint here
}
} }