Skip to content

Commit cb06e91

Browse files
committed
Don't use use ty::TyKind::*
1 parent 235fa50 commit cb06e91

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

clippy_lints/src/functions.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -497,18 +497,17 @@ fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, tys: &mut FxHash
497497
static KNOWN_WRAPPER_TYS: &[&[&str]] = &[&["alloc", "rc", "Rc"], &["std", "sync", "Arc"]];
498498

499499
fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut FxHashSet<DefId>) -> bool {
500-
use ty::TyKind::{Adt, Array, Bool, Char, Float, Int, RawPtr, Ref, Slice, Str, Tuple, Uint};
501500
match ty.kind {
502501
// primitive types are never mutable
503-
Bool | Char | Int(_) | Uint(_) | Float(_) | Str => false,
504-
Adt(ref adt, ref substs) => {
502+
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false,
503+
ty::Adt(ref adt, ref substs) => {
505504
tys.insert(adt.did) && !ty.is_freeze(cx.tcx, cx.param_env, span)
506505
|| KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path))
507506
&& substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys))
508507
},
509-
Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
510-
Array(ty, _) | Slice(ty) => is_mutable_ty(cx, ty, span, tys),
511-
RawPtr(ty::TypeAndMut { ty, mutbl }) | Ref(_, ty, mutbl) => {
508+
ty::Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
509+
ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, span, tys),
510+
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => {
512511
mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, span, tys)
513512
},
514513
// calling something constitutes a side effect, so return true on all callables

clippy_lints/src/utils/mod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1292,17 +1292,19 @@ pub fn must_use_attr(attrs: &[Attribute]) -> Option<&Attribute> {
12921292

12931293
// Returns whether the type has #[must_use] attribute
12941294
pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
1295-
use ty::TyKind::{Adt, Array, Dynamic, Foreign, Opaque, RawPtr, Ref, Slice, Tuple};
12961295
match ty.kind {
1297-
Adt(ref adt, _) => must_use_attr(&cx.tcx.get_attrs(adt.did)).is_some(),
1298-
Foreign(ref did) => must_use_attr(&cx.tcx.get_attrs(*did)).is_some(),
1299-
Slice(ref ty) | Array(ref ty, _) | RawPtr(ty::TypeAndMut { ref ty, .. }) | Ref(_, ref ty, _) => {
1296+
ty::Adt(ref adt, _) => must_use_attr(&cx.tcx.get_attrs(adt.did)).is_some(),
1297+
ty::Foreign(ref did) => must_use_attr(&cx.tcx.get_attrs(*did)).is_some(),
1298+
ty::Slice(ref ty)
1299+
| ty::Array(ref ty, _)
1300+
| ty::RawPtr(ty::TypeAndMut { ref ty, .. })
1301+
| ty::Ref(_, ref ty, _) => {
13001302
// for the Array case we don't need to care for the len == 0 case
13011303
// because we don't want to lint functions returning empty arrays
13021304
is_must_use_ty(cx, *ty)
13031305
},
1304-
Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
1305-
Opaque(ref def_id, _) => {
1306+
ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)),
1307+
ty::Opaque(ref def_id, _) => {
13061308
for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates {
13071309
if let ty::Predicate::Trait(ref poly_trait_predicate, _) = predicate {
13081310
if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() {
@@ -1312,7 +1314,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo
13121314
}
13131315
false
13141316
},
1315-
Dynamic(binder, _) => {
1317+
ty::Dynamic(binder, _) => {
13161318
for predicate in binder.skip_binder().iter() {
13171319
if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate {
13181320
if must_use_attr(&cx.tcx.get_attrs(trait_ref.def_id)).is_some() {

0 commit comments

Comments
 (0)