@@ -4,7 +4,7 @@ use clippy_utils::source::snippet_with_applicability;
44use clippy_utils:: { meets_msrv, msrvs, path_to_local} ;
55use if_chain:: if_chain;
66use rustc_errors:: Applicability ;
7- use rustc_hir:: { BinOpKind , Expr , ExprKind } ;
7+ use rustc_hir:: { BinOpKind , Expr , ExprKind , Node , TyKind } ;
88use rustc_lint:: { LateContext , LateLintPass } ;
99use rustc_semver:: RustcVersion ;
1010use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
@@ -19,12 +19,12 @@ declare_clippy_lint! {
1919 ///
2020 /// ### Example
2121 /// ```rust
22- /// let x = 24;
22+ /// let x: i32 = 24;
2323 /// let rem = ((x % 4) + 4) % 4;
2424 /// ```
2525 /// Use instead:
2626 /// ```rust
27- /// let x = 24;
27+ /// let x: i32 = 24;
2828 /// let rem = x.rem_euclid(4);
2929 /// ```
3030 #[ clippy:: version = "1.63.0" ]
@@ -63,7 +63,14 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
6363 if op3. node == BinOpKind :: Rem ;
6464 if let Some ( ( const3, expr3) ) = check_for_positive_int_constant( cx, expr2) ;
6565 if const1 == const2 && const2 == const3;
66- if path_to_local( expr3) . is_some( ) ;
66+ // Only apply if we see an explicit type annotation on the local.
67+ if let Some ( hir_id) = path_to_local( expr3) ;
68+ let hir = cx. tcx. hir( ) ;
69+ if let Some ( Node :: Binding ( _) ) = hir. find( hir_id) ;
70+ let parent = hir. get_parent_node( hir_id) ;
71+ if let Some ( Node :: Local ( local) ) = hir. find( parent) ;
72+ if let Some ( ty) = local. ty;
73+ if !matches!( ty. kind, TyKind :: Infer ) ;
6774 then {
6875 let mut app = Applicability :: MachineApplicable ;
6976 let rem_of = snippet_with_applicability( cx, expr3. span, "_" , & mut app) ;
0 commit comments