Fix some more clippy warnings

This commit is contained in:
Joshua Nelson 2020-10-26 20:02:06 -04:00
parent 388ef34904
commit bfecb18771
16 changed files with 71 additions and 97 deletions

View File

@ -490,10 +490,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let count = generics
.params
.iter()
.filter(|param| match param.kind {
ast::GenericParamKind::Lifetime { .. } => true,
_ => false,
})
.filter(|param| matches!(param.kind, ast::GenericParamKind::Lifetime { .. }))
.count();
self.lctx.type_def_lifetime_params.insert(def_id.to_def_id(), count);
}

View File

@ -262,10 +262,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lower_angle_bracketed_parameter_data(&Default::default(), param_mode, itctx)
};
let has_lifetimes = generic_args.args.iter().any(|arg| match arg {
GenericArg::Lifetime(_) => true,
_ => false,
});
let has_lifetimes =
generic_args.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)));
let first_generic_span = generic_args
.args
.iter()

View File

@ -102,10 +102,7 @@ impl TokenTree {
/// Returns `true` if the given token tree is delimited.
fn is_delimited(&self) -> bool {
match *self {
TokenTree::Delimited(..) => true,
_ => false,
}
matches!(*self, TokenTree::Delimited(..))
}
/// Returns `true` if the given token tree is a token of the given kind.

View File

@ -134,10 +134,7 @@ enum Stack<'a, T> {
impl<'a, T> Stack<'a, T> {
/// Returns whether a stack is empty.
fn is_empty(&self) -> bool {
match *self {
Stack::Empty => true,
_ => false,
}
matches!(*self, Stack::Empty)
}
/// Returns a new stack with an element of top.

View File

@ -1036,17 +1036,16 @@ fn token_can_be_followed_by_any(tok: &mbe::TokenTree) -> bool {
/// a fragment specifier (indeed, these fragments can be followed by
/// ANYTHING without fear of future compatibility hazards).
fn frag_can_be_followed_by_any(kind: NonterminalKind) -> bool {
match kind {
matches!(
kind,
NonterminalKind::Item // always terminated by `}` or `;`
| NonterminalKind::Block // exactly one token tree
| NonterminalKind::Ident // exactly one token tree
| NonterminalKind::Literal // exactly one token tree
| NonterminalKind::Meta // exactly one token tree
| NonterminalKind::Lifetime // exactly one token tree
| NonterminalKind::TT => true, // exactly one token tree
_ => false,
}
| NonterminalKind::TT // exactly one token tree
)
}
enum IsInFollow {

View File

@ -345,10 +345,10 @@ impl<'a, 'b> MutVisitor for PlaceholderExpander<'a, 'b> {
fn visit_mod(&mut self, module: &mut ast::Mod) {
noop_visit_mod(module, self);
module.items.retain(|item| match item.kind {
ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs => false, // remove macro definitions
_ => true,
});
// remove macro definitions
module.items.retain(
|item| !matches!(item.kind, ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs),
);
}
fn visit_mac(&mut self, _mac: &mut ast::MacCall) {

View File

@ -1369,10 +1369,9 @@ impl TypeAliasBounds {
hir::QPath::TypeRelative(ref ty, _) => {
// If this is a type variable, we found a `T::Assoc`.
match ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => match path.res {
Res::Def(DefKind::TyParam, _) => true,
_ => false,
},
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => {
matches!(path.res, Res::Def(DefKind::TyParam, _))
}
_ => false,
}
}
@ -2381,10 +2380,9 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
return Some(InitKind::Zeroed);
} else if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) {
return Some(InitKind::Uninit);
} else if cx.tcx.is_diagnostic_item(sym::transmute, def_id) {
if is_zero(&args[0]) {
return Some(InitKind::Zeroed);
}
} else if cx.tcx.is_diagnostic_item(sym::transmute, def_id) && is_zero(&args[0])
{
return Some(InitKind::Zeroed);
}
}
} else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
@ -2880,7 +2878,7 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, this_fi: &hir::ForeignItem<'_>) {
trace!("ClashingExternDeclarations: check_foreign_item: {:?}", this_fi);
if let ForeignItemKind::Fn(..) = this_fi.kind {
let tcx = *&cx.tcx;
let tcx = cx.tcx;
if let Some(existing_hid) = self.insert(tcx, this_fi) {
let existing_decl_ty = tcx.type_of(tcx.hir().local_def_id(existing_hid));
let this_decl_ty = tcx.type_of(tcx.hir().local_def_id(this_fi.hir_id));

View File

@ -320,7 +320,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
.with_hi(lit.span.hi() - BytePos(right as u32)),
)
})
.unwrap_or_else(|| lit.span);
.unwrap_or(lit.span);
Some(Ident::new(name, sp))
} else {

View File

@ -544,15 +544,15 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
}
fn is_comparison(binop: hir::BinOp) -> bool {
match binop.node {
matches!(
binop.node,
hir::BinOpKind::Eq
| hir::BinOpKind::Lt
| hir::BinOpKind::Le
| hir::BinOpKind::Ne
| hir::BinOpKind::Ge
| hir::BinOpKind::Gt => true,
_ => false,
}
| hir::BinOpKind::Lt
| hir::BinOpKind::Le
| hir::BinOpKind::Ne
| hir::BinOpKind::Ge
| hir::BinOpKind::Gt
)
}
}
}
@ -1233,15 +1233,10 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
}
fn is_internal_abi(&self, abi: SpecAbi) -> bool {
if let SpecAbi::Rust
| SpecAbi::RustCall
| SpecAbi::RustIntrinsic
| SpecAbi::PlatformIntrinsic = abi
{
true
} else {
false
}
matches!(
abi,
SpecAbi::Rust | SpecAbi::RustCall | SpecAbi::RustIntrinsic | SpecAbi::PlatformIntrinsic
)
}
}

View File

@ -752,14 +752,11 @@ impl UnusedDelimLint for UnusedParens {
&& value.attrs.is_empty()
&& !value.span.from_expansion()
&& (ctx != UnusedDelimsCtx::LetScrutineeExpr
|| match inner.kind {
ast::ExprKind::Binary(
|| !matches!(inner.kind, ast::ExprKind::Binary(
rustc_span::source_map::Spanned { node, .. },
_,
_,
) if node.lazy() => false,
_ => true,
})
) if node.lazy()))
{
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos)
}

View File

@ -752,10 +752,7 @@ impl<'a> CrateLoader<'a> {
// At this point we've determined that we need an allocator. Let's see
// if our compilation session actually needs an allocator based on what
// we're emitting.
let all_rlib = self.sess.crate_types().iter().all(|ct| match *ct {
CrateType::Rlib => true,
_ => false,
});
let all_rlib = self.sess.crate_types().iter().all(|ct| matches!(*ct, CrateType::Rlib));
if all_rlib {
return;
}

View File

@ -633,11 +633,9 @@ impl<'a> CrateLocator<'a> {
}
}
if self.exact_paths.is_empty() {
if self.crate_name != root.name() {
info!("Rejecting via crate name");
return None;
}
if self.exact_paths.is_empty() && self.crate_name != root.name() {
info!("Rejecting via crate name");
return None;
}
if root.triple() != &self.triple {

View File

@ -220,10 +220,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
missing_lang_items => { cdata.get_missing_lang_items(tcx) }
missing_extern_crate_item => {
let r = match *cdata.extern_crate.borrow() {
Some(extern_crate) if !extern_crate.is_direct() => true,
_ => false,
};
let r = matches!(*cdata.extern_crate.borrow(), Some(extern_crate) if !extern_crate.is_direct());
r
}
@ -254,9 +251,11 @@ pub fn provide(providers: &mut Providers) {
}
_ => false,
},
is_statically_included_foreign_item: |tcx, id| match tcx.native_library_kind(id) {
Some(NativeLibKind::StaticBundle | NativeLibKind::StaticNoBundle) => true,
_ => false,
is_statically_included_foreign_item: |tcx, id| {
matches!(
tcx.native_library_kind(id),
Some(NativeLibKind::StaticBundle | NativeLibKind::StaticNoBundle)
)
},
native_library_kind: |tcx, id| {
tcx.native_libraries(id.krate)

View File

@ -1219,9 +1219,11 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
.maybe_typeck_results
.and_then(|typeck_results| typeck_results.type_dependent_def(id)),
};
let def = def.filter(|(kind, _)| match kind {
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static => true,
_ => false,
let def = def.filter(|(kind, _)| {
matches!(
kind,
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static
)
});
if let Some((kind, def_id)) = def {
let is_local_static =

View File

@ -342,29 +342,29 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
}
(ty::Bool, Scalar(Bool)) => true,
(ty::Char, Scalar(Char)) => true,
(ty::Int(ty1), Scalar(Int(ty2))) => match (ty1, ty2) {
(ty::Int(ty1), Scalar(Int(ty2))) => matches!(
(ty1, ty2),
(ast::IntTy::Isize, chalk_ir::IntTy::Isize)
| (ast::IntTy::I8, chalk_ir::IntTy::I8)
| (ast::IntTy::I16, chalk_ir::IntTy::I16)
| (ast::IntTy::I32, chalk_ir::IntTy::I32)
| (ast::IntTy::I64, chalk_ir::IntTy::I64)
| (ast::IntTy::I128, chalk_ir::IntTy::I128) => true,
_ => false,
},
(ty::Uint(ty1), Scalar(Uint(ty2))) => match (ty1, ty2) {
| (ast::IntTy::I8, chalk_ir::IntTy::I8)
| (ast::IntTy::I16, chalk_ir::IntTy::I16)
| (ast::IntTy::I32, chalk_ir::IntTy::I32)
| (ast::IntTy::I64, chalk_ir::IntTy::I64)
| (ast::IntTy::I128, chalk_ir::IntTy::I128)
),
(ty::Uint(ty1), Scalar(Uint(ty2))) => matches!(
(ty1, ty2),
(ast::UintTy::Usize, chalk_ir::UintTy::Usize)
| (ast::UintTy::U8, chalk_ir::UintTy::U8)
| (ast::UintTy::U16, chalk_ir::UintTy::U16)
| (ast::UintTy::U32, chalk_ir::UintTy::U32)
| (ast::UintTy::U64, chalk_ir::UintTy::U64)
| (ast::UintTy::U128, chalk_ir::UintTy::U128) => true,
_ => false,
},
(ty::Float(ty1), Scalar(Float(ty2))) => match (ty1, ty2) {
| (ast::UintTy::U8, chalk_ir::UintTy::U8)
| (ast::UintTy::U16, chalk_ir::UintTy::U16)
| (ast::UintTy::U32, chalk_ir::UintTy::U32)
| (ast::UintTy::U64, chalk_ir::UintTy::U64)
| (ast::UintTy::U128, chalk_ir::UintTy::U128)
),
(ty::Float(ty1), Scalar(Float(ty2))) => matches!(
(ty1, ty2),
(ast::FloatTy::F32, chalk_ir::FloatTy::F32)
| (ast::FloatTy::F64, chalk_ir::FloatTy::F64) => true,
_ => false,
},
| (ast::FloatTy::F64, chalk_ir::FloatTy::F64)
),
(&ty::Tuple(..), Tuple(..)) => true,
(&ty::Array(..), Array) => true,
(&ty::Slice(..), Slice) => true,

View File

@ -62,7 +62,7 @@ fn compute_implied_outlives_bounds<'tcx>(
// unresolved inference variables here anyway, but there might be
// during typeck under some circumstances.)
let obligations = wf::obligations(infcx, param_env, hir::CRATE_HIR_ID, 0, arg, DUMMY_SP)
.unwrap_or(vec![]);
.unwrap_or_default();
// N.B., all of these predicates *ought* to be easily proven
// true. In fact, their correctness is (mostly) implied by