]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/utils/usage.rs
Merge branch 'master' into fix-4727
[rust.git] / clippy_lints / src / utils / usage.rs
index 4e66da8b19f42e331caa0fcfaa8dfb8b04a968a4..41662099fd3d785ec64bb97d170e1ad71d3d580b 100644 (file)
@@ -6,17 +6,24 @@
 use rustc::middle::mem_categorization::Categorization;
 use rustc::ty;
 use rustc_data_structures::fx::FxHashSet;
-use syntax::source_map::Span;
 
 /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined.
-pub fn mutated_variables<'a, 'tcx: 'a>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option<FxHashSet<HirId>> {
+pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> Option<FxHashSet<HirId>> {
     let mut delegate = MutVarsDelegate {
         used_mutably: FxHashSet::default(),
         skip: false,
     };
     let def_id = def_id::DefId::local(expr.hir_id.owner);
     let region_scope_tree = &cx.tcx.region_scope_tree(def_id);
-    ExprUseVisitor::new(&mut delegate, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).walk_expr(expr);
+    ExprUseVisitor::new(
+        &mut delegate,
+        cx.tcx,
+        def_id,
+        cx.param_env,
+        region_scope_tree,
+        cx.tables,
+    )
+    .walk_expr(expr);
 
     if delegate.skip {
         return None;
@@ -24,16 +31,12 @@ pub fn mutated_variables<'a, 'tcx: 'a>(expr: &'tcx Expr, cx: &'a LateContext<'a,
     Some(delegate.used_mutably)
 }
 
-pub fn is_potentially_mutated<'a, 'tcx: 'a>(
-    variable: &'tcx Path,
-    expr: &'tcx Expr,
-    cx: &'a LateContext<'a, 'tcx>,
-) -> bool {
-    let id = match variable.res {
-        Res::Local(id) | Res::Upvar(id, ..) => id,
-        _ => return true,
-    };
-    mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
+pub fn is_potentially_mutated<'a, 'tcx>(variable: &'tcx Path, expr: &'tcx Expr, cx: &'a LateContext<'a, 'tcx>) -> bool {
+    if let Res::Local(id) = variable.res {
+        mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
+    } else {
+        true
+    }
 }
 
 struct MutVarsDelegate {
@@ -61,21 +64,15 @@ fn update(&mut self, cat: &'tcx Categorization<'_>) {
 }
 
 impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
-    fn consume(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {}
-
-    fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
+    fn consume(&mut self, _: &cmt_<'tcx>, _: ConsumeMode) {}
 
-    fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {}
-
-    fn borrow(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
+    fn borrow(&mut self, cmt: &cmt_<'tcx>, bk: ty::BorrowKind) {
         if let ty::BorrowKind::MutBorrow = bk {
             self.update(&cmt.cat)
         }
     }
 
-    fn mutate(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
+    fn mutate(&mut self, cmt: &cmt_<'tcx>) {
         self.update(&cmt.cat)
     }
-
-    fn decl_without_init(&mut self, _: HirId, _: Span) {}
 }