Refactor drop_ref.rs to use the if_let_chain macro.
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
use rustc::lint::*;
|
use rustc::lint::*;
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc::hir::*;
|
use rustc::hir::*;
|
||||||
use syntax::codemap::Span;
|
|
||||||
use utils::{match_def_path, paths, span_note_and_lint};
|
use utils::{match_def_path, paths, span_note_and_lint};
|
||||||
|
|
||||||
/// **What it does:** Checks for calls to `std::mem::drop` with a reference
|
/// **What it does:** Checks for calls to `std::mem::drop` with a reference
|
||||||
@@ -37,29 +36,23 @@ impl LintPass for Pass {
|
|||||||
|
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||||
if let ExprCall(ref path, ref args) = expr.node {
|
if_let_chain!{[
|
||||||
if let ExprPath(ref qpath) = path.node {
|
let ExprCall(ref path, ref args) = expr.node,
|
||||||
let def_id = cx.tcx.tables().qpath_def(qpath, path.id).def_id();
|
let ExprPath(ref qpath) = path.node,
|
||||||
if match_def_path(cx, def_id, &paths::DROP) {
|
match_def_path(cx, cx.tcx.tables().qpath_def(qpath, path.id).def_id(), &paths::DROP),
|
||||||
if args.len() != 1 {
|
args.len() == 1,
|
||||||
return;
|
], {
|
||||||
}
|
let arg = &args[0];
|
||||||
check_drop_arg(cx, expr.span, &args[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_drop_arg(cx: &LateContext, call_span: Span, arg: &Expr) {
|
|
||||||
let arg_ty = cx.tcx.tables().expr_ty(arg);
|
let arg_ty = cx.tcx.tables().expr_ty(arg);
|
||||||
if let ty::TyRef(..) = arg_ty.sty {
|
if let ty::TyRef(..) = arg_ty.sty {
|
||||||
span_note_and_lint(cx,
|
span_note_and_lint(cx,
|
||||||
DROP_REF,
|
DROP_REF,
|
||||||
call_span,
|
expr.span,
|
||||||
"call to `std::mem::drop` with a reference argument. \
|
"call to `std::mem::drop` with a reference argument. \
|
||||||
Dropping a reference does nothing",
|
Dropping a reference does nothing",
|
||||||
arg.span,
|
arg.span,
|
||||||
&format!("argument has type {}", arg_ty.sty));
|
&format!("argument has type {}", arg_ty.sty));
|
||||||
}
|
}
|
||||||
|
}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user