|
1 | 1 | mod for_loop_arg;
|
| 2 | +mod for_loop_over_map_kv; |
2 | 3 | mod manual_flatten;
|
3 | 4 | mod utils;
|
4 | 5 |
|
@@ -863,7 +864,7 @@ fn check_for_loop<'tcx>(
|
863 | 864 | check_for_loop_explicit_counter(cx, pat, arg, body, expr);
|
864 | 865 | }
|
865 | 866 | for_loop_arg::check_for_loop_arg(cx, pat, arg, expr);
|
866 |
| - check_for_loop_over_map_kv(cx, pat, arg, body, expr); |
| 867 | + for_loop_over_map_kv::check_for_loop_over_map_kv(cx, pat, arg, body, expr); |
867 | 868 | check_for_mut_range_bound(cx, arg, body);
|
868 | 869 | check_for_single_element_loop(cx, pat, arg, body, expr);
|
869 | 870 | detect_same_item_push(cx, pat, arg, body, expr);
|
@@ -1732,59 +1733,6 @@ fn check_for_loop_explicit_counter<'tcx>(
|
1732 | 1733 | }
|
1733 | 1734 | }
|
1734 | 1735 |
|
1735 |
| -/// Checks for the `FOR_KV_MAP` lint. |
1736 |
| -fn check_for_loop_over_map_kv<'tcx>( |
1737 |
| - cx: &LateContext<'tcx>, |
1738 |
| - pat: &'tcx Pat<'_>, |
1739 |
| - arg: &'tcx Expr<'_>, |
1740 |
| - body: &'tcx Expr<'_>, |
1741 |
| - expr: &'tcx Expr<'_>, |
1742 |
| -) { |
1743 |
| - let pat_span = pat.span; |
1744 |
| - |
1745 |
| - if let PatKind::Tuple(ref pat, _) = pat.kind { |
1746 |
| - if pat.len() == 2 { |
1747 |
| - let arg_span = arg.span; |
1748 |
| - let (new_pat_span, kind, ty, mutbl) = match *cx.typeck_results().expr_ty(arg).kind() { |
1749 |
| - ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) { |
1750 |
| - (key, _) if pat_is_wild(cx, key, body) => (pat[1].span, "value", ty, mutbl), |
1751 |
| - (_, value) if pat_is_wild(cx, value, body) => (pat[0].span, "key", ty, Mutability::Not), |
1752 |
| - _ => return, |
1753 |
| - }, |
1754 |
| - _ => return, |
1755 |
| - }; |
1756 |
| - let mutbl = match mutbl { |
1757 |
| - Mutability::Not => "", |
1758 |
| - Mutability::Mut => "_mut", |
1759 |
| - }; |
1760 |
| - let arg = match arg.kind { |
1761 |
| - ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) => &**expr, |
1762 |
| - _ => arg, |
1763 |
| - }; |
1764 |
| - |
1765 |
| - if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP) { |
1766 |
| - span_lint_and_then( |
1767 |
| - cx, |
1768 |
| - FOR_KV_MAP, |
1769 |
| - expr.span, |
1770 |
| - &format!("you seem to want to iterate on a map's {}s", kind), |
1771 |
| - |diag| { |
1772 |
| - let map = sugg::Sugg::hir(cx, arg, "map"); |
1773 |
| - multispan_sugg( |
1774 |
| - diag, |
1775 |
| - "use the corresponding method", |
1776 |
| - vec![ |
1777 |
| - (pat_span, snippet(cx, new_pat_span, kind).into_owned()), |
1778 |
| - (arg_span, format!("{}.{}s{}()", map.maybe_par(), kind, mutbl)), |
1779 |
| - ], |
1780 |
| - ); |
1781 |
| - }, |
1782 |
| - ); |
1783 |
| - } |
1784 |
| - } |
1785 |
| - } |
1786 |
| -} |
1787 |
| - |
1788 | 1736 | fn check_for_single_element_loop<'tcx>(
|
1789 | 1737 | cx: &LateContext<'tcx>,
|
1790 | 1738 | pat: &'tcx Pat<'_>,
|
@@ -1927,17 +1875,6 @@ fn check_for_mutation<'tcx>(
|
1927 | 1875 | delegate.mutation_span()
|
1928 | 1876 | }
|
1929 | 1877 |
|
1930 |
| -/// Returns `true` if the pattern is a `PatWild` or an ident prefixed with `_`. |
1931 |
| -fn pat_is_wild<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx PatKind<'_>, body: &'tcx Expr<'_>) -> bool { |
1932 |
| - match *pat { |
1933 |
| - PatKind::Wild => true, |
1934 |
| - PatKind::Binding(_, id, ident, None) if ident.as_str().starts_with('_') => { |
1935 |
| - !LocalUsedVisitor::new(cx, id).check_expr(body) |
1936 |
| - }, |
1937 |
| - _ => false, |
1938 |
| - } |
1939 |
| -} |
1940 |
| - |
1941 | 1878 | struct VarVisitor<'a, 'tcx> {
|
1942 | 1879 | /// context reference
|
1943 | 1880 | cx: &'a LateContext<'tcx>,
|
|
0 commit comments