mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Merge pull request #2392 from theotherphil/bugfix
Fix unnecessary_fold bug
This commit is contained in:
commit
ca1439d4a7
3 changed files with 9 additions and 6 deletions
|
@ -12,8 +12,8 @@ use syntax::ast;
|
||||||
use syntax::codemap::{Span, BytePos};
|
use syntax::codemap::{Span, BytePos};
|
||||||
use utils::{get_arg_name, get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, is_self, is_self_ty,
|
use utils::{get_arg_name, get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, is_self, is_self_ty,
|
||||||
iter_input_pats, last_path_segment, match_def_path, match_path, match_qpath, match_trait_method,
|
iter_input_pats, last_path_segment, match_def_path, match_path, match_qpath, match_trait_method,
|
||||||
match_type, method_chain_args, return_ty, remove_blocks, same_tys, single_segment_path, snippet, span_lint,
|
match_type, method_chain_args, match_var, return_ty, remove_blocks, same_tys, single_segment_path, snippet,
|
||||||
span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
|
span_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
|
||||||
use utils::paths;
|
use utils::paths;
|
||||||
use utils::sugg;
|
use utils::sugg;
|
||||||
use utils::const_to_u64;
|
use utils::const_to_u64;
|
||||||
|
@ -1162,8 +1162,8 @@ fn lint_unnecessary_fold(cx: &LateContext, expr: &hir::Expr, fold_args: &[hir::E
|
||||||
if let Some(first_arg_ident) = get_arg_name(&closure_body.arguments[0].pat);
|
if let Some(first_arg_ident) = get_arg_name(&closure_body.arguments[0].pat);
|
||||||
if let Some(second_arg_ident) = get_arg_name(&closure_body.arguments[1].pat);
|
if let Some(second_arg_ident) = get_arg_name(&closure_body.arguments[1].pat);
|
||||||
|
|
||||||
if let hir::ExprPath(hir::QPath::Resolved(None, ref path)) = left_expr.node;
|
if match_var(&*left_expr, first_arg_ident);
|
||||||
if path.segments.len() == 1 && &path.segments[0].name == &first_arg_ident;
|
if replacement_has_args || match_var(&*right_expr, second_arg_ident);
|
||||||
|
|
||||||
then {
|
then {
|
||||||
// Span containing `.fold(...)`
|
// Span containing `.fold(...)`
|
||||||
|
|
|
@ -419,6 +419,9 @@ fn unnecessary_fold_should_ignore() {
|
||||||
let _ = (0..3).fold(true, |acc, x| x > 2 && acc);
|
let _ = (0..3).fold(true, |acc, x| x > 2 && acc);
|
||||||
let _ = (0..3).fold(0, |acc, x| x + acc);
|
let _ = (0..3).fold(0, |acc, x| x + acc);
|
||||||
let _ = (0..3).fold(1, |acc, x| x * acc);
|
let _ = (0..3).fold(1, |acc, x| x * acc);
|
||||||
|
|
||||||
|
let _ = [(0..2), (0..3)].iter().fold(0, |a, b| a + b.len());
|
||||||
|
let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(similar_names)]
|
#[allow(similar_names)]
|
||||||
|
|
|
@ -526,9 +526,9 @@ error: this `.fold` can be written more succinctly using another method
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
|
||||||
|
|
||||||
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
|
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
|
||||||
--> $DIR/methods.rs:427:13
|
--> $DIR/methods.rs:430:13
|
||||||
|
|
|
|
||||||
427 | let _ = opt.unwrap();
|
430 | let _ = opt.unwrap();
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D option-unwrap-used` implied by `-D warnings`
|
= note: `-D option-unwrap-used` implied by `-D warnings`
|
||||||
|
|
Loading…
Reference in a new issue