mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
fixed array bounds checking
This commit is contained in:
parent
a57f21945b
commit
97e9299a10
1 changed files with 6 additions and 1 deletions
|
@ -38,11 +38,16 @@ impl LateLintPass for OkIfLetPass {
|
||||||
let MatchSource::IfLetDesugar { .. } = *source, //test if it is an If Let
|
let MatchSource::IfLetDesugar { .. } = *source, //test if it is an If Let
|
||||||
let ExprMethodCall(_, _, ref result_types) = op.node, //check is expr.ok() has type Result<T,E>.ok()
|
let ExprMethodCall(_, _, ref result_types) = op.node, //check is expr.ok() has type Result<T,E>.ok()
|
||||||
let PatKind::TupleStruct(ref x, ref y, _) = body[0].pats[0].node, //get operation
|
let PatKind::TupleStruct(ref x, ref y, _) = body[0].pats[0].node, //get operation
|
||||||
let Some(some_expr_string) = snippet_opt(cx, y[0].span),
|
|
||||||
let Some(_) = method_chain_args(op, &["ok"]) //test to see if using ok() methoduse std::marker::Sized;
|
let Some(_) = method_chain_args(op, &["ok"]) //test to see if using ok() methoduse std::marker::Sized;
|
||||||
|
|
||||||
], {
|
], {
|
||||||
let is_result_type = match_type(cx, cx.tcx.expr_ty(&result_types[0]), &paths::RESULT);
|
let is_result_type = match_type(cx, cx.tcx.expr_ty(&result_types[0]), &paths::RESULT);
|
||||||
|
let mut some_expr_string = String::from("");
|
||||||
|
if y.len() > 0 {
|
||||||
|
if let Some(x) = snippet_opt(cx, y[0].span) {
|
||||||
|
some_expr_string = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
if print::path_to_string(x) == "Some" && is_result_type {
|
if print::path_to_string(x) == "Some" && is_result_type {
|
||||||
span_help_and_lint(cx, IF_LET_SOME_RESULT, expr.span,
|
span_help_and_lint(cx, IF_LET_SOME_RESULT, expr.span,
|
||||||
"Matching on `Some` with `ok()` is redundant",
|
"Matching on `Some` with `ok()` is redundant",
|
||||||
|
|
Loading…
Add table
Reference in a new issue