mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 00:47:16 +00:00
Move 'is_isize_or_usize' to clippy_utils
This commit is contained in:
parent
f098007caa
commit
360f065404
3 changed files with 12 additions and 14 deletions
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue