about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYoshitomo Nakanishi <yurayura.rounin.3@gmail.com>2021-03-09 11:08:26 +0900
committerYoshitomo Nakanishi <yurayura.rounin.3@gmail.com>2021-03-09 11:08:45 +0900
commit360f0654047ef45212440e0cc9dcfe77c970b1eb (patch)
tree85dd16705d8110635ee0bebe8643f0e0a1b0fd6b
parentf098007caaebe660b06ee7c43cd30006807a2a8c (diff)
downloadrust-360f0654047ef45212440e0cc9dcfe77c970b1eb.tar.gz
rust-360f0654047ef45212440e0cc9dcfe77c970b1eb.zip
Move 'is_isize_or_usize' to clippy_utils
-rw-r--r--clippy_lints/src/casts/mod.rs9
-rw-r--r--clippy_lints/src/types/mod.rs10
-rw-r--r--clippy_utils/src/lib.rs7
3 files changed, 12 insertions, 14 deletions
diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs
index d8245a3b88f..95e563fc3ba 100644
--- a/clippy_lints/src/casts/mod.rs
+++ b/clippy_lints/src/casts/mod.rs
@@ -15,8 +15,9 @@ use rustc_target::abi::LayoutOf;
 use crate::consts::{constant, Constant};
 use crate::utils::sugg::Sugg;
 use crate::utils::{
-    in_constant, is_hir_ty_cfg_dependant, meets_msrv, method_chain_args, numeric_literal::NumericLiteral, sext,
-    snippet_opt, snippet_with_applicability, span_lint, span_lint_and_sugg, span_lint_and_then,
+    in_constant, is_hir_ty_cfg_dependant, is_isize_or_usize, meets_msrv, method_chain_args,
+    numeric_literal::NumericLiteral, sext, snippet_opt, snippet_with_applicability, span_lint, span_lint_and_sugg,
+    span_lint_and_then,
 };
 
 declare_clippy_lint! {
@@ -967,7 +968,3 @@ impl<'tcx> LateLintPass<'tcx> for PtrAsPtr {
 
     extract_msrv_attr!(LateContext);
 }
-
-fn is_isize_or_usize(typ: Ty<'_>) -> bool {
-    matches!(typ.kind(), ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize))
-}
diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs
index 3e7aa53d5bc..7be4ea03793 100644
--- a/clippy_lints/src/types/mod.rs
+++ b/clippy_lints/src/types/mod.rs
@@ -37,9 +37,9 @@ use rustc_typeck::hir_ty_to_ty;
 use crate::consts::{constant, Constant};
 use crate::utils::paths;
 use crate::utils::{
-    clip, comparisons, differing_macro_contexts, higher, indent_of, int_bits, is_type_diagnostic_item, match_path,
-    multispan_sugg, reindent_multiline, sext, snippet, snippet_opt, snippet_with_macro_callsite, span_lint,
-    span_lint_and_help, span_lint_and_then, unsext,
+    clip, comparisons, differing_macro_contexts, higher, indent_of, int_bits, is_isize_or_usize,
+    is_type_diagnostic_item, match_path, multispan_sugg, reindent_multiline, sext, snippet, snippet_opt,
+    snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_then, unsext,
 };
 
 declare_clippy_lint! {
@@ -1666,7 +1666,3 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
         NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
     }
 }
-
-fn is_isize_or_usize(typ: Ty<'_>) -> bool {
-    matches!(typ.kind(), ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize))
-}
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index 3845667802d..74429982759 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -72,7 +72,7 @@ use rustc_lint::{LateContext, Level, Lint, LintContext};
 use rustc_middle::hir::exports::Export;
 use rustc_middle::hir::map::Map;
 use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
-use rustc_middle::ty::{self, layout::IntegerExt, DefIdTree, Ty, TyCtxt, TypeFoldable};
+use rustc_middle::ty::{self, layout::IntegerExt, DefIdTree, IntTy, Ty, TyCtxt, TypeFoldable, UintTy};
 use rustc_semver::RustcVersion;
 use rustc_session::Session;
 use rustc_span::hygiene::{self, ExpnKind, MacroKind};
@@ -262,6 +262,11 @@ pub fn is_ty_param_diagnostic_item(
     }
 }
 
+/// Return `true` if the passed `typ` is `isize` or `usize`.
+pub fn is_isize_or_usize(typ: Ty<'_>) -> bool {
+    matches!(typ.kind(), ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize))
+}
+
 /// Checks if the method call given in `expr` belongs to the given trait.
 pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool {
     let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();