]> git.lizzy.rs Git - rust.git/commitdiff
needless borrows found in clippy
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 26 Apr 2016 15:05:39 +0000 (17:05 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 9 May 2016 11:07:55 +0000 (13:07 +0200)
18 files changed:
src/array_indexing.rs
src/block_in_if_condition.rs
src/booleans.rs
src/consts.rs
src/copies.rs
src/cyclomatic_complexity.rs
src/enum_variants.rs
src/len_zero.rs
src/lib.rs
src/lifetimes.rs
src/loops.rs
src/matches.rs
src/methods.rs
src/misc.rs
src/mut_reference.rs
src/non_expressive_names.rs
src/shadow.rs
src/types.rs

index 2295bd7832a404e0707b95ab3d130a6db7b664e8..ce2b9a7d6c00e530b1c33d3e76b8ff6fe5268f66 100644 (file)
@@ -67,7 +67,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
                 let size = ConstInt::Infer(size as u64);
 
                 // Index is a constant uint
-                let const_index = eval_const_expr_partial(cx.tcx, &index, ExprTypeChecked, None);
+                let const_index = eval_const_expr_partial(cx.tcx, index, ExprTypeChecked, None);
                 if let Ok(ConstVal::Integral(const_index)) = const_index {
                     if size <= const_index {
                         utils::span_lint(cx, OUT_OF_BOUNDS_INDEXING, e.span, "const index is out of bounds");
index cdaf53684c539c161585a460652ebae6c46c5698..c56cf4dcd29237a623a853cbb9c819558b8f4f00 100644 (file)
@@ -59,7 +59,7 @@ fn visit_expr(&mut self, expr: &'v Expr) {
                 }
             };
             if complex {
-                self.found_block = Some(&expr);
+                self.found_block = Some(expr);
                 return;
             }
         }
index 908415acc7b954c6a1e66f34f9d9470da4c1daf7..9ab806f66ec559fdca5cf1c6bdfe705e6633b578 100644 (file)
@@ -221,7 +221,7 @@ fn recurse(brackets: bool, cx: &LateContext, suggestion: &Bool, terminals: &[&Ex
                         s.push('(');
                     }
                 }
-                s.push_str(&snip(&terminals[n as usize]));
+                s.push_str(&snip(terminals[n as usize]));
                 if brackets {
                     if let ExprBinary(..) = terminals[n as usize].node {
                         s.push(')');
@@ -319,7 +319,7 @@ fn bool_expr(&self, e: &Expr) {
             }
             let mut improvements = Vec::new();
             'simplified: for suggestion in &simplified {
-                let simplified_stats = terminal_stats(&suggestion);
+                let simplified_stats = terminal_stats(suggestion);
                 let mut improvement = false;
                 for i in 0..32 {
                     // ignore any "simplifications" that end up requiring a terminal more often than in the original expression
index 4a5f457ed7d10bb66312402d63bd0e21e7e07885..248b5bfe9e6e1588c3fc27ef6c000b6ab9bc386f 100644 (file)
@@ -164,7 +164,7 @@ fn partial_cmp(&self, other: &Constant) -> Option<Ordering> {
                 }
             }
             (&Constant::Bool(ref l), &Constant::Bool(ref r)) => Some(l.cmp(r)),
-            (&Constant::Vec(ref l), &Constant::Vec(ref r)) => l.partial_cmp(&r),
+            (&Constant::Vec(ref l), &Constant::Vec(ref r)) => l.partial_cmp(r),
             (&Constant::Repeat(ref lv, ref ls), &Constant::Repeat(ref rv, ref rs)) => {
                 match lv.partial_cmp(rv) {
                     Some(Equal) => Some(ls.cmp(rs)),
index aba4638ab8bb90e9a94d4e799af2afcbcf227def..aa9f243e8c7fc383374b2812b0ba95da1fd9e3af 100644 (file)
@@ -142,7 +142,7 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) {
     };
 
     if let ExprMatch(_, ref arms, MatchSource::Normal) = expr.node {
-        if let Some((i, j)) = search_same(&arms, hash, eq) {
+        if let Some((i, j)) = search_same(arms, hash, eq) {
             span_note_and_lint(cx,
                                MATCH_SAME_ARMS,
                                j.body.span,
@@ -256,8 +256,8 @@ fn search_same<T, Hash, Eq>(exprs: &[T], hash: Hash, eq: Eq) -> Option<(&T, &T)>
         match map.entry(hash(expr)) {
             Entry::Occupied(o) => {
                 for o in o.get() {
-                    if eq(&o, expr) {
-                        return Some((&o, expr));
+                    if eq(o, expr) {
+                        return Some((o, expr));
                     }
                 }
             }
index 9b20cc4a31258127659d5f03cfefeb43434a3730..858affd2bbb1bf891d0c163a0d0fa15556dccb2b 100644 (file)
@@ -58,7 +58,7 @@ fn check<'a, 'tcx>(&mut self, cx: &'a LateContext<'a, 'tcx>, block: &Block, span
             divergence: 0,
             short_circuits: 0,
             returns: 0,
-            tcx: &cx.tcx,
+            tcx: cx.tcx,
         };
         helper.visit_block(block);
         let CCHelper { match_arms, divergence, short_circuits, returns, .. } = helper;
index d7bd4742ebb4fc3acc9867b2f959ea6c0a5cedc9..a1f2c5e1441d149c4f0faf4c802b1c6deb2fa61a 100644 (file)
@@ -68,9 +68,9 @@ fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
             for var in &def.variants {
                 let name = var2str(var);
 
-                let pre_match = partial_match(&pre, &name);
+                let pre_match = partial_match(pre, &name);
                 pre = &pre[..pre_match];
-                let pre_camel = camel_case_until(&pre);
+                let pre_camel = camel_case_until(pre);
                 pre = &pre[..pre_camel];
                 while let Some((next, last)) = name[pre.len()..].chars().zip(pre.chars().rev()).next() {
                     if next.is_lowercase() {
@@ -82,10 +82,10 @@ fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
                     }
                 }
 
-                let post_match = partial_rmatch(&post, &name);
+                let post_match = partial_rmatch(post, &name);
                 let post_end = post.len() - post_match;
                 post = &post[post_end..];
-                let post_camel = camel_case_from(&post);
+                let post_camel = camel_case_from(post);
                 post = &post[post_camel..];
             }
             let (what, value) = match (pre.is_empty(), post.is_empty()) {
index 7e9d17d643b16cd77438f2797c5d32d5450188cd..9dae856764a197c6f6405d6e83288d36c092de16 100644 (file)
@@ -184,7 +184,7 @@ fn has_is_empty_impl(cx: &LateContext, id: &DefId) -> bool {
         })
     }
 
-    let ty = &walk_ptrs_ty(&cx.tcx.expr_ty(expr));
+    let ty = &walk_ptrs_ty(cx.tcx.expr_ty(expr));
     match ty.sty {
         ty::TyTrait(_) => {
             cx.tcx
index dc0efe815b2f2970c2a1da1d222afc19574ef9e8..e5d374a560fbc266b4ab4e4d17e9dbfbac967a92 100644 (file)
@@ -141,7 +141,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
                 ("clippy.toml", false)
             };
 
-            let (conf, errors) = utils::conf::read_conf(&file_name, must_exist);
+            let (conf, errors) = utils::conf::read_conf(file_name, must_exist);
 
             // all conf errors are non-fatal, we just use the default conf in case of error
             for error in errors {
index 67dfabe2569cacf3053c5eaedc2bdf9161849318..b9771e18ffc1fe5a21500b8f1bb37e5ec7f958dd 100644 (file)
@@ -46,7 +46,7 @@ fn get_lints(&self) -> LintArray {
 impl LateLintPass for LifetimePass {
     fn check_item(&mut self, cx: &LateContext, item: &Item) {
         if let ItemFn(ref decl, _, _, _, ref generics, _) = item.node {
-            check_fn_inner(cx, decl, None, &generics, item.span);
+            check_fn_inner(cx, decl, None, generics, item.span);
         }
     }
 
@@ -102,7 +102,7 @@ fn check_fn_inner(cx: &LateContext, decl: &FnDecl, slf: Option<&ExplicitSelf>, g
                   span,
                   "explicit lifetimes given in parameter types where they could be elided");
     }
-    report_extra_lifetimes(cx, decl, &generics, slf);
+    report_extra_lifetimes(cx, decl, generics, slf);
 }
 
 fn could_use_elision<'a, T: Iterator<Item = &'a Lifetime>>(cx: &LateContext, func: &FnDecl, slf: Option<&ExplicitSelf>,
index 70abb7a1aac7f3c35728c2ed491c66860991688b..2384c8453037b37276998b06b6a82a87df0ac9b9 100644 (file)
@@ -328,7 +328,7 @@ fn check_for_loop(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, expr: &E
 /// Check for looping over a range and then indexing a sequence with it.
 /// The iteratee must be a range literal.
 fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, expr: &Expr) {
-    if let Some(UnsugaredRange { start: Some(ref start), ref end, .. }) = unsugar_range(&arg) {
+    if let Some(UnsugaredRange { start: Some(ref start), ref end, .. }) = unsugar_range(arg) {
         // the var must be a single name
         if let PatKind::Ident(_, ref ident, _) = pat.node {
             let mut visitor = VarVisitor {
@@ -363,7 +363,7 @@ fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, ex
                 };
 
                 let take: Cow<_> = if let Some(ref end) = *end {
-                    if is_len_call(&end, &indexed) {
+                    if is_len_call(end, &indexed) {
                         "".into()
                     } else {
                         format!(".take({})", snippet(cx, end.span, "..")).into()
@@ -422,10 +422,10 @@ fn is_len_call(expr: &Expr, var: &Name) -> bool {
 
 fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
     // if this for loop is iterating over a two-sided range...
-    if let Some(UnsugaredRange { start: Some(ref start), end: Some(ref end), limits }) = unsugar_range(&arg) {
+    if let Some(UnsugaredRange { start: Some(ref start), end: Some(ref end), limits }) = unsugar_range(arg) {
         // ...and both sides are compile-time constant integers...
-        if let Ok(start_idx) = eval_const_expr_partial(&cx.tcx, start, ExprTypeChecked, None) {
-            if let Ok(end_idx) = eval_const_expr_partial(&cx.tcx, end, ExprTypeChecked, None) {
+        if let Ok(start_idx) = eval_const_expr_partial(cx.tcx, start, ExprTypeChecked, None) {
+            if let Ok(end_idx) = eval_const_expr_partial(cx.tcx, end, ExprTypeChecked, None) {
                 // ...and the start index is greater than the end index,
                 // this loop will never run. This is often confusing for developers
                 // who think that this will iterate from the larger value to the
index bce93b717a36c16ad31c910ef87931fa707dc945..db4ccf2dcdbe2a9ae474c4e9e7879a2d0749ff16 100644 (file)
@@ -461,8 +461,8 @@ fn cmp(&self, other: &Self) -> Ordering {
     let mut values = Vec::with_capacity(2 * ranges.len());
 
     for r in ranges {
-        values.push(Kind::Start(r.node.0, &r));
-        values.push(Kind::End(r.node.1, &r));
+        values.push(Kind::Start(r.node.0, r));
+        values.push(Kind::End(r.node.1, r));
     }
 
     values.sort();
@@ -475,7 +475,7 @@ fn cmp(&self, other: &Self) -> Ordering {
                 }
             }
             (&Kind::End(a, _), &Kind::Start(b, _)) if a != b => (),
-            _ => return Some((&a.range(), &b.range())),
+            _ => return Some((a.range(), b.range())),
         }
     }
 
index 44fdab454a32187e8118c9787bd277768e180a2e..5b86aab1aa1a0c43f7787fa590428412dbb911f8 100644 (file)
@@ -365,7 +365,7 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
                     lint_cstring_as_ptr(cx, expr, &arglists[0][0], &arglists[1][0]);
                 }
 
-                lint_or_fun_call(cx, expr, &name.node.as_str(), &args);
+                lint_or_fun_call(cx, expr, &name.node.as_str(), args);
 
                 let self_ty = cx.tcx.expr_ty_adjusted(&args[0]);
                 if args.len() == 1 && name.node.as_str() == "clone" {
@@ -420,7 +420,7 @@ fn check_item(&mut self, cx: &LateContext, item: &Item) {
 
                     // check conventions w.r.t. conversion method names and predicates
                     let ty = cx.tcx.lookup_item_type(cx.tcx.map.local_def_id(item.id)).ty;
-                    let is_copy = is_copy(cx, &ty, &item);
+                    let is_copy = is_copy(cx, ty, item);
                     for &(ref conv, self_kinds) in &CONVENTIONS {
                         if conv.check(&name.as_str()) &&
                            !self_kinds.iter().any(|k| k.matches(&sig.explicit_self.node, is_copy)) {
index 7323f18a46e239a6777dfe88ad3245859a206475..25747157c0f1677c816092fa899545cb0a42b66f 100644 (file)
@@ -424,7 +424,7 @@ fn is_used(cx: &LateContext, expr: &Expr) -> bool {
         match parent.node {
             ExprAssign(_, ref rhs) |
             ExprAssignOp(_, _, ref rhs) => **rhs == *expr,
-            _ => is_used(cx, &parent),
+            _ => is_used(cx, parent),
         }
     } else {
         true
index 4ac4d83360ee65588e1fcdc55e49c716d8a29b1e..f6aee54d90b35ed890c1afbda51b0dd07b78b158 100644 (file)
@@ -39,13 +39,13 @@ fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
                                                            If this happened, the compiler would have \
                                                            aborted the compilation long ago");
                 if let ExprPath(_, ref path) = fn_expr.node {
-                    check_arguments(cx, &arguments, function_type, &path.to_string());
+                    check_arguments(cx, arguments, function_type, &path.to_string());
                 }
             }
             ExprMethodCall(ref name, _, ref arguments) => {
                 let method_call = MethodCall::expr(e.id);
                 let method_type = borrowed_table.method_map.get(&method_call).expect("This should never happen.");
-                check_arguments(cx, &arguments, method_type.ty, &name.node.as_str())
+                check_arguments(cx, arguments, method_type.ty, &name.node.as_str())
             }
             _ => (),
         }
index 0c6fdc37066824fddf7c99d7bacba63516a4bf6a..9d2139fe42281ff74e34563101a20507e5d9d32a 100644 (file)
@@ -249,7 +249,7 @@ fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
                 let mut visitor = SimilarNamesLocalVisitor {
                     names: Vec::new(),
                     cx: cx,
-                    lint: &self,
+                    lint: self,
                     single_char_names: Vec::new(),
                 };
                 // initialize with function arguments
index bb287f449e3f85a78cd23e6333f12c94361852ca..4b6439c4eb36b55bb12d239d7d9667fdcce6c443 100644 (file)
@@ -278,7 +278,7 @@ fn check_expr(cx: &LateContext, expr: &Expr, bindings: &mut Vec<(Name, Span)>) {
             let len = bindings.len();
             for ref arm in arms {
                 for ref pat in &arm.pats {
-                    check_pat(cx, &pat, &Some(&**init), pat.span, bindings);
+                    check_pat(cx, pat, &Some(&**init), pat.span, bindings);
                     // This is ugly, but needed to get the right type
                     if let Some(ref guard) = arm.guard {
                         check_expr(cx, guard, bindings);
index 43d42cde501866984706b1de4b1e0b2b43f74cf0..f63538e974d005815e185d8b97e2463e79c717f7 100644 (file)
@@ -910,7 +910,7 @@ fn upcast_comparison_bounds_err(cx: &LateContext, span: &Span, rel: comparisons:
         if let Some(norm_rhs_val) = node_as_const_fullint(cx, rhs) {
             if rel == Rel::Eq || rel == Rel::Ne {
                 if norm_rhs_val < lb || norm_rhs_val > ub {
-                    err_upcast_comparison(cx, &span, lhs, rel == Rel::Ne);
+                    err_upcast_comparison(cx, span, lhs, rel == Rel::Ne);
                 }
             } else if match rel {
                 Rel::Lt => {
@@ -929,7 +929,7 @@ fn upcast_comparison_bounds_err(cx: &LateContext, span: &Span, rel: comparisons:
                 }
                 Rel::Eq | Rel::Ne => unreachable!(),
             } {
-                err_upcast_comparison(cx, &span, lhs, true)
+                err_upcast_comparison(cx, span, lhs, true)
             } else if match rel {
                 Rel::Lt => {
                     if invert {
@@ -947,7 +947,7 @@ fn upcast_comparison_bounds_err(cx: &LateContext, span: &Span, rel: comparisons:
                 }
                 Rel::Eq | Rel::Ne => unreachable!(),
             } {
-                err_upcast_comparison(cx, &span, lhs, false)
+                err_upcast_comparison(cx, span, lhs, false)
             }
         }
     }