float_literal: Check HIR tree before checking types.

This commit is contained in:
Jason Newcomb 2024-06-11 13:30:26 -04:00
parent ca7e5c1353
commit 278e8371e6

View File

@ -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);