add detection unused_io_amount of "or", "or_else" and "ok"
This commit is contained in:
parent
28dbcd85c8
commit
5625d58f9f
3 changed files with 84 additions and 7 deletions
|
|
@ -47,25 +47,35 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
|
|||
func.kind,
|
||||
hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryIntoResult, _))
|
||||
) {
|
||||
check_method_call(cx, &args[0], expr);
|
||||
check_map_error(cx, &args[0], expr);
|
||||
}
|
||||
} else {
|
||||
check_method_call(cx, res, expr);
|
||||
check_map_error(cx, res, expr);
|
||||
}
|
||||
},
|
||||
|
||||
hir::ExprKind::MethodCall(path, _, args, _) => match &*path.ident.as_str() {
|
||||
"expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => {
|
||||
check_method_call(cx, &args[0], expr);
|
||||
check_map_error(cx, &args[0], expr);
|
||||
},
|
||||
_ => (),
|
||||
},
|
||||
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) {
|
||||
let mut call = call;
|
||||
while let hir::ExprKind::MethodCall(ref path, _, ref args, _) = call.kind {
|
||||
if matches!(&*path.ident.as_str(), "or" | "or_else" | "ok") {
|
||||
call = &args[0];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
check_method_call(cx, call, expr);
|
||||
}
|
||||
|
||||
fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) {
|
||||
if let hir::ExprKind::MethodCall(path, _, _, _) = call.kind {
|
||||
let symbol = &*path.ident.as_str();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue