_ => ()
}
}
- 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 {
} 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 }
}
}
if s.starts_with('-') {
s[1..].to_owned()
} else {
- format!("-{}", &*s)
+ format!("-{}", s)
}
}
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),
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 }
}
ExprCall(_, ref args) |
ExprMethodCall(_, _, ref args) => {
for arg in args {
- check_closure(cx, &*arg)
+ check_closure(cx, arg)
}
},
_ => (),
args: &[P<Expr>], 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, "_")))
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);
}
}
}
// 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 {
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
// 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 {
"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)
);
}
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,
fn is_str_arg(cx: &Context, args: &[P<Expr>]) -> 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");
use rustc::lint::*;
use syntax::ast::*;
-use utils::{de_p, span_lint, snippet};
+use utils::{span_lint, snippet};
declare_lint! {
pub NEEDLESS_BOOL,
fn fetch_bool_block(block: &Block) -> Option<bool> {
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 }
}
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,
// 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);
}
}
_ => { }
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);
}
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
}
}
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 {} =`",
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) => {
}
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);
}
}
}
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);
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;
if let NodeExpr(parent) = node { Some(parent) } else { None } )
}
-/// dereference a P<T> and return a ref on the result
-pub fn de_p<T>(p: &P<T>) -> &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);