]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/casts/as_underscore.rs
Merge commit '7248d06384c6a90de58c04c1f46be88821278d8b' into sync-from-clippy
[rust.git] / src / tools / clippy / clippy_lints / src / casts / as_underscore.rs
1 use clippy_utils::diagnostics::span_lint_and_then;
2 use rustc_errors::Applicability;
3 use rustc_hir::{Expr, Ty, TyKind};
4 use rustc_lint::LateContext;
5 use rustc_middle::ty;
6
7 use super::AS_UNDERSCORE;
8
9 pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, ty: &'tcx Ty<'_>) {
10     if matches!(ty.kind, TyKind::Infer) {
11         span_lint_and_then(cx, AS_UNDERSCORE, expr.span, "using `as _` conversion", |diag| {
12             let ty_resolved = cx.typeck_results().expr_ty(expr);
13             if let ty::Error(_) = ty_resolved.kind() {
14                 diag.help("consider giving the type explicitly");
15             } else {
16                 diag.span_suggestion(
17                     ty.span,
18                     "consider giving the type explicitly",
19                     ty_resolved,
20                     Applicability::MachineApplicable,
21                 );
22             }
23         });
24     }
25 }