ty.kind -> ty.kind() in rustdoc and clippy
This commit is contained in:
@@ -129,7 +129,7 @@ pub fn is_wild<'tcx>(pat: &impl std::ops::Deref<Target = Pat<'tcx>>) -> bool {
|
||||
|
||||
/// Checks if type is struct, enum or union type with the given def path.
|
||||
pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Adt(adt, _) => match_def_path(cx, adt.did, path),
|
||||
_ => false,
|
||||
}
|
||||
@@ -137,7 +137,7 @@ pub fn match_type(cx: &LateContext<'_>, ty: Ty<'_>, path: &[&str]) -> bool {
|
||||
|
||||
/// Checks if the type is equal to a diagnostic item
|
||||
pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symbol) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Adt(adt, _) => cx.tcx.is_diagnostic_item(diag_item, adt.did),
|
||||
_ => false,
|
||||
}
|
||||
@@ -145,7 +145,7 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb
|
||||
|
||||
/// Checks if the type is equal to a lang item
|
||||
pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).unwrap() == adt.did,
|
||||
_ => false,
|
||||
}
|
||||
@@ -754,7 +754,7 @@ pub fn walk_ptrs_hir_ty<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {
|
||||
|
||||
/// Returns the base type for references and raw pointers.
|
||||
pub fn walk_ptrs_ty(ty: Ty<'_>) -> Ty<'_> {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Ref(_, ty, _) => walk_ptrs_ty(ty),
|
||||
_ => ty,
|
||||
}
|
||||
@@ -764,7 +764,7 @@ pub fn walk_ptrs_ty(ty: Ty<'_>) -> Ty<'_> {
|
||||
/// depth.
|
||||
pub fn walk_ptrs_ty_depth(ty: Ty<'_>) -> (Ty<'_>, usize) {
|
||||
fn inner(ty: Ty<'_>, depth: usize) -> (Ty<'_>, usize) {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Ref(_, ty, _) => inner(ty, depth + 1),
|
||||
_ => (ty, depth),
|
||||
}
|
||||
@@ -877,7 +877,7 @@ pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
|
||||
|
||||
/// Returns `true` if the given type is an `unsafe` function.
|
||||
pub fn type_is_unsafe_function<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::FnDef(..) | ty::FnPtr(_) => ty.fn_sig(cx.tcx).unsafety() == Unsafety::Unsafe,
|
||||
_ => false,
|
||||
}
|
||||
@@ -942,7 +942,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
|
||||
is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat))
|
||||
},
|
||||
PatKind::Slice(ref head, ref middle, ref tail) => {
|
||||
match &cx.typeck_results().node_type(pat.hir_id).kind {
|
||||
match &cx.typeck_results().node_type(pat.hir_id).kind() {
|
||||
ty::Slice(..) => {
|
||||
// [..] is the only irrefutable slice pattern.
|
||||
!head.is_empty() || middle.is_none() || !tail.is_empty()
|
||||
@@ -1156,12 +1156,12 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<
|
||||
&paths::RECEIVER,
|
||||
];
|
||||
|
||||
let ty_to_check = match probably_ref_ty.kind {
|
||||
let ty_to_check = match probably_ref_ty.kind() {
|
||||
ty::Ref(_, ty_to_check, _) => ty_to_check,
|
||||
_ => probably_ref_ty,
|
||||
};
|
||||
|
||||
let def_id = match ty_to_check.kind {
|
||||
let def_id = match ty_to_check.kind() {
|
||||
ty::Array(..) => return Some("array"),
|
||||
ty::Slice(..) => return Some("slice"),
|
||||
ty::Adt(adt, _) => adt.did,
|
||||
@@ -1277,7 +1277,7 @@ pub fn must_use_attr(attrs: &[Attribute]) -> Option<&Attribute> {
|
||||
|
||||
// Returns whether the type has #[must_use] attribute
|
||||
pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Adt(ref adt, _) => must_use_attr(&cx.tcx.get_attrs(adt.did)).is_some(),
|
||||
ty::Foreign(ref did) => must_use_attr(&cx.tcx.get_attrs(*did)).is_some(),
|
||||
ty::Slice(ref ty)
|
||||
@@ -1409,9 +1409,9 @@ pub fn run_lints(cx: &LateContext<'_>, lints: &[&'static Lint], id: HirId) -> bo
|
||||
/// Returns true iff the given type is a primitive (a bool or char, any integer or floating-point
|
||||
/// number type, a str, or an array, slice, or tuple of those types).
|
||||
pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool {
|
||||
match ty.kind {
|
||||
match ty.kind() {
|
||||
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true,
|
||||
ty::Ref(_, inner, _) if inner.kind == ty::Str => true,
|
||||
ty::Ref(_, inner, _) if *inner.kind() == ty::Str => true,
|
||||
ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type),
|
||||
ty::Tuple(inner_types) => inner_types.types().all(is_recursively_primitive_type),
|
||||
_ => false,
|
||||
@@ -1423,24 +1423,23 @@ pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool {
|
||||
/// `is_recursively_primitive_type` function) and None otherwise.
|
||||
pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
|
||||
let expr_type = cx.typeck_results().expr_ty_adjusted(expr);
|
||||
let expr_kind = &expr_type.kind;
|
||||
let expr_kind = expr_type.kind();
|
||||
let is_primitive = match expr_kind {
|
||||
ty::Slice(ref element_type)
|
||||
| ty::Ref(
|
||||
_,
|
||||
ty::TyS {
|
||||
kind: ty::Slice(ref element_type),
|
||||
..
|
||||
},
|
||||
_,
|
||||
) => is_recursively_primitive_type(element_type),
|
||||
ty::Slice(element_type) => is_recursively_primitive_type(element_type),
|
||||
ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), &ty::Slice(_)) => {
|
||||
if let ty::Slice(element_type) = inner_ty.kind() {
|
||||
is_recursively_primitive_type(element_type)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
||||
if is_primitive {
|
||||
// if we have wrappers like Array, Slice or Tuple, print these
|
||||
// and get the type enclosed in the slice ref
|
||||
match expr_type.peel_refs().walk().nth(1).unwrap().expect_ty().kind {
|
||||
match expr_type.peel_refs().walk().nth(1).unwrap().expect_ty().kind() {
|
||||
ty::Slice(..) => return Some("slice".into()),
|
||||
ty::Array(..) => return Some("array".into()),
|
||||
ty::Tuple(..) => return Some("tuple".into()),
|
||||
|
||||
Reference in New Issue
Block a user