From 278e8371e64e09b684127054a78b0166074b5e9b Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Tue, 11 Jun 2024 13:30:26 -0400 Subject: [PATCH] `float_literal`: Check HIR tree before checking types. --- clippy_lints/src/float_literal.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 2261fcdbdab..6adcd2235dc 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -62,10 +62,9 @@ declare_lint_pass!(FloatLiteral => [EXCESSIVE_PRECISION, LOSSY_FLOAT_LITERAL]); impl<'tcx> LateLintPass<'tcx> for FloatLiteral { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - let ty = cx.typeck_results().expr_ty(expr); - if let ty::Float(fty) = *ty.kind() - && let hir::ExprKind::Lit(lit) = expr.kind + if let hir::ExprKind::Lit(lit) = expr.kind && let LitKind::Float(sym, lit_float_ty) = lit.node + && let ty::Float(fty) = *cx.typeck_results().expr_ty(expr).kind() { let sym_str = sym.as_str(); let formatter = FloatFormat::new(sym_str);