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
}

compiler/rustc_metadata/src/creader.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,7 @@ impl<'a> CrateLoader<'a> {
752752
// At this point we've determined that we need an allocator. Let's see
753753
// if our compilation session actually needs an allocator based on what
754754
// we're emitting.
755-
let all_rlib = self.sess.crate_types().iter().all(|ct| match *ct {
756-
CrateType::Rlib => true,
757-
_ => false,
758-
});
755+
let all_rlib = self.sess.crate_types().iter().all(|ct| matches!(*ct, CrateType::Rlib));
759756
if all_rlib {
760757
return;
761758
}

compiler/rustc_metadata/src/locator.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,9 @@ impl<'a> CrateLocator<'a> {
633633
}
634634
}
635635

636-
if self.exact_paths.is_empty() {
637-
if self.crate_name != root.name() {
638-
info!("Rejecting via crate name");
639-
return None;
640-
}
636+
if self.exact_paths.is_empty() && self.crate_name != root.name() {
637+
info!("Rejecting via crate name");
638+
return None;
641639
}
642640

643641
if root.triple() != &self.triple {

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
220220
missing_lang_items => { cdata.get_missing_lang_items(tcx) }
221221

222222
missing_extern_crate_item => {
223-
let r = match *cdata.extern_crate.borrow() {
224-
Some(extern_crate) if !extern_crate.is_direct() => true,
225-
_ => false,
226-
};
223+
let r = matches!(*cdata.extern_crate.borrow(), Some(extern_crate) if !extern_crate.is_direct());
227224
r
228225
}
229226

@@ -254,9 +251,11 @@ pub fn provide(providers: &mut Providers) {
254251
}
255252
_ => false,
256253
},
257-
is_statically_included_foreign_item: |tcx, id| match tcx.native_library_kind(id) {
258-
Some(NativeLibKind::StaticBundle | NativeLibKind::StaticNoBundle) => true,
259-
_ => false,
254+
is_statically_included_foreign_item: |tcx, id| {
255+
matches!(
256+
tcx.native_library_kind(id),
257+
Some(NativeLibKind::StaticBundle | NativeLibKind::StaticNoBundle)
258+
)
260259
},
261260
native_library_kind: |tcx, id| {
262261
tcx.native_libraries(id.krate)

compiler/rustc_privacy/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,11 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
12191219
.maybe_typeck_results
12201220
.and_then(|typeck_results| typeck_results.type_dependent_def(id)),
12211221
};
1222-
let def = def.filter(|(kind, _)| match kind {
1223-
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static => true,
1224-
_ => false,
1222+
let def = def.filter(|(kind, _)| {
1223+
matches!(
1224+
kind,
1225+
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static
1226+
)
12251227
});
12261228
if let Some((kind, def_id)) = def {
12271229
let is_local_static =

compiler/rustc_traits/src/chalk/db.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -342,29 +342,29 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
342342
}
343343
(ty::Bool, Scalar(Bool)) => true,
344344
(ty::Char, Scalar(Char)) => true,
345-
(ty::Int(ty1), Scalar(Int(ty2))) => match (ty1, ty2) {
345+
(ty::Int(ty1), Scalar(Int(ty2))) => matches!(
346+
(ty1, ty2),
346347
(ast::IntTy::Isize, chalk_ir::IntTy::Isize)
347-
| (ast::IntTy::I8, chalk_ir::IntTy::I8)
348-
| (ast::IntTy::I16, chalk_ir::IntTy::I16)
349-
| (ast::IntTy::I32, chalk_ir::IntTy::I32)
350-
| (ast::IntTy::I64, chalk_ir::IntTy::I64)
351-
| (ast::IntTy::I128, chalk_ir::IntTy::I128) => true,
352-
_ => false,
353-
},
354-
(ty::Uint(ty1), Scalar(Uint(ty2))) => match (ty1, ty2) {
348+
| (ast::IntTy::I8, chalk_ir::IntTy::I8)
349+
| (ast::IntTy::I16, chalk_ir::IntTy::I16)
350+
| (ast::IntTy::I32, chalk_ir::IntTy::I32)
351+
| (ast::IntTy::I64, chalk_ir::IntTy::I64)
352+
| (ast::IntTy::I128, chalk_ir::IntTy::I128)
353+
),
354+
(ty::Uint(ty1), Scalar(Uint(ty2))) => matches!(
355+
(ty1, ty2),
355356
(ast::UintTy::Usize, chalk_ir::UintTy::Usize)
356-
| (ast::UintTy::U8, chalk_ir::UintTy::U8)
357-
| (ast::UintTy::U16, chalk_ir::UintTy::U16)
358-
| (ast::UintTy::U32, chalk_ir::UintTy::U32)
359-
| (ast::UintTy::U64, chalk_ir::UintTy::U64)
360-
| (ast::UintTy::U128, chalk_ir::UintTy::U128) => true,
361-
_ => false,
362-
},
363-
(ty::Float(ty1), Scalar(Float(ty2))) => match (ty1, ty2) {
357+
| (ast::UintTy::U8, chalk_ir::UintTy::U8)
358+
| (ast::UintTy::U16, chalk_ir::UintTy::U16)
359+
| (ast::UintTy::U32, chalk_ir::UintTy::U32)
360+
| (ast::UintTy::U64, chalk_ir::UintTy::U64)
361+
| (ast::UintTy::U128, chalk_ir::UintTy::U128)
362+
),
363+
(ty::Float(ty1), Scalar(Float(ty2))) => matches!(
364+
(ty1, ty2),
364365
(ast::FloatTy::F32, chalk_ir::FloatTy::F32)
365-
| (ast::FloatTy::F64, chalk_ir::FloatTy::F64) => true,
366-
_ => false,
367-
},
366+
| (ast::FloatTy::F64, chalk_ir::FloatTy::F64)
367+
),
368368
(&ty::Tuple(..), Tuple(..)) => true,
369369
(&ty::Array(..), Array) => true,
370370
(&ty::Slice(..), Slice) => true,

compiler/rustc_traits/src/implied_outlives_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn compute_implied_outlives_bounds<'tcx>(
6262
// unresolved inference variables here anyway, but there might be
6363
// during typeck under some circumstances.)
6464
let obligations = wf::obligations(infcx, param_env, hir::CRATE_HIR_ID, 0, arg, DUMMY_SP)
65-
.unwrap_or(vec![]);
65+
.unwrap_or_default();
6666

6767
// N.B., all of these predicates *ought* to be easily proven
6868
// true. In fact, their correctness is (mostly) implied by

0 commit comments

Comments
 (0)