Auto merge of #7132 - rust-lang:single_element_loop_iter, r=Manishearth
extend `single_element_loop` to match `.iter()` This extends `single_element_loop` to also match `[..].iter()` in the loop argument. Related to #7125, but not completely fixing it due to the lint only firing if the array expression contains a local variable. --- changelog: none
This commit is contained in:
commit
1bb3b12dfb
4 changed files with 33 additions and 2 deletions
|
|
@ -14,8 +14,14 @@ pub(super) fn check<'tcx>(
|
|||
body: &'tcx Expr<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
) {
|
||||
let arg_expr = match arg.kind {
|
||||
ExprKind::AddrOf(BorrowKind::Ref, _, ref_arg) => ref_arg,
|
||||
ExprKind::MethodCall(method, _, args, _) if args.len() == 1 && method.ident.name == rustc_span::sym::iter => {
|
||||
&args[0]
|
||||
},
|
||||
_ => return,
|
||||
};
|
||||
if_chain! {
|
||||
if let ExprKind::AddrOf(BorrowKind::Ref, _, arg_expr) = arg.kind;
|
||||
if let PatKind::Binding(.., target, _) = pat.kind;
|
||||
if let ExprKind::Array([arg_expression]) = arg_expr.kind;
|
||||
if let ExprKind::Path(ref list_item) = arg_expression.kind;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue