-use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::diagnostics::span_lint_hir_and_then;
use clippy_utils::numeric_literal;
use clippy_utils::source::snippet_opt;
use if_chain::if_chain;
}
/// Check whether a passed literal has potential to cause fallback or not.
- fn check_lit(&self, lit: &Lit, lit_ty: Ty<'tcx>) {
+ fn check_lit(&self, lit: &Lit, lit_ty: Ty<'tcx>, emit_hir_id: HirId) {
if_chain! {
if !in_external_macro(self.cx.sess(), lit.span);
if let Some(ty_bound) = self.ty_bounds.last();
}
};
let sugg = numeric_literal::format(&src, Some(suffix), is_float);
- span_lint_and_sugg(
+ span_lint_hir_and_then(
self.cx,
DEFAULT_NUMERIC_FALLBACK,
+ emit_hir_id,
lit.span,
"default numeric fallback might occur",
- "consider adding suffix",
- sugg,
- Applicability::MaybeIncorrect,
+ |diag| {
+ diag.span_suggestion(lit.span, "consider adding suffix", sugg, Applicability::MaybeIncorrect);
+ }
);
}
}
}
impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
- #[allow(clippy::too_many_lines)]
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
match &expr.kind {
ExprKind::Call(func, args) => {
ExprKind::Lit(lit) => {
let ty = self.cx.typeck_results().expr_ty(expr);
- self.check_lit(lit, ty);
+ self.check_lit(lit, ty, expr.hir_id);
return;
},