Skip to content

Commit b13d318

Browse files
birkenfeldllogiq
authored andcommitted
all: remove unneeded deref and/or ref operations
1 parent 88047a0 commit b13d318

16 files changed

+33
-37
lines changed

src/attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ fn is_relevant_block(block: &Block) -> bool {
7171
_ => ()
7272
}
7373
}
74-
block.expr.as_ref().map_or(false, |e| is_relevant_expr(&*e))
74+
block.expr.as_ref().map_or(false, |e| is_relevant_expr(e))
7575
}
7676

7777
fn is_relevant_expr(expr: &Expr) -> bool {
7878
match expr.node {
7979
ExprBlock(ref block) => is_relevant_block(block),
8080
ExprRet(Some(ref e)) | ExprParen(ref e) =>
81-
is_relevant_expr(&*e),
81+
is_relevant_expr(e),
8282
ExprRet(None) | ExprBreak(_) | ExprMac(_) => false,
8383
ExprCall(ref path_expr, _) => {
8484
if let ExprPath(_, ref path) = path_expr.node {

src/collapsible_if.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn single_stmt_of_block(block: &Block) -> Option<&Expr> {
7979
} else { None }
8080
} else {
8181
if block.stmts.is_empty() {
82-
if let Some(ref p) = block.expr { Some(&*p) } else { None }
82+
if let Some(ref p) = block.expr { Some(p) } else { None }
8383
} else { None }
8484
}
8585
}

src/consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ fn neg_float_str(s: String) -> String {
222222
if s.starts_with('-') {
223223
s[1..].to_owned()
224224
} else {
225-
format!("-{}", &*s)
225+
format!("-{}", s)
226226
}
227227
}
228228

@@ -299,7 +299,7 @@ impl<'c, 'cc> ConstEvalContext<'c, 'cc> {
299299
ExprPath(_, _) => self.fetch_path(e),
300300
ExprBlock(ref block) => self.block(block),
301301
ExprIf(ref cond, ref then, ref otherwise) =>
302-
self.ifthenelse(&*cond, &*then, &*otherwise),
302+
self.ifthenelse(cond, then, otherwise),
303303
ExprLit(ref lit) => Some(lit_to_constant(&lit.node)),
304304
ExprVec(ref vec) => self.multi(vec).map(ConstantVec),
305305
ExprTup(ref tup) => self.multi(tup).map(ConstantTuple),
@@ -362,7 +362,7 @@ impl<'c, 'cc> ConstEvalContext<'c, 'cc> {
362362
if b {
363363
self.block(then)
364364
} else {
365-
otherwise.as_ref().and_then(|ref expr| self.expr(expr))
365+
otherwise.as_ref().and_then(|expr| self.expr(expr))
366366
}
367367
} else { None }
368368
}

src/eta_reduction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl LintPass for EtaPass {
2222
ExprCall(_, ref args) |
2323
ExprMethodCall(_, _, ref args) => {
2424
for arg in args {
25-
check_closure(cx, &*arg)
25+
check_closure(cx, arg)
2626
}
2727
},
2828
_ => (),

src/len_zero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn check_len_zero(cx: &Context, span: Span, method: &SpannedIdent,
102102
args: &[P<Expr>], lit: &Lit, op: &str) {
103103
if let Spanned{node: LitInt(0, _), ..} = *lit {
104104
if method.node.name == "len" && args.len() == 1 &&
105-
has_is_empty(cx, &*args[0]) {
105+
has_is_empty(cx, &args[0]) {
106106
span_lint(cx, LEN_ZERO, span, &format!(
107107
"consider replacing the len comparison with `{}{}.is_empty()`",
108108
op, snippet(cx, args[0].span, "_")))

src/lifetimes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ impl LintPass for LifetimePass {
2626

2727
fn check_impl_item(&mut self, cx: &Context, item: &ImplItem) {
2828
if let MethodImplItem(ref sig, _) = item.node {
29-
check_fn_inner(cx, &*sig.decl, Some(&sig.explicit_self),
29+
check_fn_inner(cx, &sig.decl, Some(&sig.explicit_self),
3030
&sig.generics.lifetimes, item.span);
3131
}
3232
}
3333

3434
fn check_trait_item(&mut self, cx: &Context, item: &TraitItem) {
3535
if let MethodTraitItem(ref sig, _) = item.node {
36-
check_fn_inner(cx, &*sig.decl, Some(&sig.explicit_self),
36+
check_fn_inner(cx, &sig.decl, Some(&sig.explicit_self),
3737
&sig.generics.lifetimes, item.span);
3838
}
3939
}
@@ -92,7 +92,7 @@ fn could_use_elision(func: &FnDecl, slf: Option<&ExplicitSelf>,
9292
}
9393
// extract lifetimes in input argument types
9494
for arg in &func.inputs {
95-
walk_ty(&mut input_visitor, &*arg.ty);
95+
walk_ty(&mut input_visitor, &arg.ty);
9696
}
9797
// extract lifetimes in output type
9898
if let Return(ref ty) = func.output {

src/loops.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ fn recover_for_loop(expr: &Expr) -> Option<(&Pat, &Expr, &Expr)> {
9595
let PatEnum(_, Some(ref somepats)) = innerarms[0].pats[0].node,
9696
somepats.len() == 1
9797
], {
98-
return Some((&*somepats[0],
99-
&*iterargs[0],
100-
&*innerarms[0].body));
98+
return Some((&somepats[0],
99+
&iterargs[0],
100+
&innerarms[0].body));
101101
}
102102
}
103103
None

src/matches.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl LintPass for MatchPass {
3434
// when an enum is extended, so we don't consider these cases
3535
arms[1].pats[0].node == PatWild(PatWildSingle) &&
3636
// finally, we don't want any content in the second arm (unit or empty block)
37-
is_unit_expr(&*arms[1].body)
37+
is_unit_expr(&arms[1].body)
3838
{
3939
let body_code = snippet_block(cx, arms[0].body.span, "..");
4040
let body_code = if let ExprBlock(_) = arms[0].body.node {
@@ -46,10 +46,10 @@ impl LintPass for MatchPass {
4646
"you seem to be trying to use match for \
4747
destructuring a single pattern. Did you mean to \
4848
use `if let`?",
49-
&*format!("try\nif let {} = {} {}",
50-
snippet(cx, arms[0].pats[0].span, ".."),
51-
snippet(cx, ex.span, ".."),
52-
body_code)
49+
&format!("try\nif let {} = {} {}",
50+
snippet(cx, arms[0].pats[0].span, ".."),
51+
snippet(cx, ex.span, ".."),
52+
body_code)
5353
);
5454
}
5555

src/methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl LintPass for MethodsPass {
2424

2525
fn check_expr(&mut self, cx: &Context, expr: &Expr) {
2626
if let ExprMethodCall(ref ident, _, ref args) = expr.node {
27-
let obj_ty = walk_ptrs_ty(cx.tcx.expr_ty(&*args[0]));
27+
let obj_ty = walk_ptrs_ty(cx.tcx.expr_ty(&args[0]));
2828
if ident.node.name == "unwrap" {
2929
if match_type(cx, obj_ty, &OPTION_PATH) {
3030
span_lint(cx, OPTION_UNWRAP_USED, expr.span,

src/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn check_to_owned(cx: &Context, expr: &Expr, other_span: Span) {
203203

204204
fn is_str_arg(cx: &Context, args: &[P<Expr>]) -> bool {
205205
args.len() == 1 && if let ty::TyStr =
206-
walk_ptrs_ty(cx.tcx.expr_ty(&*args[0])).sty { true } else { false }
206+
walk_ptrs_ty(cx.tcx.expr_ty(&args[0])).sty { true } else { false }
207207
}
208208

209209
declare_lint!(pub MODULO_ONE, Warn, "taking a number modulo 1, which always returns 0");

src/needless_bool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use rustc::lint::*;
66
use syntax::ast::*;
77

8-
use utils::{de_p, span_lint, snippet};
8+
use utils::{span_lint, snippet};
99

1010
declare_lint! {
1111
pub NEEDLESS_BOOL,
@@ -55,7 +55,7 @@ impl LintPass for NeedlessBool {
5555

5656
fn fetch_bool_block(block: &Block) -> Option<bool> {
5757
if block.stmts.is_empty() {
58-
block.expr.as_ref().map(de_p).and_then(fetch_bool_expr)
58+
block.expr.as_ref().and_then(|e| fetch_bool_expr(e))
5959
} else { None }
6060
}
6161

src/ptr_arg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl LintPass for PtrArg {
4545

4646
fn check_fn(cx: &Context, decl: &FnDecl) {
4747
for arg in &decl.inputs {
48-
if let Some(pat_ty) = cx.tcx.pat_ty_opt(&*arg.pat) {
48+
if let Some(pat_ty) = cx.tcx.pat_ty_opt(&arg.pat) {
4949
if let ty::TyRef(_, ty::TypeAndMut { ty, mutbl: MutImmutable }) = pat_ty.sty {
5050
if match_type(cx, ty, &VEC_PATH) {
5151
span_lint(cx, PTR_ARG, arg.ty.span,

src/returns.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl ReturnPass {
5050
// a match expr, check all arms
5151
ExprMatch(_, ref arms, _) => {
5252
for arm in arms {
53-
self.check_final_expr(cx, &*arm.body);
53+
self.check_final_expr(cx, &arm.body);
5454
}
5555
}
5656
_ => { }
@@ -76,7 +76,7 @@ impl ReturnPass {
7676
let PatIdent(_, Spanned { node: id, .. }, _) = local.pat.node,
7777
let Some(ref retexpr) = block.expr,
7878
let ExprPath(_, ref path) = retexpr.node,
79-
match_path(path, &[&*id.name.as_str()])
79+
match_path(path, &[&id.name.as_str()])
8080
], {
8181
self.emit_let_lint(cx, retexpr.span, initexpr.span);
8282
}

src/strings.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ fn is_add(cx: &Context, src: &Expr, target: &Expr) -> bool {
7070
is_exp_equal(cx, target, left),
7171
ExprBlock(ref block) => block.stmts.is_empty() &&
7272
block.expr.as_ref().map_or(false,
73-
|expr| is_add(cx, &*expr, target)),
74-
ExprParen(ref expr) => is_add(cx, &*expr, target),
73+
|expr| is_add(cx, expr, target)),
74+
ExprParen(ref expr) => is_add(cx, expr, target),
7575
_ => false
7676
}
7777
}

src/types.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare_lint!(pub LET_UNIT_VALUE, Warn,
5555
fn check_let_unit(cx: &Context, decl: &Decl, info: Option<&ExpnInfo>) {
5656
if in_macro(cx, info) { return; }
5757
if let DeclLocal(ref local) = decl.node {
58-
let bindtype = &cx.tcx.pat_ty(&*local.pat).sty;
58+
let bindtype = &cx.tcx.pat_ty(&local.pat).sty;
5959
if *bindtype == ty::TyTuple(vec![]) {
6060
span_lint(cx, LET_UNIT_VALUE, decl.span, &format!(
6161
"this let-binding has unit value. Consider omitting `let {} =`",
@@ -210,7 +210,7 @@ impl LintPass for CastPass {
210210

211211
fn check_expr(&mut self, cx: &Context, expr: &Expr) {
212212
if let ExprCast(ref ex, _) = expr.node {
213-
let (cast_from, cast_to) = (cx.tcx.expr_ty(&*ex), cx.tcx.expr_ty(expr));
213+
let (cast_from, cast_to) = (cx.tcx.expr_ty(ex), cx.tcx.expr_ty(expr));
214214
if cast_from.is_numeric() && cast_to.is_numeric() && !in_external_macro(cx, expr.span) {
215215
match (cast_from.is_integral(), cast_to.is_integral()) {
216216
(true, false) => {
@@ -263,14 +263,14 @@ impl LintPass for TypeComplexityPass {
263263
}
264264

265265
fn check_struct_field(&mut self, cx: &Context, field: &StructField) {
266-
check_type(cx, &*field.node.ty);
266+
check_type(cx, &field.node.ty);
267267
}
268268

269269
fn check_variant(&mut self, cx: &Context, var: &Variant, _: &Generics) {
270270
// StructVariant is covered by check_struct_field
271271
if let TupleVariantKind(ref args) = var.node.kind {
272272
for arg in args {
273-
check_type(cx, &*arg.ty);
273+
check_type(cx, &arg.ty);
274274
}
275275
}
276276
}
@@ -312,7 +312,7 @@ impl LintPass for TypeComplexityPass {
312312

313313
fn check_fndecl(cx: &Context, decl: &FnDecl) {
314314
for arg in &decl.inputs {
315-
check_type(cx, &*arg.ty);
315+
check_type(cx, &arg.ty);
316316
}
317317
if let Return(ref ty) = decl.output {
318318
check_type(cx, ty);

src/utils.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc::lint::*;
22
use syntax::ast::*;
33
use syntax::codemap::{ExpnInfo, Span};
4-
use syntax::ptr::P;
54
use rustc::ast_map::Node::NodeExpr;
65
use rustc::middle::ty;
76
use std::borrow::Cow;
@@ -130,9 +129,6 @@ pub fn get_parent_expr<'c>(cx: &'c Context, e: &Expr) -> Option<&'c Expr> {
130129
if let NodeExpr(parent) = node { Some(parent) } else { None } )
131130
}
132131

133-
/// dereference a P<T> and return a ref on the result
134-
pub fn de_p<T>(p: &P<T>) -> &T { &*p }
135-
136132
#[cfg(not(feature="structured_logging"))]
137133
pub fn span_lint(cx: &Context, lint: &'static Lint, sp: Span, msg: &str) {
138134
cx.span_lint(lint, sp, msg);

0 commit comments

Comments
 (0)