update clippy
This commit is contained in:
parent
a703a82035
commit
e390e6c469
@ -193,7 +193,7 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &m
|
|||||||
|| KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path))
|
|| KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path))
|
||||||
&& substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys))
|
&& substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys))
|
||||||
},
|
},
|
||||||
ty::Tuple(substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
|
ty::Tuple(substs) => substs.iter().any(|ty| is_mutable_ty(cx, ty, span, tys)),
|
||||||
ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, span, tys),
|
ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, span, tys),
|
||||||
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => {
|
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => {
|
||||||
mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, span, tys)
|
mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, span, tys)
|
||||||
|
@ -58,8 +58,8 @@ fn type_needs_ordered_drop_inner<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, see
|
|||||||
// This type doesn't implement drop, so no side effects here.
|
// This type doesn't implement drop, so no side effects here.
|
||||||
// Check if any component type has any.
|
// Check if any component type has any.
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Tuple(_) => ty.tuple_fields().any(|ty| type_needs_ordered_drop_inner(cx, ty, seen)),
|
ty::Tuple(fields) => fields.iter().any(|ty| type_needs_ordered_drop_inner(cx, ty, seen)),
|
||||||
ty::Array(ty, _) => type_needs_ordered_drop_inner(cx, *ty, seen),
|
&ty::Array(ty, _) => type_needs_ordered_drop_inner(cx, ty, seen),
|
||||||
ty::Adt(adt, subs) => adt
|
ty::Adt(adt, subs) => adt
|
||||||
.all_fields()
|
.all_fields()
|
||||||
.map(|f| f.ty(cx.tcx, subs))
|
.map(|f| f.ty(cx.tcx, subs))
|
||||||
|
@ -142,7 +142,7 @@ fn is_interior_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Sp
|
|||||||
size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0)
|
size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0)
|
||||||
&& is_interior_mutable_type(cx, inner_ty, span)
|
&& is_interior_mutable_type(cx, inner_ty, span)
|
||||||
},
|
},
|
||||||
Tuple(..) => ty.tuple_fields().any(|ty| is_interior_mutable_type(cx, ty, span)),
|
Tuple(fields) => fields.iter().any(|ty| is_interior_mutable_type(cx, ty, span)),
|
||||||
Adt(def, substs) => {
|
Adt(def, substs) => {
|
||||||
// Special case for collections in `std` who's impl of `Hash` or `Ord` delegates to
|
// Special case for collections in `std` who's impl of `Hash` or `Ord` delegates to
|
||||||
// that of their type parameters. Note: we don't include `HashSet` and `HashMap`
|
// that of their type parameters. Note: we don't include `HashSet` and `HashMap`
|
||||||
|
@ -202,8 +202,8 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t
|
|||||||
|
|
||||||
// The type is known to be `!Send` and `!Copy`
|
// The type is known to be `!Send` and `!Copy`
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Tuple(_) => ty
|
ty::Tuple(fields) => fields
|
||||||
.tuple_fields()
|
.iter()
|
||||||
.all(|ty| ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait)),
|
.all(|ty| ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait)),
|
||||||
ty::Array(ty, _) | ty::Slice(ty) => ty_allowed_with_raw_pointer_heuristic(cx, *ty, send_trait),
|
ty::Array(ty, _) | ty::Slice(ty) => ty_allowed_with_raw_pointer_heuristic(cx, *ty, send_trait),
|
||||||
ty::Adt(_, substs) => {
|
ty::Adt(_, substs) => {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use rustc_hir::Expr;
|
use rustc_hir::Expr;
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::ty::subst::{GenericArg, Subst};
|
use rustc_middle::ty::subst::Subst;
|
||||||
use rustc_middle::ty::{self, Ty, TypeAndMut};
|
use rustc_middle::ty::{self, Ty, TypeAndMut};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
@ -246,11 +246,10 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
|
|||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
ty::Tuple(args) => {
|
ty::Tuple(args) => {
|
||||||
let mut iter = args.iter().map(GenericArg::expect_ty);
|
let Some(sized_ty) = args.iter().find(|&ty| !is_zero_sized_ty(cx, ty)) else {
|
||||||
let Some(sized_ty) = iter.find(|ty| !is_zero_sized_ty(cx, *ty)) else {
|
|
||||||
return ReducedTy::OrderedFields(ty);
|
return ReducedTy::OrderedFields(ty);
|
||||||
};
|
};
|
||||||
if iter.all(|ty| is_zero_sized_ty(cx, ty)) {
|
if args.iter().all(|ty| is_zero_sized_ty(cx, ty)) {
|
||||||
ty = sized_ty;
|
ty = sized_ty;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
|||||||
// because we don't want to lint functions returning empty arrays
|
// because we don't want to lint functions returning empty arrays
|
||||||
is_must_use_ty(cx, *ty)
|
is_must_use_ty(cx, *ty)
|
||||||
},
|
},
|
||||||
ty::Tuple(substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
|
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
|
||||||
ty::Opaque(ref def_id, _) => {
|
ty::Opaque(ref def_id, _) => {
|
||||||
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
|
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
|
||||||
if let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() {
|
if let ty::PredicateKind::Trait(trait_predicate) = predicate.kind().skip_binder() {
|
||||||
@ -249,11 +249,11 @@ pub fn is_non_aggregate_primitive_type(ty: Ty<'_>) -> bool {
|
|||||||
/// Returns `true` if the given type is a primitive (a `bool` or `char`, any integer or
|
/// Returns `true` if 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).
|
/// floating-point number type, a `str`, or an array, slice, or tuple of those types).
|
||||||
pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool {
|
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::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::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),
|
ty::Tuple(inner_types) => inner_types.iter().all(is_recursively_primitive_type),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -393,9 +393,9 @@ pub fn same_type_and_consts<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
|
|||||||
|
|
||||||
/// Checks if a given type looks safe to be uninitialized.
|
/// Checks if a given type looks safe to be uninitialized.
|
||||||
pub fn is_uninit_value_valid_for_ty(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
|
pub fn is_uninit_value_valid_for_ty(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
|
||||||
match ty.kind() {
|
match *ty.kind() {
|
||||||
ty::Array(component, _) => is_uninit_value_valid_for_ty(cx, *component),
|
ty::Array(component, _) => is_uninit_value_valid_for_ty(cx, component),
|
||||||
ty::Tuple(types) => types.types().all(|ty| is_uninit_value_valid_for_ty(cx, ty)),
|
ty::Tuple(types) => types.iter().all(|ty| is_uninit_value_valid_for_ty(cx, ty)),
|
||||||
ty::Adt(adt, _) => cx.tcx.lang_items().maybe_uninit() == Some(adt.did),
|
ty::Adt(adt, _) => cx.tcx.lang_items().maybe_uninit() == Some(adt.did),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@ -426,8 +426,8 @@ impl<'tcx> ExprFnSig<'tcx> {
|
|||||||
pub fn input(self, i: usize) -> Binder<'tcx, Ty<'tcx>> {
|
pub fn input(self, i: usize) -> Binder<'tcx, Ty<'tcx>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Sig(sig) => sig.input(i),
|
Self::Sig(sig) => sig.input(i),
|
||||||
Self::Closure(sig) => sig.input(0).map_bound(|ty| ty.tuple_element_ty(i).unwrap()),
|
Self::Closure(sig) => sig.input(0).map_bound(|ty| ty.tuple_fields()[i]),
|
||||||
Self::Trait(inputs, _) => inputs.map_bound(|ty| ty.tuple_element_ty(i).unwrap()),
|
Self::Trait(inputs, _) => inputs.map_bound(|ty| ty.tuple_fields()[i]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user