Skip to content

Commit 3c1ecc9

Browse files
authored
Rollup merge of #90642 - matthiaskrgr:clippy_matches, r=cjgillot
use matches!() macro in more places
2 parents f3f9ec6 + 0a5640b commit 3c1ecc9

File tree

21 files changed

+49
-86
lines changed

21 files changed

+49
-86
lines changed

compiler/rustc_ast/src/util/parser.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ impl AssocOp {
212212
/// parentheses while having a high degree of confidence on the correctness of the suggestion.
213213
pub fn can_continue_expr_unambiguously(&self) -> bool {
214214
use AssocOp::*;
215-
match self {
215+
matches!(
216+
self,
216217
BitXor | // `{ 42 } ^ 3`
217218
Assign | // `{ 42 } = { 42 }`
218219
Divide | // `{ 42 } / 42`
@@ -225,9 +226,8 @@ impl AssocOp {
225226
As | // `{ 42 } as usize`
226227
// Equal | // `{ 42 } == { 42 }` Accepting these here would regress incorrect
227228
// NotEqual | // `{ 42 } != { 42 } struct literals parser recovery.
228-
Colon => true, // `{ 42 }: usize`
229-
_ => false,
230-
}
229+
Colon, // `{ 42 }: usize`
230+
)
231231
}
232232
}
233233

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ pub(crate) enum LaterUseKind {
5353

5454
impl BorrowExplanation {
5555
pub(crate) fn is_explained(&self) -> bool {
56-
match self {
57-
BorrowExplanation::Unexplained => false,
58-
_ => true,
59-
}
56+
!matches!(self, BorrowExplanation::Unexplained)
6057
}
6158
pub(crate) fn add_explanation_to_diagnostic<'tcx>(
6259
&self,

compiler/rustc_borrowck/src/region_infer/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2110,14 +2110,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21102110
_ => constraint_sup_scc != target_scc,
21112111
}
21122112
} else {
2113-
match categorized_path[*i].category {
2113+
!matches!(
2114+
categorized_path[*i].category,
21142115
ConstraintCategory::OpaqueType
2115-
| ConstraintCategory::Boring
2116-
| ConstraintCategory::BoringNoLocation
2117-
| ConstraintCategory::Internal
2118-
| ConstraintCategory::Predicate(_) => false,
2119-
_ => true,
2120-
}
2116+
| ConstraintCategory::Boring
2117+
| ConstraintCategory::BoringNoLocation
2118+
| ConstraintCategory::Internal
2119+
| ConstraintCategory::Predicate(_)
2120+
)
21212121
}
21222122
};
21232123

compiler/rustc_borrowck/src/universal_regions.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,11 @@ impl<'tcx> DefiningTy<'tcx> {
138138
}
139139

140140
pub fn is_fn_def(&self) -> bool {
141-
match *self {
142-
DefiningTy::FnDef(..) => true,
143-
_ => false,
144-
}
141+
matches!(*self, DefiningTy::FnDef(..))
145142
}
146143

147144
pub fn is_const(&self) -> bool {
148-
match *self {
149-
DefiningTy::Const(..) => true,
150-
_ => false,
151-
}
145+
matches!(*self, DefiningTy::Const(..))
152146
}
153147

154148
pub fn def_id(&self) -> DefId {

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ fn push_debuginfo_type_name<'tcx>(
124124
// info for MSVC debugger. However, wrapping these types' names in a synthetic type
125125
// causes the .natvis engine for WinDbg to fail to display their data, so we opt these
126126
// types out to aid debugging in MSVC.
127-
let is_slice_or_str = match *inner_type.kind() {
128-
ty::Slice(_) | ty::Str => true,
129-
_ => false,
130-
};
127+
let is_slice_or_str = matches!(*inner_type.kind(), ty::Slice(_) | ty::Str);
131128

132129
if !cpp_like_names {
133130
output.push('&');

compiler/rustc_const_eval/src/const_eval/error.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ pub enum ConstEvalErrKind {
2525

2626
impl MachineStopType for ConstEvalErrKind {
2727
fn is_hard_err(&self) -> bool {
28-
match self {
29-
Self::Panic { .. } => true,
30-
_ => false,
31-
}
28+
matches!(self, Self::Panic { .. })
3229
}
3330
}
3431

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
5151
// If the function itself is not annotated with `const`, it may still be a `const fn`
5252
// if it resides in a const trait impl.
5353
is_parent_const_impl_raw(tcx, hir_id)
54-
} else if let hir::Node::Ctor(_) = node {
55-
true
5654
} else {
57-
false
55+
matches!(node, hir::Node::Ctor(_))
5856
}
5957
}
6058

compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
138138
args: &[GenericArg<'tcx>],
139139
) -> Result<Self::Path, Self::Error> {
140140
self = print_prefix(self)?;
141-
let args = args.iter().cloned().filter(|arg| match arg.unpack() {
142-
GenericArgKind::Lifetime(_) => false,
143-
_ => true,
144-
});
141+
let args =
142+
args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
145143
if args.clone().next().is_some() {
146144
self.generic_delimiters(|cx| cx.comma_sep(args))
147145
} else {

compiler/rustc_const_eval/src/interpret/terminator.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
345345

346346
// Figure out how to pass which arguments.
347347
// The Rust ABI is special: ZST get skipped.
348-
let rust_abi = match caller_abi {
349-
Abi::Rust | Abi::RustCall => true,
350-
_ => false,
351-
};
348+
let rust_abi = matches!(caller_abi, Abi::Rust | Abi::RustCall);
349+
352350
// We have two iterators: Where the arguments come from,
353351
// and where they go to.
354352

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ impl Qualifs<'mir, 'tcx> {
131131
.body
132132
.basic_blocks()
133133
.iter_enumerated()
134-
.find(|(_, block)| match block.terminator().kind {
135-
TerminatorKind::Return => true,
136-
_ => false,
137-
})
134+
.find(|(_, block)| matches!(block.terminator().kind, TerminatorKind::Return))
138135
.map(|(bb, _)| bb);
139136

140137
let return_block = match return_block {

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ impl Qualif for NeedsNonConstDrop {
170170
let mut selcx = SelectionContext::with_constness(&infcx, hir::Constness::Const);
171171
selcx.select(&obligation)
172172
});
173-
match implsrc {
174-
Ok(Some(ImplSource::ConstDrop(_)))
175-
| Ok(Some(ImplSource::Param(_, ty::BoundConstness::ConstIfConst))) => false,
176-
_ => true,
177-
}
173+
!matches!(
174+
implsrc,
175+
Ok(Some(
176+
ImplSource::ConstDrop(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
177+
))
178+
)
178179
}
179180

180181
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {

compiler/rustc_lexer/src/unescape.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ pub enum EscapeError {
6868
impl EscapeError {
6969
/// Returns true for actual errors, as opposed to warnings.
7070
pub fn is_fatal(&self) -> bool {
71-
match self {
72-
EscapeError::UnskippedWhitespaceWarning => false,
73-
EscapeError::MultipleSkippedLinesWarning => false,
74-
_ => true,
75-
}
71+
!matches!(
72+
self,
73+
EscapeError::UnskippedWhitespaceWarning | EscapeError::MultipleSkippedLinesWarning
74+
)
7675
}
7776
}
7877

compiler/rustc_middle/src/mir/interpret/error.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,12 @@ impl InterpError<'_> {
538538
/// To avoid performance issues, there are places where we want to be sure to never raise these formatting errors,
539539
/// so this method lets us detect them and `bug!` on unexpected errors.
540540
pub fn formatted_string(&self) -> bool {
541-
match self {
541+
matches!(
542+
self,
542543
InterpError::Unsupported(UnsupportedOpInfo::Unsupported(_))
543-
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::ValidationFailure { .. })
544-
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::Ub(_)) => true,
545-
_ => false,
546-
}
544+
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::ValidationFailure { .. })
545+
| InterpError::UndefinedBehavior(UndefinedBehaviorInfo::Ub(_))
546+
)
547547
}
548548

549549
/// Should this error be reported as a hard error, preventing compilation, or a soft error,

compiler/rustc_mir_transform/src/coverage/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn inject_statement(
485485

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

compiler/rustc_mir_transform/src/coverage/spans.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ impl CoverageSpan {
9494
stmt_index: usize,
9595
) -> Self {
9696
let is_closure = match statement.kind {
97-
StatementKind::Assign(box (_, Rvalue::Aggregate(box ref kind, _))) => match kind {
98-
AggregateKind::Closure(_, _) | AggregateKind::Generator(_, _, _) => true,
99-
_ => false,
100-
},
97+
StatementKind::Assign(box (_, Rvalue::Aggregate(box ref kind, _))) => {
98+
matches!(kind, AggregateKind::Closure(_, _) | AggregateKind::Generator(_, _, _))
99+
}
101100
_ => false,
102101
};
103102

compiler/rustc_mir_transform/src/unreachable_prop.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ impl MirPass<'_> for UnreachablePropagation {
2727
// This is a temporary solution that handles possibly diverging asm statements.
2828
// Accompanying testcases: mir-opt/unreachable_asm.rs and mir-opt/unreachable_asm_2.rs
2929
let asm_stmt_in_block = || {
30-
bb_data.statements.iter().any(|stmt: &Statement<'_>| match stmt.kind {
31-
StatementKind::LlvmInlineAsm(..) => true,
32-
_ => false,
30+
bb_data.statements.iter().any(|stmt: &Statement<'_>| {
31+
matches!(stmt.kind, StatementKind::LlvmInlineAsm(..))
3332
})
3433
};
3534

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
320320

321321
/// Returns `true` if the trait predicate is considerd `const` to this selection context.
322322
pub fn is_trait_predicate_const(&self, pred: ty::TraitPredicate<'_>) -> bool {
323-
match pred.constness {
324-
ty::BoundConstness::ConstIfConst if self.is_in_const_context => true,
325-
_ => false,
326-
}
323+
matches!(pred.constness, ty::BoundConstness::ConstIfConst) && self.is_in_const_context
327324
}
328325

329326
/// Returns `true` if the predicate is considered `const` to

compiler/rustc_typeck/src/check/cast.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
436436
// Very crude check to see whether the expression must be wrapped
437437
// in parentheses for the suggestion to work (issue #89497).
438438
// Can/should be extended in the future.
439-
let needs_parens = !has_parens
440-
&& match self.expr.kind {
441-
hir::ExprKind::Cast(..) => true,
442-
_ => false,
443-
};
439+
let needs_parens =
440+
!has_parens && matches!(self.expr.kind, hir::ExprKind::Cast(..));
444441

445442
let mut suggestion = vec![(self.expr.span.shrink_to_lo(), sugg)];
446443
if needs_parens {

compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
300300
hir::TyKind::Path(hir::QPath::Resolved(
301301
None,
302302
hir::Path { res: hir::def::Res::Def(_, id), .. },
303-
)) if *id == def_id => true,
303+
)) => *id == def_id,
304304
_ => false,
305305
})
306306
})

library/std/src/net/ip.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -878,12 +878,7 @@ impl Ipv4Addr {
878878
#[must_use]
879879
#[inline]
880880
pub const fn is_documentation(&self) -> bool {
881-
match self.octets() {
882-
[192, 0, 2, _] => true,
883-
[198, 51, 100, _] => true,
884-
[203, 0, 113, _] => true,
885-
_ => false,
886-
}
881+
matches!(self.octets(), [192, 0, 2, _] | [198, 51, 100, _] | [203, 0, 113, _])
887882
}
888883

889884
/// Converts this address to an [IPv4-compatible] [`IPv6` address].

library/std/src/os/unix/net/addr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl SocketAddr {
159159
#[must_use]
160160
#[stable(feature = "unix_socket", since = "1.10.0")]
161161
pub fn is_unnamed(&self) -> bool {
162-
if let AddressKind::Unnamed = self.address() { true } else { false }
162+
matches!(self.address(), AddressKind::Unnamed)
163163
}
164164

165165
/// Returns the contents of this address if it is a `pathname` address.

0 commit comments

Comments
 (0)