1 use clippy_utils::diagnostics::span_lint_and_help;
2 use clippy_utils::ty::match_type;
3 use clippy_utils::{get_parent_expr, paths};
4 use if_chain::if_chain;
6 use rustc_lint::LateContext;
7 use rustc_span::source_map::Span;
9 use super::FILETYPE_IS_FILE;
11 pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
12 let ty = cx.typeck_results().expr_ty(recv);
14 if !match_type(cx, ty, &paths::FILE_TYPE) {
23 if let Some(parent) = get_parent_expr(cx, expr);
24 if let hir::ExprKind::Unary(op, _) = parent.kind;
25 if op == hir::UnOp::Not;
38 let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb);
39 let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary);
40 span_lint_and_help(cx, FILETYPE_IS_FILE, span, &lint_msg, None, &help_msg);