Rollup merge of #110398 - matthiaskrgr:clippy_match, r=Nilstrieb,fee1-dead

use matches! macro in more places

r? `@Nilstrieb`
This commit is contained in:
fee1-dead 2023-04-16 19:36:02 +08:00 committed by GitHub
commit fba49a7ee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 52 additions and 75 deletions

View File

@ -1298,7 +1298,8 @@ impl Expr {
/// To a first-order approximation, is this a pattern? /// To a first-order approximation, is this a pattern?
pub fn is_approximately_pattern(&self) -> bool { pub fn is_approximately_pattern(&self) -> bool {
match &self.peel_parens().kind { matches!(
&self.peel_parens().kind,
ExprKind::Array(_) ExprKind::Array(_)
| ExprKind::Call(_, _) | ExprKind::Call(_, _)
| ExprKind::Tup(_) | ExprKind::Tup(_)
@ -1306,9 +1307,8 @@ impl Expr {
| ExprKind::Range(_, _, _) | ExprKind::Range(_, _, _)
| ExprKind::Underscore | ExprKind::Underscore
| ExprKind::Path(_, _) | ExprKind::Path(_, _)
| ExprKind::Struct(_) => true, | ExprKind::Struct(_)
_ => false, )
}
} }
} }

View File

@ -332,10 +332,7 @@ enum FnDeclKind {
impl FnDeclKind { impl FnDeclKind {
fn param_impl_trait_allowed(&self) -> bool { fn param_impl_trait_allowed(&self) -> bool {
match self { matches!(self, FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait)
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => true,
_ => false,
}
} }
fn return_impl_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool { fn return_impl_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool {

View File

@ -234,10 +234,7 @@ impl DefKind {
#[inline] #[inline]
pub fn is_fn_like(self) -> bool { pub fn is_fn_like(self) -> bool {
match self { matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator)
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator => true,
_ => false,
}
} }
/// Whether `query get_codegen_attrs` should be used with this definition. /// Whether `query get_codegen_attrs` should be used with this definition.

View File

@ -1457,10 +1457,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
} }
fn is_foreign_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { fn is_foreign_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
match tcx.hir().get_by_def_id(def_id) { matches!(tcx.hir().get_by_def_id(def_id), Node::ForeignItem(..))
Node::ForeignItem(..) => true,
_ => false,
}
} }
fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::GeneratorKind> { fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::GeneratorKind> {

View File

@ -1735,10 +1735,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else { } else {
self.check_expr_has_type_or_error(base_expr, adt_ty, |_| { self.check_expr_has_type_or_error(base_expr, adt_ty, |_| {
let base_ty = self.typeck_results.borrow().expr_ty(*base_expr); let base_ty = self.typeck_results.borrow().expr_ty(*base_expr);
let same_adt = match (adt_ty.kind(), base_ty.kind()) { let same_adt = matches!((adt_ty.kind(), base_ty.kind()),
(ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true, (ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt);
_ => false,
};
if self.tcx.sess.is_nightly_build() && same_adt { if self.tcx.sess.is_nightly_build() && same_adt {
feature_err( feature_err(
&self.tcx.sess.parse_sess, &self.tcx.sess.parse_sess,

View File

@ -312,13 +312,10 @@ pub fn suggest_new_region_bound(
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );
} }
} else if opaque.bounds.iter().any(|arg| match arg { } else if opaque.bounds.iter().any(|arg| {
matches!(arg,
GenericBound::Outlives(Lifetime { ident, .. }) GenericBound::Outlives(Lifetime { ident, .. })
if ident.name.to_string() == lifetime_name => if ident.name.to_string() == lifetime_name )
{
true
}
_ => false,
}) { }) {
} else { } else {
// get a lifetime name of existing named lifetimes if any // get a lifetime name of existing named lifetimes if any

View File

@ -1577,10 +1577,10 @@ impl<'tcx> InferCtxt<'tcx> {
(TyOrConstInferVar::Ty(ty_var), Ok(inner)) => { (TyOrConstInferVar::Ty(ty_var), Ok(inner)) => {
use self::type_variable::TypeVariableValue; use self::type_variable::TypeVariableValue;
match inner.try_type_variables_probe_ref(ty_var) { matches!(
Some(TypeVariableValue::Unknown { .. }) => true, inner.try_type_variables_probe_ref(ty_var),
_ => false, Some(TypeVariableValue::Unknown { .. })
} )
} }
_ => false, _ => false,
}; };

View File

@ -89,10 +89,10 @@ impl<'tcx> PredicateObligation<'tcx> {
impl<'tcx> TraitObligation<'tcx> { impl<'tcx> TraitObligation<'tcx> {
/// Returns `true` if the trait predicate is considered `const` in its ParamEnv. /// Returns `true` if the trait predicate is considered `const` in its ParamEnv.
pub fn is_const(&self) -> bool { pub fn is_const(&self) -> bool {
match (self.predicate.skip_binder().constness, self.param_env.constness()) { matches!(
(ty::BoundConstness::ConstIfConst, hir::Constness::Const) => true, (self.predicate.skip_binder().constness, self.param_env.constness()),
_ => false, (ty::BoundConstness::ConstIfConst, hir::Constness::Const)
} )
} }
pub fn derived_cause( pub fn derived_cause(

View File

@ -384,13 +384,8 @@ impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
diag.span_note(span, fluent::mir_build_def_note); diag.span_note(span, fluent::mir_build_def_note);
} }
let is_variant_list_non_exhaustive = match self.ty.kind() { let is_variant_list_non_exhaustive = matches!(self.ty.kind(),
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local() => { ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local());
true
}
_ => false,
};
if is_variant_list_non_exhaustive { if is_variant_list_non_exhaustive {
diag.note(fluent::mir_build_non_exhaustive_type_note); diag.note(fluent::mir_build_non_exhaustive_type_note);
} else { } else {

View File

@ -671,10 +671,8 @@ fn non_exhaustive_match<'p, 'tcx>(
}; };
}; };
let is_variant_list_non_exhaustive = match scrut_ty.kind() { let is_variant_list_non_exhaustive = matches!(scrut_ty.kind(),
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local() => true, ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local());
_ => false,
};
adt_defined_here(cx, &mut err, scrut_ty, &witnesses); adt_defined_here(cx, &mut err, scrut_ty, &witnesses);
err.note(&format!( err.note(&format!(

View File

@ -2577,14 +2577,12 @@ impl<'a> Parser<'a> {
} }
fn recover_self_param(&mut self) -> bool { fn recover_self_param(&mut self) -> bool {
match self matches!(
.parse_outer_attributes() self.parse_outer_attributes()
.and_then(|_| self.parse_self_param()) .and_then(|_| self.parse_self_param())
.map_err(|e| e.cancel()) .map_err(|e| e.cancel()),
{ Ok(Some(_))
Ok(Some(_)) => true, )
_ => false,
}
} }
} }

View File

@ -20,12 +20,10 @@ impl<'a> Parser<'a> {
pub fn nonterminal_may_begin_with(kind: NonterminalKind, token: &Token) -> bool { pub fn nonterminal_may_begin_with(kind: NonterminalKind, token: &Token) -> bool {
/// Checks whether the non-terminal may contain a single (non-keyword) identifier. /// Checks whether the non-terminal may contain a single (non-keyword) identifier.
fn may_be_ident(nt: &token::Nonterminal) -> bool { fn may_be_ident(nt: &token::Nonterminal) -> bool {
match *nt { !matches!(
token::NtItem(_) | token::NtBlock(_) | token::NtVis(_) | token::NtLifetime(_) => { *nt,
false token::NtItem(_) | token::NtBlock(_) | token::NtVis(_) | token::NtLifetime(_)
} )
_ => true,
}
} }
match kind { match kind {

View File

@ -663,15 +663,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
Ident::with_dummy_span(name), Ident::with_dummy_span(name),
Namespace::ValueNS, Namespace::ValueNS,
&parent_scope, &parent_scope,
&|res: Res| match res { &|res: Res| {
matches!(
res,
Res::Def( Res::Def(
DefKind::Ctor(CtorOf::Variant, CtorKind::Const) DefKind::Ctor(CtorOf::Variant, CtorKind::Const)
| DefKind::Ctor(CtorOf::Struct, CtorKind::Const) | DefKind::Ctor(CtorOf::Struct, CtorKind::Const)
| DefKind::Const | DefKind::Const
| DefKind::AssocConst, | DefKind::AssocConst,
_, _,
) => true, )
_ => false, )
}, },
); );