Rollup merge of #110398 - matthiaskrgr:clippy_match, r=Nilstrieb,fee1-dead
use matches! macro in more places r? `@Nilstrieb`
This commit is contained in:
commit
fba49a7ee2
@ -1298,17 +1298,17 @@ pub fn take(&mut self) -> Self {
|
||||
|
||||
/// To a first-order approximation, is this a pattern?
|
||||
pub fn is_approximately_pattern(&self) -> bool {
|
||||
match &self.peel_parens().kind {
|
||||
matches!(
|
||||
&self.peel_parens().kind,
|
||||
ExprKind::Array(_)
|
||||
| ExprKind::Call(_, _)
|
||||
| ExprKind::Tup(_)
|
||||
| ExprKind::Lit(_)
|
||||
| ExprKind::Range(_, _, _)
|
||||
| ExprKind::Underscore
|
||||
| ExprKind::Path(_, _)
|
||||
| ExprKind::Struct(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
| ExprKind::Call(_, _)
|
||||
| ExprKind::Tup(_)
|
||||
| ExprKind::Lit(_)
|
||||
| ExprKind::Range(_, _, _)
|
||||
| ExprKind::Underscore
|
||||
| ExprKind::Path(_, _)
|
||||
| ExprKind::Struct(_)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,10 +332,7 @@ enum FnDeclKind {
|
||||
|
||||
impl FnDeclKind {
|
||||
fn param_impl_trait_allowed(&self) -> bool {
|
||||
match self {
|
||||
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait)
|
||||
}
|
||||
|
||||
fn return_impl_trait_allowed(&self, tcx: TyCtxt<'_>) -> bool {
|
||||
|
@ -234,10 +234,7 @@ pub fn ns(&self) -> Option<Namespace> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_fn_like(self) -> bool {
|
||||
match self {
|
||||
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator)
|
||||
}
|
||||
|
||||
/// Whether `query get_codegen_attrs` should be used with this definition.
|
||||
|
@ -1457,10 +1457,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
|
||||
}
|
||||
|
||||
fn is_foreign_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
match tcx.hir().get_by_def_id(def_id) {
|
||||
Node::ForeignItem(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(tcx.hir().get_by_def_id(def_id), Node::ForeignItem(..))
|
||||
}
|
||||
|
||||
fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::GeneratorKind> {
|
||||
|
@ -1735,10 +1735,8 @@ fn check_expr_struct_fields(
|
||||
} else {
|
||||
self.check_expr_has_type_or_error(base_expr, adt_ty, |_| {
|
||||
let base_ty = self.typeck_results.borrow().expr_ty(*base_expr);
|
||||
let same_adt = match (adt_ty.kind(), base_ty.kind()) {
|
||||
(ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true,
|
||||
_ => false,
|
||||
};
|
||||
let same_adt = matches!((adt_ty.kind(), base_ty.kind()),
|
||||
(ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt);
|
||||
if self.tcx.sess.is_nightly_build() && same_adt {
|
||||
feature_err(
|
||||
&self.tcx.sess.parse_sess,
|
||||
|
@ -312,13 +312,10 @@ pub fn suggest_new_region_bound(
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
} else if opaque.bounds.iter().any(|arg| match arg {
|
||||
GenericBound::Outlives(Lifetime { ident, .. })
|
||||
if ident.name.to_string() == lifetime_name =>
|
||||
{
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
} else if opaque.bounds.iter().any(|arg| {
|
||||
matches!(arg,
|
||||
GenericBound::Outlives(Lifetime { ident, .. })
|
||||
if ident.name.to_string() == lifetime_name )
|
||||
}) {
|
||||
} else {
|
||||
// get a lifetime name of existing named lifetimes if any
|
||||
|
@ -1577,10 +1577,10 @@ pub fn is_ty_infer_var_definitely_unchanged<'a>(
|
||||
(TyOrConstInferVar::Ty(ty_var), Ok(inner)) => {
|
||||
use self::type_variable::TypeVariableValue;
|
||||
|
||||
match inner.try_type_variables_probe_ref(ty_var) {
|
||||
Some(TypeVariableValue::Unknown { .. }) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
inner.try_type_variables_probe_ref(ty_var),
|
||||
Some(TypeVariableValue::Unknown { .. })
|
||||
)
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
@ -89,10 +89,10 @@ pub fn without_const(mut self, tcx: TyCtxt<'tcx>) -> PredicateObligation<'tcx> {
|
||||
impl<'tcx> TraitObligation<'tcx> {
|
||||
/// Returns `true` if the trait predicate is considered `const` in its ParamEnv.
|
||||
pub fn is_const(&self) -> bool {
|
||||
match (self.predicate.skip_binder().constness, self.param_env.constness()) {
|
||||
(ty::BoundConstness::ConstIfConst, hir::Constness::Const) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
(self.predicate.skip_binder().constness, self.param_env.constness()),
|
||||
(ty::BoundConstness::ConstIfConst, hir::Constness::Const)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn derived_cause(
|
||||
|
@ -384,13 +384,8 @@ fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'_, ErrorGua
|
||||
diag.span_note(span, fluent::mir_build_def_note);
|
||||
}
|
||||
|
||||
let is_variant_list_non_exhaustive = match self.ty.kind() {
|
||||
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local() => {
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
||||
let is_variant_list_non_exhaustive = matches!(self.ty.kind(),
|
||||
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local());
|
||||
if is_variant_list_non_exhaustive {
|
||||
diag.note(fluent::mir_build_non_exhaustive_type_note);
|
||||
} else {
|
||||
|
@ -671,10 +671,8 @@ fn non_exhaustive_match<'p, 'tcx>(
|
||||
};
|
||||
};
|
||||
|
||||
let is_variant_list_non_exhaustive = match scrut_ty.kind() {
|
||||
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local() => true,
|
||||
_ => false,
|
||||
};
|
||||
let is_variant_list_non_exhaustive = matches!(scrut_ty.kind(),
|
||||
ty::Adt(def, _) if def.is_variant_list_non_exhaustive() && !def.did().is_local());
|
||||
|
||||
adt_defined_here(cx, &mut err, scrut_ty, &witnesses);
|
||||
err.note(&format!(
|
||||
|
@ -2577,14 +2577,12 @@ fn is_named_param(&self) -> bool {
|
||||
}
|
||||
|
||||
fn recover_self_param(&mut self) -> bool {
|
||||
match self
|
||||
.parse_outer_attributes()
|
||||
.and_then(|_| self.parse_self_param())
|
||||
.map_err(|e| e.cancel())
|
||||
{
|
||||
Ok(Some(_)) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
self.parse_outer_attributes()
|
||||
.and_then(|_| self.parse_self_param())
|
||||
.map_err(|e| e.cancel()),
|
||||
Ok(Some(_))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,10 @@ impl<'a> Parser<'a> {
|
||||
pub fn nonterminal_may_begin_with(kind: NonterminalKind, token: &Token) -> bool {
|
||||
/// Checks whether the non-terminal may contain a single (non-keyword) identifier.
|
||||
fn may_be_ident(nt: &token::Nonterminal) -> bool {
|
||||
match *nt {
|
||||
token::NtItem(_) | token::NtBlock(_) | token::NtVis(_) | token::NtLifetime(_) => {
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
}
|
||||
!matches!(
|
||||
*nt,
|
||||
token::NtItem(_) | token::NtBlock(_) | token::NtVis(_) | token::NtLifetime(_)
|
||||
)
|
||||
}
|
||||
|
||||
match kind {
|
||||
|
@ -663,15 +663,17 @@ pub(crate) fn into_struct_error(
|
||||
Ident::with_dummy_span(name),
|
||||
Namespace::ValueNS,
|
||||
&parent_scope,
|
||||
&|res: Res| match res {
|
||||
Res::Def(
|
||||
DefKind::Ctor(CtorOf::Variant, CtorKind::Const)
|
||||
| DefKind::Ctor(CtorOf::Struct, CtorKind::Const)
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst,
|
||||
_,
|
||||
) => true,
|
||||
_ => false,
|
||||
&|res: Res| {
|
||||
matches!(
|
||||
res,
|
||||
Res::Def(
|
||||
DefKind::Ctor(CtorOf::Variant, CtorKind::Const)
|
||||
| DefKind::Ctor(CtorOf::Struct, CtorKind::Const)
|
||||
| DefKind::Const
|
||||
| DefKind::AssocConst,
|
||||
_,
|
||||
)
|
||||
)
|
||||
},
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user