]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/clippy_lints/src/casts/cast_enum_constructor.rs
New upstream version 1.61.0+dfsg1
[rustc.git] / src / tools / clippy / clippy_lints / src / casts / cast_enum_constructor.rs
1 use clippy_utils::diagnostics::span_lint;
2 use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
3 use rustc_hir::{Expr, ExprKind};
4 use rustc_lint::LateContext;
5 use rustc_middle::ty::{self, Ty};
6
7 use super::CAST_ENUM_CONSTRUCTOR;
8
9 pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>) {
10 if matches!(cast_from.kind(), ty::FnDef(..))
11 && let ExprKind::Path(path) = &cast_expr.kind
12 && let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Fn), _) = cx.qpath_res(path, cast_expr.hir_id)
13 {
14 span_lint(
15 cx,
16 CAST_ENUM_CONSTRUCTOR,
17 expr.span,
18 "cast of an enum tuple constructor to an integer",
19 );
20 }
21 }