Skip to content

Commit

Permalink
Rollup merge of #110398 - matthiaskrgr:clippy_match, r=Nilstrieb,fee1…
Browse files Browse the repository at this point in the history
…-dead

use matches! macro in more places

r? `@Nilstrieb`
  • Loading branch information
fee1-dead authored Apr 16, 2023
2 parents 508d661 + bcc15bb commit fba49a7
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 75 deletions.
20 changes: 10 additions & 10 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,17 +1298,17 @@ impl Expr {

/// 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(_)
)
}
}

Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,7 @@ impl DefKind {

#[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.
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,10 +1735,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,10 +1577,10 @@ impl<'tcx> InferCtxt<'tcx> {
(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,
};
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_infer/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ impl<'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(
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,8 @@ impl<'a> IntoDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_> {
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 {
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2577,14 +2577,12 @@ impl<'a> Parser<'a> {
}

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(_))
)
}
}

Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_parse/src/parser/nonterminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 11 additions & 9 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
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,
_,
)
)
},
);

Expand Down

0 comments on commit fba49a7

Please sign in to comment.