use rustc_ast::ast::{LitFloatType, LitIntType, LitKind};
use rustc_errors::Applicability;
use rustc_hir::{
- intravisit::{walk_expr, walk_stmt, NestedVisitorMap, Visitor},
+ intravisit::{walk_expr, walk_stmt, Visitor},
Body, Expr, ExprKind, HirId, Lit, Stmt, StmtKind,
};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::{
- hir::map::Map,
lint::in_external_macro,
ty::{self, FloatTy, IntTy, PolyFnSig, Ty},
};
use std::iter;
declare_clippy_lint! {
- /// **What it does:** Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type
+ /// ### What it does
+ /// Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type
/// inference.
///
/// Default numeric fallback means that if numeric types have not yet been bound to concrete
///
/// See [RFC0212](https://github.com/rust-lang/rfcs/blob/master/text/0212-restore-int-fallback.md) for more information about the fallback.
///
- /// **Why is this bad?** For those who are very careful about types, default numeric fallback
+ /// ### Why is this bad?
+ /// For those who are very careful about types, default numeric fallback
/// can be a pitfall that cause unexpected runtime behavior.
///
- /// **Known problems:** This lint can only be allowed at the function level or above.
+ /// ### Known problems
+ /// This lint can only be allowed at the function level or above.
///
- /// **Example:**
+ /// ### Example
/// ```rust
/// let i = 10;
/// let f = 1.23;
/// let i = 10i32;
/// let f = 1.23f64;
/// ```
+ #[clippy::version = "1.52.0"]
pub DEFAULT_NUMERIC_FALLBACK,
restriction,
"usage of unconstrained numeric literals which may cause default numeric fallback."
declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
-impl LateLintPass<'_> for DefaultNumericFallback {
+impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
let mut visitor = NumericFallbackVisitor::new(cx);
visitor.visit_body(body);
}
impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
- type Map = Map<'tcx>;
-
#[allow(clippy::too_many_lines)]
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
match &expr.kind {
}
},
- ExprKind::MethodCall(_, _, args, _) => {
+ ExprKind::MethodCall(_, args, _) => {
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder();
for (expr, bound) in iter::zip(*args, fn_sig.inputs()) {
fields_def
.iter()
.find_map(|f_def| {
- if f_def.ident == field.ident
+ if f_def.ident(self.cx.tcx) == field.ident
{ Some(self.cx.tcx.type_of(f_def.did)) }
else { None }
});
walk_stmt(self, stmt);
self.ty_bounds.pop();
}
-
- fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
- NestedVisitorMap::None
- }
}
fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'tcx>> {