|
| 1 | +use crate::consts::{constant, Constant}; |
1 | 2 | use crate::reexport::*; |
| 3 | +use crate::utils::paths; |
| 4 | +use crate::utils::usage::{is_unused, mutated_variables}; |
| 5 | +use crate::utils::{ |
| 6 | + get_enclosing_block, get_parent_expr, get_trait_def_id, has_iter_method, higher, implements_trait, |
| 7 | + is_integer_const, is_refutable, last_path_segment, match_trait_method, match_type, match_var, multispan_sugg, |
| 8 | + snippet, snippet_opt, snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg, |
| 9 | + span_lint_and_then, SpanlessEq, |
| 10 | +}; |
| 11 | +use crate::utils::{is_type_diagnostic_item, qpath_res, same_tys, sext, sugg}; |
2 | 12 | use if_chain::if_chain; |
3 | 13 | use itertools::Itertools; |
| 14 | +use rustc::hir::map::Map; |
4 | 15 | use rustc::lint::in_external_macro; |
5 | 16 | use rustc::middle::region; |
| 17 | +use rustc::ty::{self, Ty}; |
| 18 | +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; |
| 19 | +use rustc_errors::Applicability; |
6 | 20 | use rustc_hir::def::{DefKind, Res}; |
7 | 21 | use rustc_hir::def_id; |
8 | 22 | use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor}; |
9 | 23 | use rustc_hir::*; |
10 | 24 | use rustc_lint::{LateContext, LateLintPass, LintContext}; |
11 | 25 | use rustc_session::{declare_lint_pass, declare_tool_lint}; |
12 | | -// use rustc::middle::region::CodeExtent; |
13 | | -use crate::consts::{constant, Constant}; |
14 | | -use crate::utils::usage::mutated_variables; |
15 | | -use crate::utils::{is_type_diagnostic_item, qpath_res, same_tys, sext, sugg}; |
16 | | -use rustc::hir::map::Map; |
17 | | -use rustc::ty::{self, Ty}; |
18 | | -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; |
19 | | -use rustc_errors::Applicability; |
20 | 26 | use rustc_span::source_map::Span; |
21 | 27 | use rustc_span::{BytePos, Symbol}; |
22 | 28 | use rustc_typeck::expr_use_visitor::*; |
23 | 29 | use std::iter::{once, Iterator}; |
24 | 30 | use std::mem; |
25 | 31 | use syntax::ast; |
26 | 32 |
|
27 | | -use crate::utils::paths; |
28 | | -use crate::utils::{ |
29 | | - get_enclosing_block, get_parent_expr, get_trait_def_id, has_iter_method, higher, implements_trait, |
30 | | - is_integer_const, is_refutable, last_path_segment, match_trait_method, match_type, match_var, multispan_sugg, |
31 | | - snippet, snippet_opt, snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg, |
32 | | - span_lint_and_then, SpanlessEq, |
33 | | -}; |
34 | | - |
35 | 33 | declare_clippy_lint! { |
36 | 34 | /// **What it does:** Checks for for-loops that manually copy items between |
37 | 35 | /// slices that could be optimized by having a memcpy. |
@@ -1689,39 +1687,11 @@ fn check_for_mutation( |
1689 | 1687 | fn pat_is_wild<'tcx>(pat: &'tcx PatKind<'_>, body: &'tcx Expr<'_>) -> bool { |
1690 | 1688 | match *pat { |
1691 | 1689 | PatKind::Wild => true, |
1692 | | - PatKind::Binding(.., ident, None) if ident.as_str().starts_with('_') => { |
1693 | | - let mut visitor = UsedVisitor { |
1694 | | - var: ident.name, |
1695 | | - used: false, |
1696 | | - }; |
1697 | | - walk_expr(&mut visitor, body); |
1698 | | - !visitor.used |
1699 | | - }, |
| 1690 | + PatKind::Binding(.., ident, None) if ident.as_str().starts_with('_') => is_unused(&ident, body), |
1700 | 1691 | _ => false, |
1701 | 1692 | } |
1702 | 1693 | } |
1703 | 1694 |
|
1704 | | -struct UsedVisitor { |
1705 | | - var: ast::Name, // var to look for |
1706 | | - used: bool, // has the var been used otherwise? |
1707 | | -} |
1708 | | - |
1709 | | -impl<'tcx> Visitor<'tcx> for UsedVisitor { |
1710 | | - type Map = Map<'tcx>; |
1711 | | - |
1712 | | - fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { |
1713 | | - if match_var(expr, self.var) { |
1714 | | - self.used = true; |
1715 | | - } else { |
1716 | | - walk_expr(self, expr); |
1717 | | - } |
1718 | | - } |
1719 | | - |
1720 | | - fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { |
1721 | | - NestedVisitorMap::None |
1722 | | - } |
1723 | | -} |
1724 | | - |
1725 | 1695 | struct LocalUsedVisitor<'a, 'tcx> { |
1726 | 1696 | cx: &'a LateContext<'a, 'tcx>, |
1727 | 1697 | local: HirId, |
|
0 commit comments