Don't use matches! when == suffices
In the codebase we sometimes use `matches!` for values that can actually just be compared. Replace them with `==`.
This commit is contained in:
parent
04813e4de8
commit
9f566f2463
23 changed files with 32 additions and 36 deletions
|
|
@ -251,7 +251,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
|
|||
let mut transient = DenseBitSet::new_filled(ccx.body.local_decls.len());
|
||||
// Make sure to only visit reachable blocks, the dataflow engine can ICE otherwise.
|
||||
for (bb, data) in traversal::reachable(&ccx.body) {
|
||||
if matches!(data.terminator().kind, TerminatorKind::Return) {
|
||||
if data.terminator().kind == TerminatorKind::Return {
|
||||
let location = ccx.body.terminator_loc(bb);
|
||||
maybe_storage_live.seek_after_primary_effect(location);
|
||||
// If a local may be live here, it is definitely not transient.
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ where
|
|||
// i.e., we treat all qualifs as non-structural for deref projections. Generally,
|
||||
// we can say very little about `*ptr` even if we know that `ptr` satisfies all
|
||||
// sorts of properties.
|
||||
if matches!(elem, ProjectionElem::Deref) {
|
||||
if elem == ProjectionElem::Deref {
|
||||
// We have to assume that this qualifies.
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
'tcx: 'y,
|
||||
{
|
||||
assert_eq!(callee_ty, callee_abi.layout.ty);
|
||||
if matches!(callee_abi.mode, PassMode::Ignore) {
|
||||
if callee_abi.mode == PassMode::Ignore {
|
||||
// This one is skipped. Still must be made live though!
|
||||
if !already_live {
|
||||
self.storage_live(callee_arg.as_local().unwrap())?;
|
||||
|
|
|
|||
|
|
@ -861,7 +861,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
}
|
||||
} else {
|
||||
// unsigned
|
||||
if matches!(mir_op, BinOp::Add) {
|
||||
if mir_op == BinOp::Add {
|
||||
// max unsigned
|
||||
Scalar::from_uint(size.unsigned_int_max(), size)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
return Err(ConstEvalErrKind::ConstMakeGlobalWithOffset(ptr)).into();
|
||||
}
|
||||
|
||||
if matches!(self.tcx.try_get_global_alloc(alloc_id), Some(_)) {
|
||||
if self.tcx.try_get_global_alloc(alloc_id).is_some() {
|
||||
// This points to something outside the current interpreter.
|
||||
return Err(ConstEvalErrKind::ConstMakeGlobalPtrIsNonHeap(ptr)).into();
|
||||
}
|
||||
|
|
@ -981,7 +981,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
msg: CheckInAllocMsg,
|
||||
) -> InterpResult<'tcx, (Size, Align)> {
|
||||
let info = self.get_alloc_info(id);
|
||||
if matches!(info.kind, AllocKind::Dead) {
|
||||
if info.kind == AllocKind::Dead {
|
||||
throw_ub!(PointerUseAfterFree(id, msg))
|
||||
}
|
||||
interp_ok((info.size, info.align))
|
||||
|
|
@ -1072,7 +1072,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
// Recurse, if there is data here.
|
||||
// Do this *before* invoking the callback, as the callback might mutate the
|
||||
// allocation and e.g. replace all provenance by wildcards!
|
||||
if matches!(info.kind, AllocKind::LiveData) {
|
||||
if info.kind == AllocKind::LiveData {
|
||||
let alloc = self.get_alloc_raw(id)?;
|
||||
for prov in alloc.provenance().provenances() {
|
||||
if let Some(id) = prov.get_alloc_id() {
|
||||
|
|
@ -1605,7 +1605,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
match self.ptr_try_get_alloc_id(ptr, 0) {
|
||||
Ok((alloc_id, offset, _)) => {
|
||||
let info = self.get_alloc_info(alloc_id);
|
||||
if matches!(info.kind, AllocKind::TypeId) {
|
||||
if info.kind == AllocKind::TypeId {
|
||||
// We *could* actually precisely answer this question since here,
|
||||
// the offset *is* the integer value. But the entire point of making
|
||||
// this a pointer is not to leak the integer value, so we say everything
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ pub(crate) fn check_trait_item<'tcx>(
|
|||
|
||||
let mut res = Ok(());
|
||||
|
||||
if matches!(tcx.def_kind(def_id), DefKind::AssocFn) {
|
||||
if tcx.def_kind(def_id) == DefKind::AssocFn {
|
||||
for &assoc_ty_def_id in
|
||||
tcx.associated_types_for_impl_traits_in_associated_fn(def_id.to_def_id())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -543,7 +543,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if matches!(def_kind, DefKind::AnonConst)
|
||||
if def_kind == DefKind::AnonConst
|
||||
&& tcx.features().generic_const_exprs()
|
||||
&& let Some(defaulted_param_def_id) =
|
||||
tcx.hir_opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id))
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// Don't write user type annotations for const param types, since we give them
|
||||
// identity args just so that we can trivially substitute their `EarlyBinder`.
|
||||
// We enforce that they match their type in MIR later on.
|
||||
if matches!(self.tcx.def_kind(def_id), DefKind::ConstParam) {
|
||||
if self.tcx.def_kind(def_id) == DefKind::ConstParam {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ impl<'tcx> Statement<'tcx> {
|
|||
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
|
||||
/// invalidating statement indices in `Location`s.
|
||||
pub fn make_nop(&mut self, drop_debuginfo: bool) {
|
||||
if matches!(self.kind, StatementKind::Nop) {
|
||||
if self.kind == StatementKind::Nop {
|
||||
return;
|
||||
}
|
||||
let replaced_stmt = std::mem::replace(&mut self.kind, StatementKind::Nop);
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ impl<'tcx> InhabitedPredicate<'tcx> {
|
|||
pub fn all(tcx: TyCtxt<'tcx>, iter: impl IntoIterator<Item = Self>) -> Self {
|
||||
let mut result = Self::True;
|
||||
for pred in iter {
|
||||
if matches!(pred, Self::False) {
|
||||
if pred == Self::False {
|
||||
return Self::False;
|
||||
}
|
||||
result = result.and(tcx, pred);
|
||||
|
|
@ -171,7 +171,7 @@ impl<'tcx> InhabitedPredicate<'tcx> {
|
|||
pub fn any(tcx: TyCtxt<'tcx>, iter: impl IntoIterator<Item = Self>) -> Self {
|
||||
let mut result = Self::False;
|
||||
for pred in iter {
|
||||
if matches!(pred, Self::True) {
|
||||
if pred == Self::True {
|
||||
return Self::True;
|
||||
}
|
||||
result = result.or(tcx, pred);
|
||||
|
|
|
|||
|
|
@ -3381,7 +3381,7 @@ define_print_and_forward_display! {
|
|||
fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, Namespace, DefId)) {
|
||||
// Iterate all (non-anonymous) local crate items no matter where they are defined.
|
||||
for id in tcx.hir_free_items() {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Use) {
|
||||
if tcx.def_kind(id.owner_id) == DefKind::Use {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1582,7 +1582,7 @@ impl<'v> RootCollector<'_, 'v> {
|
|||
}
|
||||
|
||||
fn process_impl_item(&mut self, id: hir::ImplItemId) {
|
||||
if matches!(self.tcx.def_kind(id.owner_id), DefKind::AssocFn) {
|
||||
if self.tcx.def_kind(id.owner_id) == DefKind::AssocFn {
|
||||
self.push_if_root(id.owner_id.def_id);
|
||||
}
|
||||
}
|
||||
|
|
@ -1720,7 +1720,7 @@ fn create_mono_items_for_default_impls<'tcx>(
|
|||
) {
|
||||
let impl_ = tcx.impl_trait_header(item.owner_id);
|
||||
|
||||
if matches!(impl_.polarity, ty::ImplPolarity::Negative) {
|
||||
if impl_.polarity == ty::ImplPolarity::Negative {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ fn eat_operand_keyword<'a>(
|
|||
exp: ExpKeywordPair,
|
||||
asm_macro: AsmMacro,
|
||||
) -> PResult<'a, bool> {
|
||||
if matches!(asm_macro, AsmMacro::Asm) {
|
||||
if asm_macro == AsmMacro::Asm {
|
||||
Ok(p.eat_keyword(exp))
|
||||
} else {
|
||||
let span = p.token.span;
|
||||
|
|
|
|||
|
|
@ -3100,7 +3100,7 @@ impl<'a> Parser<'a> {
|
|||
pub(crate) fn eat_label(&mut self) -> Option<Label> {
|
||||
if let Some((ident, is_raw)) = self.token.lifetime() {
|
||||
// Disallow `'fn`, but with a better error message than `expect_lifetime`.
|
||||
if matches!(is_raw, IdentIsRaw::No) && ident.without_first_quote().is_reserved() {
|
||||
if is_raw == IdentIsRaw::No && ident.without_first_quote().is_reserved() {
|
||||
self.dcx().emit_err(errors::KeywordLabel { span: ident.span });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2094,7 +2094,7 @@ impl<'a> Parser<'a> {
|
|||
/// for better diagnostics and suggestions.
|
||||
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
|
||||
let (ident, is_raw) = self.ident_or_err(true)?;
|
||||
if matches!(is_raw, IdentIsRaw::No) && ident.is_reserved() {
|
||||
if is_raw == IdentIsRaw::No && ident.is_reserved() {
|
||||
let snapshot = self.create_snapshot_for_diagnostic();
|
||||
let err = if self.check_fn_front_matter(false, Case::Sensitive) {
|
||||
let inherited_vis =
|
||||
|
|
|
|||
|
|
@ -472,7 +472,7 @@ impl<'a> Parser<'a> {
|
|||
fn parse_ident_common(&mut self, recover: bool) -> PResult<'a, Ident> {
|
||||
let (ident, is_raw) = self.ident_or_err(recover)?;
|
||||
|
||||
if matches!(is_raw, IdentIsRaw::No) && ident.is_reserved() {
|
||||
if is_raw == IdentIsRaw::No && ident.is_reserved() {
|
||||
let err = self.expected_ident_found_err();
|
||||
if recover {
|
||||
err.emit();
|
||||
|
|
|
|||
|
|
@ -1551,9 +1551,7 @@ impl<'a> Parser<'a> {
|
|||
/// Parses a single lifetime `'a` or panics.
|
||||
pub(super) fn expect_lifetime(&mut self) -> Lifetime {
|
||||
if let Some((ident, is_raw)) = self.token.lifetime() {
|
||||
if matches!(is_raw, IdentIsRaw::No)
|
||||
&& ident.without_first_quote().is_reserved_lifetime()
|
||||
{
|
||||
if is_raw == IdentIsRaw::No && ident.without_first_quote().is_reserved_lifetime() {
|
||||
self.dcx().emit_err(errors::KeywordLifetime { span: ident.span });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -523,7 +523,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
target: Target,
|
||||
item: Option<ItemLike<'_>>,
|
||||
) {
|
||||
if matches!(target, Target::Impl { of_trait: true }) {
|
||||
if target == (Target::Impl { of_trait: true }) {
|
||||
match item.unwrap() {
|
||||
ItemLike::Item(it) => match it.expect_impl().constness {
|
||||
Constness::Const => {}
|
||||
|
|
@ -1503,10 +1503,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
fn check_deprecated(&self, hir_id: HirId, attr_span: Span, target: Target) {
|
||||
match target {
|
||||
Target::AssocConst | Target::Method(..) | Target::AssocTy
|
||||
if matches!(
|
||||
self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id)),
|
||||
DefKind::Impl { of_trait: true }
|
||||
) =>
|
||||
if self.tcx.def_kind(self.tcx.local_parent(hir_id.owner.def_id))
|
||||
== DefKind::Impl { of_trait: true } =>
|
||||
{
|
||||
self.tcx.emit_node_span_lint(
|
||||
UNUSED_ATTRIBUTES,
|
||||
|
|
|
|||
|
|
@ -422,7 +422,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
|
|||
hir::ItemKind::Trait(.., trait_item_refs) => {
|
||||
// mark assoc ty live if the trait is live
|
||||
for trait_item in trait_item_refs {
|
||||
if matches!(self.tcx.def_kind(trait_item.owner_id), DefKind::AssocTy) {
|
||||
if self.tcx.def_kind(trait_item.owner_id) == DefKind::AssocTy {
|
||||
self.check_def_id(trait_item.owner_id.to_def_id());
|
||||
}
|
||||
}
|
||||
|
|
@ -1179,7 +1179,7 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
|
|||
// we have diagnosed them in the trait if they are unused,
|
||||
// for unused assoc items in unused trait,
|
||||
// we have diagnosed the unused trait.
|
||||
if matches!(def_kind, DefKind::Impl { of_trait: false })
|
||||
if def_kind == (DefKind::Impl { of_trait: false })
|
||||
|| (def_kind == DefKind::Trait && live_symbols.contains(&item.owner_id.def_id))
|
||||
{
|
||||
for &def_id in tcx.associated_item_def_ids(item.owner_id.def_id) {
|
||||
|
|
|
|||
|
|
@ -1140,7 +1140,7 @@ impl Target {
|
|||
Arch::AArch64 | Arch::Arm64EC => {
|
||||
// Aarch64 has no sane ABI specifier, and LLVM doesn't even have a way to force
|
||||
// the use of soft-float, so all we can do here is some crude hacks.
|
||||
if matches!(self.abi, Abi::SoftFloat) {
|
||||
if self.abi == Abi::SoftFloat {
|
||||
// LLVM will use float registers when `fp-armv8` is available, e.g. for
|
||||
// calls to built-ins. The only way to ensure a consistent softfloat ABI
|
||||
// on aarch64 is to never enable `fp-armv8`, so we enforce that.
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
let (def_id, args) = match *ty.kind() {
|
||||
ty::Alias(_, ty::AliasTy { def_id, args, .. })
|
||||
if matches!(self.tcx.def_kind(def_id), DefKind::OpaqueTy) =>
|
||||
if self.tcx.def_kind(def_id) == DefKind::OpaqueTy =>
|
||||
{
|
||||
(def_id, args)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ pub fn evaluate_host_effect_obligation<'tcx>(
|
|||
selcx: &mut SelectionContext<'_, 'tcx>,
|
||||
obligation: &HostEffectObligation<'tcx>,
|
||||
) -> Result<ThinVec<PredicateObligation<'tcx>>, EvaluationFailure> {
|
||||
if matches!(selcx.infcx.typing_mode(), TypingMode::Coherence) {
|
||||
if selcx.infcx.typing_mode() == TypingMode::Coherence {
|
||||
span_bug!(
|
||||
obligation.cause.span,
|
||||
"should not select host obligation in old solver in intercrate mode"
|
||||
|
|
|
|||
|
|
@ -1654,7 +1654,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
// share the same type as `self_ty`. This is because for truly rigid
|
||||
// projections, we will never be able to equate, e.g. `<T as Tr>::A`
|
||||
// with `<<T as Tr>::A as Tr>::A`.
|
||||
let relevant_bounds = if matches!(alias_bound_kind, AliasBoundKind::NonSelfBounds) {
|
||||
let relevant_bounds = if alias_bound_kind == AliasBoundKind::NonSelfBounds {
|
||||
self.tcx().item_non_self_bounds(alias_ty.def_id)
|
||||
} else {
|
||||
self.tcx().item_self_bounds(alias_ty.def_id)
|
||||
|
|
@ -2855,7 +2855,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||
}
|
||||
|
||||
// Register any outlives obligations from the trait here, cc #124336.
|
||||
if matches!(tcx.def_kind(def_id), DefKind::Impl { of_trait: true }) {
|
||||
if tcx.def_kind(def_id) == (DefKind::Impl { of_trait: true }) {
|
||||
for clause in tcx.impl_super_outlives(def_id).iter_instantiated(tcx, args) {
|
||||
let clause = normalize_with_depth_to(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue