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