Skip to content

Commit bfecb18

Browse files
committed
Fix some more clippy warnings
1 parent 388ef34 commit bfecb18

File tree

16 files changed

+71
-97
lines changed

16 files changed

+71
-97
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
490490
let count = generics
491491
.params
492492
.iter()
493-
.filter(|param| match param.kind {
494-
ast::GenericParamKind::Lifetime { .. } => true,
495-
_ => false,
496-
})
493+
.filter(|param| matches!(param.kind, ast::GenericParamKind::Lifetime { .. }))
497494
.count();
498495
self.lctx.type_def_lifetime_params.insert(def_id.to_def_id(), count);
499496
}

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
262262
self.lower_angle_bracketed_parameter_data(&Default::default(), param_mode, itctx)
263263
};
264264

265-
let has_lifetimes = generic_args.args.iter().any(|arg| match arg {
266-
GenericArg::Lifetime(_) => true,
267-
_ => false,
268-
});
265+
let has_lifetimes =
266+
generic_args.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)));
269267
let first_generic_span = generic_args
270268
.args
271269
.iter()

compiler/rustc_expand/src/mbe.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ impl TokenTree {
102102

103103
/// Returns `true` if the given token tree is delimited.
104104
fn is_delimited(&self) -> bool {
105-
match *self {
106-
TokenTree::Delimited(..) => true,
107-
_ => false,
108-
}
105+
matches!(*self, TokenTree::Delimited(..))
109106
}
110107

111108
/// Returns `true` if the given token tree is a token of the given kind.

compiler/rustc_expand/src/mbe/macro_check.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ enum Stack<'a, T> {
134134
impl<'a, T> Stack<'a, T> {
135135
/// Returns whether a stack is empty.
136136
fn is_empty(&self) -> bool {
137-
match *self {
138-
Stack::Empty => true,
139-
_ => false,
140-
}
137+
matches!(*self, Stack::Empty)
141138
}
142139

143140
/// Returns a new stack with an element of top.

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,17 +1036,16 @@ fn token_can_be_followed_by_any(tok: &mbe::TokenTree) -> bool {
10361036
/// a fragment specifier (indeed, these fragments can be followed by
10371037
/// ANYTHING without fear of future compatibility hazards).
10381038
fn frag_can_be_followed_by_any(kind: NonterminalKind) -> bool {
1039-
match kind {
1039+
matches!(
1040+
kind,
10401041
NonterminalKind::Item // always terminated by `}` or `;`
10411042
| NonterminalKind::Block // exactly one token tree
10421043
| NonterminalKind::Ident // exactly one token tree
10431044
| NonterminalKind::Literal // exactly one token tree
10441045
| NonterminalKind::Meta // exactly one token tree
10451046
| NonterminalKind::Lifetime // exactly one token tree
1046-
| NonterminalKind::TT => true, // exactly one token tree
1047-
1048-
_ => false,
1049-
}
1047+
| NonterminalKind::TT // exactly one token tree
1048+
)
10501049
}
10511050

10521051
enum IsInFollow {

compiler/rustc_expand/src/placeholders.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
345345

346346
fn visit_mod(&mut self, module: &mut ast::Mod) {
347347
noop_visit_mod(module, self);
348-
module.items.retain(|item| match item.kind {
349-
ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs => false, // remove macro definitions
350-
_ => true,
351-
});
348+
// remove macro definitions
349+
module.items.retain(
350+
|item| !matches!(item.kind, ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs),
351+
);
352352
}
353353

354354
fn visit_mac(&mut self, _mac: &mut ast::MacCall) {

compiler/rustc_lint/src/builtin.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,10 +1369,9 @@ impl TypeAliasBounds {
13691369
hir::QPath::TypeRelative(ref ty, _) => {
13701370
// If this is a type variable, we found a `T::Assoc`.
13711371
match ty.kind {
1372-
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => match path.res {
1373-
Res::Def(DefKind::TyParam, _) => true,
1374-
_ => false,
1375-
},
1372+
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => {
1373+
matches!(path.res, Res::Def(DefKind::TyParam, _))
1374+
}
13761375
_ => false,
13771376
}
13781377
}
@@ -2381,10 +2380,9 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
23812380
return Some(InitKind::Zeroed);
23822381
} else if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) {
23832382
return Some(InitKind::Uninit);
2384-
} else if cx.tcx.is_diagnostic_item(sym::transmute, def_id) {
2385-
if is_zero(&args[0]) {
2386-
return Some(InitKind::Zeroed);
2387-
}
2383+
} else if cx.tcx.is_diagnostic_item(sym::transmute, def_id) && is_zero(&args[0])
2384+
{
2385+
return Some(InitKind::Zeroed);
23882386
}
23892387
}
23902388
} else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
@@ -2880,7 +2878,7 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
28802878
fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, this_fi: &hir::ForeignItem<'_>) {
28812879
trace!("ClashingExternDeclarations: check_foreign_item: {:?}", this_fi);
28822880
if let ForeignItemKind::Fn(..) = this_fi.kind {
2883-
let tcx = *&cx.tcx;
2881+
let tcx = cx.tcx;
28842882
if let Some(existing_hid) = self.insert(tcx, this_fi) {
28852883
let existing_decl_ty = tcx.type_of(tcx.hir().local_def_id(existing_hid));
28862884
let this_decl_ty = tcx.type_of(tcx.hir().local_def_id(this_fi.hir_id));

compiler/rustc_lint/src/nonstandard_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
320320
.with_hi(lit.span.hi() - BytePos(right as u32)),
321321
)
322322
})
323-
.unwrap_or_else(|| lit.span);
323+
.unwrap_or(lit.span);
324324

325325
Some(Ident::new(name, sp))
326326
} else {

compiler/rustc_lint/src/types.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,15 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
544544
}
545545

546546
fn is_comparison(binop: hir::BinOp) -> bool {
547-
match binop.node {
547+
matches!(
548+
binop.node,
548549
hir::BinOpKind::Eq
549-
| hir::BinOpKind::Lt
550-
| hir::BinOpKind::Le
551-
| hir::BinOpKind::Ne
552-
| hir::BinOpKind::Ge
553-
| hir::BinOpKind::Gt => true,
554-
_ => false,
555-
}
550+
| hir::BinOpKind::Lt
551+
| hir::BinOpKind::Le
552+
| hir::BinOpKind::Ne
553+
| hir::BinOpKind::Ge
554+
| hir::BinOpKind::Gt
555+
)
556556
}
557557
}
558558
}
@@ -1233,15 +1233,10 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
12331233
}
12341234

12351235
fn is_internal_abi(&self, abi: SpecAbi) -> bool {
1236-
if let SpecAbi::Rust
1237-
| SpecAbi::RustCall
1238-
| SpecAbi::RustIntrinsic
1239-
| SpecAbi::PlatformIntrinsic = abi
1240-
{
1241-
true
1242-
} else {
1243-
false
1244-
}
1236+
matches!(
1237+
abi,
1238+
SpecAbi::Rust | SpecAbi::RustCall | SpecAbi::RustIntrinsic | SpecAbi::PlatformIntrinsic
1239+
)
12451240
}
12461241
}
12471242

compiler/rustc_lint/src/unused.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,14 +752,11 @@ impl UnusedDelimLint for UnusedParens {
752752
&& value.attrs.is_empty()
753753
&& !value.span.from_expansion()
754754
&& (ctx != UnusedDelimsCtx::LetScrutineeExpr
755-
|| match inner.kind {
756-
ast::ExprKind::Binary(
755+
|| !matches!(inner.kind, ast::ExprKind::Binary(
757756
rustc_span::source_map::Spanned { node, .. },
758757
_,
759758
_,
760-
) if node.lazy() => false,
761-
_ => true,
762-
})
759+
) if node.lazy()))
763760
{
764761
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos)
765762
}

0 commit comments

Comments
 (0)