]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/casts/cast_sign_loss.rs
Merge commit '0eff589afc83e21a03a168497bbab6b4dfbb4ef6' into clippyup
[rust.git] / clippy_lints / src / casts / cast_sign_loss.rs
index 9656fbebd772089ab159054227c47e04c049939c..c9c111a2847af31f2d568b65b7ff30d7f36e92a0 100644 (file)
@@ -1,12 +1,11 @@
+use clippy_utils::consts::{constant, Constant};
+use clippy_utils::diagnostics::span_lint;
+use clippy_utils::{method_chain_args, sext};
+use if_chain::if_chain;
 use rustc_hir::{Expr, ExprKind};
 use rustc_lint::LateContext;
 use rustc_middle::ty::{self, Ty};
 
-use if_chain::if_chain;
-
-use crate::consts::{constant, Constant};
-use crate::utils::{method_chain_args, sext, span_lint};
-
 use super::CAST_SIGN_LOSS;
 
 pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
@@ -31,7 +30,7 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast
             }
 
             // Don't lint for positive constants.
-            let const_val = constant(cx, &cx.typeck_results(), cast_op);
+            let const_val = constant(cx, cx.typeck_results(), cast_op);
             if_chain! {
                 if let Some((Constant::Int(n), _)) = const_val;
                 if let ty::Int(ity) = *cast_from.kind();
@@ -42,14 +41,14 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast
             }
 
             // Don't lint for the result of methods that always return non-negative values.
-            if let ExprKind::MethodCall(ref path, _, _, _) = cast_op.kind {
+            if let ExprKind::MethodCall(path, _, _, _) = cast_op.kind {
                 let mut method_name = path.ident.name.as_str();
                 let allowed_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"];
 
                 if_chain! {
                     if method_name == "unwrap";
                     if let Some(arglist) = method_chain_args(cast_op, &["unwrap"]);
-                    if let ExprKind::MethodCall(ref inner_path, _, _, _) = &arglist[0][0].kind;
+                    if let ExprKind::MethodCall(inner_path, _, _, _) = &arglist[0][0].kind;
                     then {
                         method_name = inner_path.ident.name.as_str();
                     }