Move has_drop to the utils module.

This commit is contained in:
Chris Emerson 2017-09-19 21:38:35 +01:00
parent f680eb164d
commit 9a0a8a0010
2 changed files with 10 additions and 10 deletions

View File

@ -1,7 +1,7 @@
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::hir::def::Def;
use rustc::hir::{BiAnd, BiOr, BlockCheckMode, Expr, Expr_, Stmt, StmtSemi, UnsafeSource};
use utils::{in_macro, snippet_opt, span_lint, span_lint_and_sugg};
use utils::{in_macro, snippet_opt, span_lint, span_lint_and_sugg, has_drop};
use std::ops::Deref;
/// **What it does:** Checks for statements which have no effect.
@ -40,15 +40,6 @@ declare_lint! {
"outer expressions with no effect"
}
/// Check whether this type implements Drop.
fn has_drop(cx: &LateContext, expr: &Expr) -> bool {
let struct_ty = cx.tables.expr_ty(expr);
match struct_ty.ty_adt_def() {
Some(def) => def.has_dtor(cx.tcx),
_ => false,
}
}
fn has_no_effect(cx: &LateContext, expr: &Expr) -> bool {
if in_macro(expr.span) {
return false;

View File

@ -358,6 +358,15 @@ pub fn implements_trait<'a, 'tcx>(
})
}
/// Check whether this type implements Drop.
pub fn has_drop(cx: &LateContext, expr: &Expr) -> bool {
let struct_ty = cx.tables.expr_ty(expr);
match struct_ty.ty_adt_def() {
Some(def) => def.has_dtor(cx.tcx),
_ => false,
}
}
/// Resolve the definition of a node from its `HirId`.
pub fn resolve_node(cx: &LateContext, qpath: &QPath, id: HirId) -> def::Def {
cx.tables.qpath_def(qpath, id)