1
Fork 0

use matches!() macro in more places

This commit is contained in:
Matthias Krüger 2021-11-06 01:31:32 +01:00
parent 3cd3bbecc5
commit 0a5640b55f
21 changed files with 49 additions and 86 deletions

View file

@ -212,7 +212,8 @@ impl AssocOp {
/// parentheses while having a high degree of confidence on the correctness of the suggestion. /// parentheses while having a high degree of confidence on the correctness of the suggestion.
pub fn can_continue_expr_unambiguously(&self) -> bool { pub fn can_continue_expr_unambiguously(&self) -> bool {
use AssocOp::*; use AssocOp::*;
match self { matches!(
self,
BitXor | // `{ 42 } ^ 3` BitXor | // `{ 42 } ^ 3`
Assign | // `{ 42 } = { 42 }` Assign | // `{ 42 } = { 42 }`
Divide | // `{ 42 } / 42` Divide | // `{ 42 } / 42`
@ -225,9 +226,8 @@ impl AssocOp {
As | // `{ 42 } as usize` As | // `{ 42 } as usize`
// Equal | // `{ 42 } == { 42 }` Accepting these here would regress incorrect // Equal | // `{ 42 } == { 42 }` Accepting these here would regress incorrect
// NotEqual | // `{ 42 } != { 42 } struct literals parser recovery. // NotEqual | // `{ 42 } != { 42 } struct literals parser recovery.
Colon => true, // `{ 42 }: usize` Colon, // `{ 42 }: usize`
_ => false, )
}
} }
} }

View file

@ -53,10 +53,7 @@ pub(crate) enum LaterUseKind {
impl BorrowExplanation { impl BorrowExplanation {
pub(crate) fn is_explained(&self) -> bool { pub(crate) fn is_explained(&self) -> bool {
match self { !matches!(self, BorrowExplanation::Unexplained)
BorrowExplanation::Unexplained => false,
_ => true,
}
} }
pub(crate) fn add_explanation_to_diagnostic<'tcx>( pub(crate) fn add_explanation_to_diagnostic<'tcx>(
&self, &self,

View file

@ -2110,14 +2110,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
_ => constraint_sup_scc != target_scc, _ => constraint_sup_scc != target_scc,
} }
} else { } else {
match categorized_path[*i].category { !matches!(
categorized_path[*i].category,
ConstraintCategory::OpaqueType ConstraintCategory::OpaqueType
| ConstraintCategory::Boring | ConstraintCategory::Boring
| ConstraintCategory::BoringNoLocation | ConstraintCategory::BoringNoLocation
| ConstraintCategory::Internal | ConstraintCategory::Internal
| ConstraintCategory::Predicate(_) => false, | ConstraintCategory::Predicate(_)
_ => true, )
}
} }
}; };

View file

@ -138,17 +138,11 @@ impl<'tcx> DefiningTy<'tcx> {
} }
pub fn is_fn_def(&self) -> bool { pub fn is_fn_def(&self) -> bool {
match *self { matches!(*self, DefiningTy::FnDef(..))
DefiningTy::FnDef(..) => true,
_ => false,
}
} }
pub fn is_const(&self) -> bool { pub fn is_const(&self) -> bool {
match *self { matches!(*self, DefiningTy::Const(..))
DefiningTy::Const(..) => true,
_ => false,
}
} }
pub fn def_id(&self) -> DefId { pub fn def_id(&self) -> DefId {

View file

@ -124,10 +124,7 @@ fn push_debuginfo_type_name<'tcx>(
// info for MSVC debugger. However, wrapping these types' names in a synthetic type // info for MSVC debugger. However, wrapping these types' names in a synthetic type
// causes the .natvis engine for WinDbg to fail to display their data, so we opt these // causes the .natvis engine for WinDbg to fail to display their data, so we opt these
// types out to aid debugging in MSVC. // types out to aid debugging in MSVC.
let is_slice_or_str = match *inner_type.kind() { let is_slice_or_str = matches!(*inner_type.kind(), ty::Slice(_) | ty::Str);
ty::Slice(_) | ty::Str => true,
_ => false,
};
if !cpp_like_names { if !cpp_like_names {
output.push('&'); output.push('&');

View file

@ -25,10 +25,7 @@ pub enum ConstEvalErrKind {
impl MachineStopType for ConstEvalErrKind { impl MachineStopType for ConstEvalErrKind {
fn is_hard_err(&self) -> bool { fn is_hard_err(&self) -> bool {
match self { matches!(self, Self::Panic { .. })
Self::Panic { .. } => true,
_ => false,
}
} }
} }

View file

@ -51,10 +51,8 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
// If the function itself is not annotated with `const`, it may still be a `const fn` // If the function itself is not annotated with `const`, it may still be a `const fn`
// if it resides in a const trait impl. // if it resides in a const trait impl.
is_parent_const_impl_raw(tcx, hir_id) is_parent_const_impl_raw(tcx, hir_id)
} else if let hir::Node::Ctor(_) = node {
true
} else { } else {
false matches!(node, hir::Node::Ctor(_))
} }
} }

View file

@ -138,10 +138,8 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
args: &[GenericArg<'tcx>], args: &[GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> { ) -> Result<Self::Path, Self::Error> {
self = print_prefix(self)?; self = print_prefix(self)?;
let args = args.iter().cloned().filter(|arg| match arg.unpack() { let args =
GenericArgKind::Lifetime(_) => false, args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
_ => true,
});
if args.clone().next().is_some() { if args.clone().next().is_some() {
self.generic_delimiters(|cx| cx.comma_sep(args)) self.generic_delimiters(|cx| cx.comma_sep(args))
} else { } else {

View file

@ -345,10 +345,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// Figure out how to pass which arguments. // Figure out how to pass which arguments.
// The Rust ABI is special: ZST get skipped. // The Rust ABI is special: ZST get skipped.
let rust_abi = match caller_abi { let rust_abi = matches!(caller_abi, Abi::Rust | Abi::RustCall);
Abi::Rust | Abi::RustCall => true,
_ => false,
};
// We have two iterators: Where the arguments come from, // We have two iterators: Where the arguments come from,
// and where they go to. // and where they go to.

View file

@ -131,10 +131,7 @@ impl Qualifs<'mir, 'tcx> {
.body .body
.basic_blocks() .basic_blocks()
.iter_enumerated() .iter_enumerated()
.find(|(_, block)| match block.terminator().kind { .find(|(_, block)| matches!(block.terminator().kind, TerminatorKind::Return))
TerminatorKind::Return => true,
_ => false,
})
.map(|(bb, _)| bb); .map(|(bb, _)| bb);
let return_block = match return_block { let return_block = match return_block {

View file

@ -170,11 +170,12 @@ impl Qualif for NeedsNonConstDrop {
let mut selcx = SelectionContext::with_constness(&infcx, hir::Constness::Const); let mut selcx = SelectionContext::with_constness(&infcx, hir::Constness::Const);
selcx.select(&obligation) selcx.select(&obligation)
}); });
match implsrc { !matches!(
Ok(Some(ImplSource::ConstDrop(_))) implsrc,
| Ok(Some(ImplSource::Param(_, ty::BoundConstness::ConstIfConst))) => false, Ok(Some(
_ => true, ImplSource::ConstDrop(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
} ))
)
} }
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool { fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {

View file

@ -68,11 +68,10 @@ pub enum EscapeError {
impl EscapeError { impl EscapeError {
/// Returns true for actual errors, as opposed to warnings. /// Returns true for actual errors, as opposed to warnings.
pub fn is_fatal(&self) -> bool { pub fn is_fatal(&self) -> bool {
match self { !matches!(
EscapeError::UnskippedWhitespaceWarning => false, self,
EscapeError::MultipleSkippedLinesWarning => false, EscapeError::UnskippedWhitespaceWarning | EscapeError::MultipleSkippedLinesWarning
_ => true, )
}
} }
} }

View file

@ -538,12 +538,12 @@ impl InterpError<'_> {
/// To avoid performance issues, there are places where we want to be sure to never raise these formatting errors, /// To avoid performance issues, there are places where we want to be sure to never raise these formatting errors,
/// so this method lets us detect them and `bug!` on unexpected errors. /// so this method lets us detect them and `bug!` on unexpected errors.
pub fn formatted_string(&self) -> bool { pub fn formatted_string(&self) -> bool {
match self { matches!(
self,
InterpError::Unsupported(UnsupportedOpInfo::Unsupported(_)) InterpError::Unsupported(UnsupportedOpInfo::Unsupported(_))
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::ValidationFailure { .. }) | InterpError::UndefinedBehavior(UndefinedBehaviorInfo::ValidationFailure { .. })
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::Ub(_)) => true, | InterpError::UndefinedBehavior(UndefinedBehaviorInfo::Ub(_))
_ => false, )
}
} }
/// Should this error be reported as a hard error, preventing compilation, or a soft error, /// Should this error be reported as a hard error, preventing compilation, or a soft error,

View file

@ -485,7 +485,7 @@ fn inject_statement(
// Non-code expressions are injected into the coverage map, without generating executable code. // Non-code expressions are injected into the coverage map, without generating executable code.
fn inject_intermediate_expression(mir_body: &mut mir::Body<'tcx>, expression: CoverageKind) { fn inject_intermediate_expression(mir_body: &mut mir::Body<'tcx>, expression: CoverageKind) {
debug_assert!(if let CoverageKind::Expression { .. } = expression { true } else { false }); debug_assert!(matches!(expression, CoverageKind::Expression { .. }));
debug!(" injecting non-code expression {:?}", expression); debug!(" injecting non-code expression {:?}", expression);
let inject_in_bb = mir::START_BLOCK; let inject_in_bb = mir::START_BLOCK;
let data = &mut mir_body[inject_in_bb]; let data = &mut mir_body[inject_in_bb];

View file

@ -94,10 +94,9 @@ impl CoverageSpan {
stmt_index: usize, stmt_index: usize,
) -> Self { ) -> Self {
let is_closure = match statement.kind { let is_closure = match statement.kind {
StatementKind::Assign(box (_, Rvalue::Aggregate(box ref kind, _))) => match kind { StatementKind::Assign(box (_, Rvalue::Aggregate(box ref kind, _))) => {
AggregateKind::Closure(_, _) | AggregateKind::Generator(_, _, _) => true, matches!(kind, AggregateKind::Closure(_, _) | AggregateKind::Generator(_, _, _))
_ => false, }
},
_ => false, _ => false,
}; };

View file

@ -27,9 +27,8 @@ impl MirPass<'_> for UnreachablePropagation {
// This is a temporary solution that handles possibly diverging asm statements. // This is a temporary solution that handles possibly diverging asm statements.
// Accompanying testcases: mir-opt/unreachable_asm.rs and mir-opt/unreachable_asm_2.rs // Accompanying testcases: mir-opt/unreachable_asm.rs and mir-opt/unreachable_asm_2.rs
let asm_stmt_in_block = || { let asm_stmt_in_block = || {
bb_data.statements.iter().any(|stmt: &Statement<'_>| match stmt.kind { bb_data.statements.iter().any(|stmt: &Statement<'_>| {
StatementKind::LlvmInlineAsm(..) => true, matches!(stmt.kind, StatementKind::LlvmInlineAsm(..))
_ => false,
}) })
}; };

View file

@ -320,10 +320,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
/// Returns `true` if the trait predicate is considerd `const` to this selection context. /// Returns `true` if the trait predicate is considerd `const` to this selection context.
pub fn is_trait_predicate_const(&self, pred: ty::TraitPredicate<'_>) -> bool { pub fn is_trait_predicate_const(&self, pred: ty::TraitPredicate<'_>) -> bool {
match pred.constness { matches!(pred.constness, ty::BoundConstness::ConstIfConst) && self.is_in_const_context
ty::BoundConstness::ConstIfConst if self.is_in_const_context => true,
_ => false,
}
} }
/// Returns `true` if the predicate is considered `const` to /// Returns `true` if the predicate is considered `const` to

View file

@ -436,11 +436,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
// Very crude check to see whether the expression must be wrapped // Very crude check to see whether the expression must be wrapped
// in parentheses for the suggestion to work (issue #89497). // in parentheses for the suggestion to work (issue #89497).
// Can/should be extended in the future. // Can/should be extended in the future.
let needs_parens = !has_parens let needs_parens =
&& match self.expr.kind { !has_parens && matches!(self.expr.kind, hir::ExprKind::Cast(..));
hir::ExprKind::Cast(..) => true,
_ => false,
};
let mut suggestion = vec![(self.expr.span.shrink_to_lo(), sugg)]; let mut suggestion = vec![(self.expr.span.shrink_to_lo(), sugg)];
if needs_parens { if needs_parens {

View file

@ -300,7 +300,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
hir::TyKind::Path(hir::QPath::Resolved( hir::TyKind::Path(hir::QPath::Resolved(
None, None,
hir::Path { res: hir::def::Res::Def(_, id), .. }, hir::Path { res: hir::def::Res::Def(_, id), .. },
)) if *id == def_id => true, )) => *id == def_id,
_ => false, _ => false,
}) })
}) })

View file

@ -878,12 +878,7 @@ impl Ipv4Addr {
#[must_use] #[must_use]
#[inline] #[inline]
pub const fn is_documentation(&self) -> bool { pub const fn is_documentation(&self) -> bool {
match self.octets() { matches!(self.octets(), [192, 0, 2, _] | [198, 51, 100, _] | [203, 0, 113, _])
[192, 0, 2, _] => true,
[198, 51, 100, _] => true,
[203, 0, 113, _] => true,
_ => false,
}
} }
/// Converts this address to an [IPv4-compatible] [`IPv6` address]. /// Converts this address to an [IPv4-compatible] [`IPv6` address].

View file

@ -159,7 +159,7 @@ impl SocketAddr {
#[must_use] #[must_use]
#[stable(feature = "unix_socket", since = "1.10.0")] #[stable(feature = "unix_socket", since = "1.10.0")]
pub fn is_unnamed(&self) -> bool { pub fn is_unnamed(&self) -> bool {
if let AddressKind::Unnamed = self.address() { true } else { false } matches!(self.address(), AddressKind::Unnamed)
} }
/// Returns the contents of this address if it is a `pathname` address. /// Returns the contents of this address if it is a `pathname` address.