Skip to content

Commit 360f065

Browse files
committed
Move 'is_isize_or_usize' to clippy_utils
1 parent f098007 commit 360f065

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

clippy_lints/src/casts/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use rustc_target::abi::LayoutOf;
1515
use crate::consts::{constant, Constant};
1616
use crate::utils::sugg::Sugg;
1717
use crate::utils::{
18-
in_constant, is_hir_ty_cfg_dependant, meets_msrv, method_chain_args, numeric_literal::NumericLiteral, sext,
19-
snippet_opt, snippet_with_applicability, span_lint, span_lint_and_sugg, span_lint_and_then,
18+
in_constant, is_hir_ty_cfg_dependant, is_isize_or_usize, meets_msrv, method_chain_args,
19+
numeric_literal::NumericLiteral, sext, snippet_opt, snippet_with_applicability, span_lint, span_lint_and_sugg,
20+
span_lint_and_then,
2021
};
2122

2223
declare_clippy_lint! {
@@ -967,7 +968,3 @@ impl<'tcx> LateLintPass<'tcx> for PtrAsPtr {
967968

968969
extract_msrv_attr!(LateContext);
969970
}
970-
971-
fn is_isize_or_usize(typ: Ty<'_>) -> bool {
972-
matches!(typ.kind(), ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize))
973-
}

clippy_lints/src/types/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ use rustc_typeck::hir_ty_to_ty;
3737
use crate::consts::{constant, Constant};
3838
use crate::utils::paths;
3939
use crate::utils::{
40-
clip, comparisons, differing_macro_contexts, higher, indent_of, int_bits, is_type_diagnostic_item, match_path,
41-
multispan_sugg, reindent_multiline, sext, snippet, snippet_opt, snippet_with_macro_callsite, span_lint,
42-
span_lint_and_help, span_lint_and_then, unsext,
40+
clip, comparisons, differing_macro_contexts, higher, indent_of, int_bits, is_isize_or_usize,
41+
is_type_diagnostic_item, match_path, multispan_sugg, reindent_multiline, sext, snippet, snippet_opt,
42+
snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_then, unsext,
4343
};
4444

4545
declare_clippy_lint! {
@@ -1666,7 +1666,3 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
16661666
NestedVisitorMap::OnlyBodies(self.cx.tcx.hir())
16671667
}
16681668
}
1669-
1670-
fn is_isize_or_usize(typ: Ty<'_>) -> bool {
1671-
matches!(typ.kind(), ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize))
1672-
}

clippy_utils/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use rustc_lint::{LateContext, Level, Lint, LintContext};
7272
use rustc_middle::hir::exports::Export;
7373
use rustc_middle::hir::map::Map;
7474
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
75-
use rustc_middle::ty::{self, layout::IntegerExt, DefIdTree, Ty, TyCtxt, TypeFoldable};
75+
use rustc_middle::ty::{self, layout::IntegerExt, DefIdTree, IntTy, Ty, TyCtxt, TypeFoldable, UintTy};
7676
use rustc_semver::RustcVersion;
7777
use rustc_session::Session;
7878
use rustc_span::hygiene::{self, ExpnKind, MacroKind};
@@ -262,6 +262,11 @@ pub fn is_ty_param_diagnostic_item(
262262
}
263263
}
264264

265+
/// Return `true` if the passed `typ` is `isize` or `usize`.
266+
pub fn is_isize_or_usize(typ: Ty<'_>) -> bool {
267+
matches!(typ.kind(), ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize))
268+
}
269+
265270
/// Checks if the method call given in `expr` belongs to the given trait.
266271
pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool {
267272
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();

0 commit comments

Comments
 (0)