From 92a3394065e601f6f4ace7f374f5ce782d7b211d Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 25 Aug 2015 14:41:35 +0200 Subject: [PATCH] all: remove unneeded deref and/or ref operations --- src/attrs.rs | 4 ++-- src/collapsible_if.rs | 2 +- src/consts.rs | 6 +++--- src/eta_reduction.rs | 2 +- src/len_zero.rs | 2 +- src/lifetimes.rs | 6 +++--- src/loops.rs | 6 +++--- src/matches.rs | 10 +++++----- src/methods.rs | 2 +- src/misc.rs | 2 +- src/needless_bool.rs | 4 ++-- src/ptr_arg.rs | 2 +- src/returns.rs | 4 ++-- src/strings.rs | 4 ++-- src/types.rs | 10 +++++----- src/utils.rs | 4 ---- 16 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/attrs.rs b/src/attrs.rs index 3e451ac5eda..ad021f28a4d 100644 --- a/src/attrs.rs +++ b/src/attrs.rs @@ -71,14 +71,14 @@ fn is_relevant_block(block: &Block) -> bool { _ => () } } - block.expr.as_ref().map_or(false, |e| is_relevant_expr(&*e)) + block.expr.as_ref().map_or(false, |e| is_relevant_expr(e)) } fn is_relevant_expr(expr: &Expr) -> bool { match expr.node { ExprBlock(ref block) => is_relevant_block(block), ExprRet(Some(ref e)) | ExprParen(ref e) => - is_relevant_expr(&*e), + is_relevant_expr(e), ExprRet(None) | ExprBreak(_) | ExprMac(_) => false, ExprCall(ref path_expr, _) => { if let ExprPath(_, ref path) = path_expr.node { diff --git a/src/collapsible_if.rs b/src/collapsible_if.rs index 7d654b43f2f..e0b25b7283b 100644 --- a/src/collapsible_if.rs +++ b/src/collapsible_if.rs @@ -79,7 +79,7 @@ fn single_stmt_of_block(block: &Block) -> Option<&Expr> { } else { None } } else { if block.stmts.is_empty() { - if let Some(ref p) = block.expr { Some(&*p) } else { None } + if let Some(ref p) = block.expr { Some(p) } else { None } } else { None } } } diff --git a/src/consts.rs b/src/consts.rs index e54ac77b599..1a828317fc2 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -222,7 +222,7 @@ fn neg_float_str(s: String) -> String { if s.starts_with('-') { s[1..].to_owned() } else { - format!("-{}", &*s) + format!("-{}", s) } } @@ -299,7 +299,7 @@ impl<'c, 'cc> ConstEvalContext<'c, 'cc> { ExprPath(_, _) => self.fetch_path(e), ExprBlock(ref block) => self.block(block), ExprIf(ref cond, ref then, ref otherwise) => - self.ifthenelse(&*cond, &*then, &*otherwise), + self.ifthenelse(cond, then, otherwise), ExprLit(ref lit) => Some(lit_to_constant(&lit.node)), ExprVec(ref vec) => self.multi(vec).map(ConstantVec), ExprTup(ref tup) => self.multi(tup).map(ConstantTuple), @@ -362,7 +362,7 @@ impl<'c, 'cc> ConstEvalContext<'c, 'cc> { if b { self.block(then) } else { - otherwise.as_ref().and_then(|ref expr| self.expr(expr)) + otherwise.as_ref().and_then(|expr| self.expr(expr)) } } else { None } } diff --git a/src/eta_reduction.rs b/src/eta_reduction.rs index 25e967b07e5..481512abc62 100644 --- a/src/eta_reduction.rs +++ b/src/eta_reduction.rs @@ -22,7 +22,7 @@ impl LintPass for EtaPass { ExprCall(_, ref args) | ExprMethodCall(_, _, ref args) => { for arg in args { - check_closure(cx, &*arg) + check_closure(cx, arg) } }, _ => (), diff --git a/src/len_zero.rs b/src/len_zero.rs index 5eaa0256402..ca3ce51bf7c 100644 --- a/src/len_zero.rs +++ b/src/len_zero.rs @@ -102,7 +102,7 @@ fn check_len_zero(cx: &Context, span: Span, method: &SpannedIdent, args: &[P], lit: &Lit, op: &str) { if let Spanned{node: LitInt(0, _), ..} = *lit { if method.node.name == "len" && args.len() == 1 && - has_is_empty(cx, &*args[0]) { + has_is_empty(cx, &args[0]) { span_lint(cx, LEN_ZERO, span, &format!( "consider replacing the len comparison with `{}{}.is_empty()`", op, snippet(cx, args[0].span, "_"))) diff --git a/src/lifetimes.rs b/src/lifetimes.rs index 9d07df4a3ed..660d68535bd 100644 --- a/src/lifetimes.rs +++ b/src/lifetimes.rs @@ -26,14 +26,14 @@ impl LintPass for LifetimePass { fn check_impl_item(&mut self, cx: &Context, item: &ImplItem) { if let MethodImplItem(ref sig, _) = item.node { - check_fn_inner(cx, &*sig.decl, Some(&sig.explicit_self), + check_fn_inner(cx, &sig.decl, Some(&sig.explicit_self), &sig.generics.lifetimes, item.span); } } fn check_trait_item(&mut self, cx: &Context, item: &TraitItem) { if let MethodTraitItem(ref sig, _) = item.node { - check_fn_inner(cx, &*sig.decl, Some(&sig.explicit_self), + check_fn_inner(cx, &sig.decl, Some(&sig.explicit_self), &sig.generics.lifetimes, item.span); } } @@ -92,7 +92,7 @@ fn could_use_elision(func: &FnDecl, slf: Option<&ExplicitSelf>, } // extract lifetimes in input argument types for arg in &func.inputs { - walk_ty(&mut input_visitor, &*arg.ty); + walk_ty(&mut input_visitor, &arg.ty); } // extract lifetimes in output type if let Return(ref ty) = func.output { diff --git a/src/loops.rs b/src/loops.rs index 5f18439eafe..ca8d3990fc5 100644 --- a/src/loops.rs +++ b/src/loops.rs @@ -95,9 +95,9 @@ fn recover_for_loop(expr: &Expr) -> Option<(&Pat, &Expr, &Expr)> { let PatEnum(_, Some(ref somepats)) = innerarms[0].pats[0].node, somepats.len() == 1 ], { - return Some((&*somepats[0], - &*iterargs[0], - &*innerarms[0].body)); + return Some((&somepats[0], + &iterargs[0], + &innerarms[0].body)); } } None diff --git a/src/matches.rs b/src/matches.rs index 002da07f50b..d1c74daf2cd 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -34,7 +34,7 @@ impl LintPass for MatchPass { // when an enum is extended, so we don't consider these cases arms[1].pats[0].node == PatWild(PatWildSingle) && // finally, we don't want any content in the second arm (unit or empty block) - is_unit_expr(&*arms[1].body) + is_unit_expr(&arms[1].body) { let body_code = snippet_block(cx, arms[0].body.span, ".."); let body_code = if let ExprBlock(_) = arms[0].body.node { @@ -46,10 +46,10 @@ impl LintPass for MatchPass { "you seem to be trying to use match for \ destructuring a single pattern. Did you mean to \ use `if let`?", - &*format!("try\nif let {} = {} {}", - snippet(cx, arms[0].pats[0].span, ".."), - snippet(cx, ex.span, ".."), - body_code) + &format!("try\nif let {} = {} {}", + snippet(cx, arms[0].pats[0].span, ".."), + snippet(cx, ex.span, ".."), + body_code) ); } diff --git a/src/methods.rs b/src/methods.rs index 40043be109a..07693e11d99 100644 --- a/src/methods.rs +++ b/src/methods.rs @@ -24,7 +24,7 @@ impl LintPass for MethodsPass { fn check_expr(&mut self, cx: &Context, expr: &Expr) { if let ExprMethodCall(ref ident, _, ref args) = expr.node { - let obj_ty = walk_ptrs_ty(cx.tcx.expr_ty(&*args[0])); + let obj_ty = walk_ptrs_ty(cx.tcx.expr_ty(&args[0])); if ident.node.name == "unwrap" { if match_type(cx, obj_ty, &OPTION_PATH) { span_lint(cx, OPTION_UNWRAP_USED, expr.span, diff --git a/src/misc.rs b/src/misc.rs index 81b03db5e14..2290af38bb5 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -203,7 +203,7 @@ fn check_to_owned(cx: &Context, expr: &Expr, other_span: Span) { fn is_str_arg(cx: &Context, args: &[P]) -> bool { args.len() == 1 && if let ty::TyStr = - walk_ptrs_ty(cx.tcx.expr_ty(&*args[0])).sty { true } else { false } + walk_ptrs_ty(cx.tcx.expr_ty(&args[0])).sty { true } else { false } } declare_lint!(pub MODULO_ONE, Warn, "taking a number modulo 1, which always returns 0"); diff --git a/src/needless_bool.rs b/src/needless_bool.rs index 7671d63a35d..0fe52c44189 100644 --- a/src/needless_bool.rs +++ b/src/needless_bool.rs @@ -5,7 +5,7 @@ use rustc::lint::*; use syntax::ast::*; -use utils::{de_p, span_lint, snippet}; +use utils::{span_lint, snippet}; declare_lint! { pub NEEDLESS_BOOL, @@ -55,7 +55,7 @@ impl LintPass for NeedlessBool { fn fetch_bool_block(block: &Block) -> Option { if block.stmts.is_empty() { - block.expr.as_ref().map(de_p).and_then(fetch_bool_expr) + block.expr.as_ref().and_then(|e| fetch_bool_expr(e)) } else { None } } diff --git a/src/ptr_arg.rs b/src/ptr_arg.rs index 2d09fcbcca9..bcbd8dad68a 100644 --- a/src/ptr_arg.rs +++ b/src/ptr_arg.rs @@ -45,7 +45,7 @@ impl LintPass for PtrArg { fn check_fn(cx: &Context, decl: &FnDecl) { for arg in &decl.inputs { - if let Some(pat_ty) = cx.tcx.pat_ty_opt(&*arg.pat) { + if let Some(pat_ty) = cx.tcx.pat_ty_opt(&arg.pat) { if let ty::TyRef(_, ty::TypeAndMut { ty, mutbl: MutImmutable }) = pat_ty.sty { if match_type(cx, ty, &VEC_PATH) { span_lint(cx, PTR_ARG, arg.ty.span, diff --git a/src/returns.rs b/src/returns.rs index df0b93f301e..301072f7912 100644 --- a/src/returns.rs +++ b/src/returns.rs @@ -50,7 +50,7 @@ impl ReturnPass { // a match expr, check all arms ExprMatch(_, ref arms, _) => { for arm in arms { - self.check_final_expr(cx, &*arm.body); + self.check_final_expr(cx, &arm.body); } } _ => { } @@ -76,7 +76,7 @@ impl ReturnPass { let PatIdent(_, Spanned { node: id, .. }, _) = local.pat.node, let Some(ref retexpr) = block.expr, let ExprPath(_, ref path) = retexpr.node, - match_path(path, &[&*id.name.as_str()]) + match_path(path, &[&id.name.as_str()]) ], { self.emit_let_lint(cx, retexpr.span, initexpr.span); } diff --git a/src/strings.rs b/src/strings.rs index b24ea345244..d03f4d53c60 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -70,8 +70,8 @@ fn is_add(cx: &Context, src: &Expr, target: &Expr) -> bool { is_exp_equal(cx, target, left), ExprBlock(ref block) => block.stmts.is_empty() && block.expr.as_ref().map_or(false, - |expr| is_add(cx, &*expr, target)), - ExprParen(ref expr) => is_add(cx, &*expr, target), + |expr| is_add(cx, expr, target)), + ExprParen(ref expr) => is_add(cx, expr, target), _ => false } } diff --git a/src/types.rs b/src/types.rs index 4e9dd133ac8..7479a65b6ee 100644 --- a/src/types.rs +++ b/src/types.rs @@ -55,7 +55,7 @@ declare_lint!(pub LET_UNIT_VALUE, Warn, fn check_let_unit(cx: &Context, decl: &Decl, info: Option<&ExpnInfo>) { if in_macro(cx, info) { return; } if let DeclLocal(ref local) = decl.node { - let bindtype = &cx.tcx.pat_ty(&*local.pat).sty; + let bindtype = &cx.tcx.pat_ty(&local.pat).sty; if *bindtype == ty::TyTuple(vec![]) { span_lint(cx, LET_UNIT_VALUE, decl.span, &format!( "this let-binding has unit value. Consider omitting `let {} =`", @@ -210,7 +210,7 @@ impl LintPass for CastPass { fn check_expr(&mut self, cx: &Context, expr: &Expr) { if let ExprCast(ref ex, _) = expr.node { - let (cast_from, cast_to) = (cx.tcx.expr_ty(&*ex), cx.tcx.expr_ty(expr)); + let (cast_from, cast_to) = (cx.tcx.expr_ty(ex), cx.tcx.expr_ty(expr)); if cast_from.is_numeric() && cast_to.is_numeric() && !in_external_macro(cx, expr.span) { match (cast_from.is_integral(), cast_to.is_integral()) { (true, false) => { @@ -263,14 +263,14 @@ impl LintPass for TypeComplexityPass { } fn check_struct_field(&mut self, cx: &Context, field: &StructField) { - check_type(cx, &*field.node.ty); + check_type(cx, &field.node.ty); } fn check_variant(&mut self, cx: &Context, var: &Variant, _: &Generics) { // StructVariant is covered by check_struct_field if let TupleVariantKind(ref args) = var.node.kind { for arg in args { - check_type(cx, &*arg.ty); + check_type(cx, &arg.ty); } } } @@ -312,7 +312,7 @@ impl LintPass for TypeComplexityPass { fn check_fndecl(cx: &Context, decl: &FnDecl) { for arg in &decl.inputs { - check_type(cx, &*arg.ty); + check_type(cx, &arg.ty); } if let Return(ref ty) = decl.output { check_type(cx, ty); diff --git a/src/utils.rs b/src/utils.rs index 5e7c63e85d9..394204bedfc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,7 +1,6 @@ use rustc::lint::*; use syntax::ast::*; use syntax::codemap::{ExpnInfo, Span}; -use syntax::ptr::P; use rustc::ast_map::Node::NodeExpr; use rustc::middle::ty; use std::borrow::Cow; @@ -130,9 +129,6 @@ pub fn get_parent_expr<'c>(cx: &'c Context, e: &Expr) -> Option<&'c Expr> { if let NodeExpr(parent) = node { Some(parent) } else { None } ) } -/// dereference a P and return a ref on the result -pub fn de_p(p: &P) -> &T { &*p } - #[cfg(not(feature="structured_logging"))] pub fn span_lint(cx: &Context, lint: &'static Lint, sp: Span, msg: &str) { cx.span_lint(lint, sp, msg);