1
Fork 0

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 let count = generics
.params .params
.iter() .iter()
.filter(|param| match param.kind { .filter(|param| matches!(param.kind, ast::GenericParamKind::Lifetime { .. }))
ast::GenericParamKind::Lifetime { .. } => true,
_ => false,
})
.count(); .count();
self.lctx.type_def_lifetime_params.insert(def_id.to_def_id(), 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) self.lower_angle_bracketed_parameter_data(&Default::default(), param_mode, itctx)
}; };
let has_lifetimes = generic_args.args.iter().any(|arg| match arg { let has_lifetimes =
GenericArg::Lifetime(_) => true, generic_args.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_)));
_ => false,
});
let first_generic_span = generic_args let first_generic_span = generic_args
.args .args
.iter() .iter()

View file

@ -102,10 +102,7 @@ impl TokenTree {
/// Returns `true` if the given token tree is delimited. /// Returns `true` if the given token tree is delimited.
fn is_delimited(&self) -> bool { fn is_delimited(&self) -> bool {
match *self { matches!(*self, TokenTree::Delimited(..))
TokenTree::Delimited(..) => true,
_ => false,
}
} }
/// Returns `true` if the given token tree is a token of the given kind. /// 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> { impl<'a, T> Stack<'a, T> {
/// Returns whether a stack is empty. /// Returns whether a stack is empty.
fn is_empty(&self) -> bool { fn is_empty(&self) -> bool {
match *self { matches!(*self, Stack::Empty)
Stack::Empty => true,
_ => false,
}
} }
/// Returns a new stack with an element of top. /// 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 /// a fragment specifier (indeed, these fragments can be followed by
/// ANYTHING without fear of future compatibility hazards). /// ANYTHING without fear of future compatibility hazards).
fn frag_can_be_followed_by_any(kind: NonterminalKind) -> bool { fn frag_can_be_followed_by_any(kind: NonterminalKind) -> bool {
match kind { matches!(
kind,
NonterminalKind::Item // always terminated by `}` or `;` NonterminalKind::Item // always terminated by `}` or `;`
| NonterminalKind::Block // exactly one token tree | NonterminalKind::Block // exactly one token tree
| NonterminalKind::Ident // exactly one token tree | NonterminalKind::Ident // exactly one token tree
| NonterminalKind::Literal // exactly one token tree | NonterminalKind::Literal // exactly one token tree
| NonterminalKind::Meta // exactly one token tree | NonterminalKind::Meta // exactly one token tree
| NonterminalKind::Lifetime // exactly one token tree | NonterminalKind::Lifetime // exactly one token tree
| NonterminalKind::TT => true, // exactly one token tree | NonterminalKind::TT // exactly one token tree
)
_ => false,
}
} }
enum IsInFollow { 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) { fn visit_mod(&mut self, module: &mut ast::Mod) {
noop_visit_mod(module, self); noop_visit_mod(module, self);
module.items.retain(|item| match item.kind { // remove macro definitions
ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs => false, // remove macro definitions module.items.retain(
_ => true, |item| !matches!(item.kind, ast::ItemKind::MacCall(_) if !self.cx.ecfg.keep_macs),
}); );
} }
fn visit_mac(&mut self, _mac: &mut ast::MacCall) { fn visit_mac(&mut self, _mac: &mut ast::MacCall) {

View file

@ -1369,10 +1369,9 @@ impl TypeAliasBounds {
hir::QPath::TypeRelative(ref ty, _) => { hir::QPath::TypeRelative(ref ty, _) => {
// If this is a type variable, we found a `T::Assoc`. // If this is a type variable, we found a `T::Assoc`.
match ty.kind { match ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => match path.res { hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => {
Res::Def(DefKind::TyParam, _) => true, matches!(path.res, Res::Def(DefKind::TyParam, _))
_ => false, }
},
_ => false, _ => false,
} }
} }
@ -2381,12 +2380,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
return Some(InitKind::Zeroed); return Some(InitKind::Zeroed);
} else if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) { } else if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) {
return Some(InitKind::Uninit); return Some(InitKind::Uninit);
} else if cx.tcx.is_diagnostic_item(sym::transmute, def_id) { } else if cx.tcx.is_diagnostic_item(sym::transmute, def_id) && is_zero(&args[0])
if is_zero(&args[0]) { {
return Some(InitKind::Zeroed); return Some(InitKind::Zeroed);
} }
} }
}
} else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind { } else if let hir::ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
// Find problematic calls to `MaybeUninit::assume_init`. // Find problematic calls to `MaybeUninit::assume_init`.
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?; let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;
@ -2880,7 +2878,7 @@ impl<'tcx> LateLintPass<'tcx> for ClashingExternDeclarations {
fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, this_fi: &hir::ForeignItem<'_>) { fn check_foreign_item(&mut self, cx: &LateContext<'tcx>, this_fi: &hir::ForeignItem<'_>) {
trace!("ClashingExternDeclarations: check_foreign_item: {:?}", this_fi); trace!("ClashingExternDeclarations: check_foreign_item: {:?}", this_fi);
if let ForeignItemKind::Fn(..) = this_fi.kind { 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) { 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 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)); 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)), .with_hi(lit.span.hi() - BytePos(right as u32)),
) )
}) })
.unwrap_or_else(|| lit.span); .unwrap_or(lit.span);
Some(Ident::new(name, sp)) Some(Ident::new(name, sp))
} else { } else {

View file

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

View file

@ -752,14 +752,11 @@ impl UnusedDelimLint for UnusedParens {
&& value.attrs.is_empty() && value.attrs.is_empty()
&& !value.span.from_expansion() && !value.span.from_expansion()
&& (ctx != UnusedDelimsCtx::LetScrutineeExpr && (ctx != UnusedDelimsCtx::LetScrutineeExpr
|| match inner.kind { || !matches!(inner.kind, ast::ExprKind::Binary(
ast::ExprKind::Binary(
rustc_span::source_map::Spanned { node, .. }, rustc_span::source_map::Spanned { node, .. },
_, _,
_, _,
) if node.lazy() => false, ) if node.lazy()))
_ => true,
})
{ {
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos) 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 // 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 // if our compilation session actually needs an allocator based on what
// we're emitting. // we're emitting.
let all_rlib = self.sess.crate_types().iter().all(|ct| match *ct { let all_rlib = self.sess.crate_types().iter().all(|ct| matches!(*ct, CrateType::Rlib));
CrateType::Rlib => true,
_ => false,
});
if all_rlib { if all_rlib {
return; return;
} }

View file

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

View file

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

View file

@ -1219,9 +1219,11 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
.maybe_typeck_results .maybe_typeck_results
.and_then(|typeck_results| typeck_results.type_dependent_def(id)), .and_then(|typeck_results| typeck_results.type_dependent_def(id)),
}; };
let def = def.filter(|(kind, _)| match kind { let def = def.filter(|(kind, _)| {
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static => true, matches!(
_ => false, kind,
DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static
)
}); });
if let Some((kind, def_id)) = def { if let Some((kind, def_id)) = def {
let is_local_static = 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::Bool, Scalar(Bool)) => true,
(ty::Char, Scalar(Char)) => 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::Isize, chalk_ir::IntTy::Isize)
| (ast::IntTy::I8, chalk_ir::IntTy::I8) | (ast::IntTy::I8, chalk_ir::IntTy::I8)
| (ast::IntTy::I16, chalk_ir::IntTy::I16) | (ast::IntTy::I16, chalk_ir::IntTy::I16)
| (ast::IntTy::I32, chalk_ir::IntTy::I32) | (ast::IntTy::I32, chalk_ir::IntTy::I32)
| (ast::IntTy::I64, chalk_ir::IntTy::I64) | (ast::IntTy::I64, chalk_ir::IntTy::I64)
| (ast::IntTy::I128, chalk_ir::IntTy::I128) => true, | (ast::IntTy::I128, chalk_ir::IntTy::I128)
_ => false, ),
}, (ty::Uint(ty1), Scalar(Uint(ty2))) => matches!(
(ty::Uint(ty1), Scalar(Uint(ty2))) => match (ty1, ty2) { (ty1, ty2),
(ast::UintTy::Usize, chalk_ir::UintTy::Usize) (ast::UintTy::Usize, chalk_ir::UintTy::Usize)
| (ast::UintTy::U8, chalk_ir::UintTy::U8) | (ast::UintTy::U8, chalk_ir::UintTy::U8)
| (ast::UintTy::U16, chalk_ir::UintTy::U16) | (ast::UintTy::U16, chalk_ir::UintTy::U16)
| (ast::UintTy::U32, chalk_ir::UintTy::U32) | (ast::UintTy::U32, chalk_ir::UintTy::U32)
| (ast::UintTy::U64, chalk_ir::UintTy::U64) | (ast::UintTy::U64, chalk_ir::UintTy::U64)
| (ast::UintTy::U128, chalk_ir::UintTy::U128) => true, | (ast::UintTy::U128, chalk_ir::UintTy::U128)
_ => false, ),
}, (ty::Float(ty1), Scalar(Float(ty2))) => matches!(
(ty::Float(ty1), Scalar(Float(ty2))) => match (ty1, ty2) { (ty1, ty2),
(ast::FloatTy::F32, chalk_ir::FloatTy::F32) (ast::FloatTy::F32, chalk_ir::FloatTy::F32)
| (ast::FloatTy::F64, chalk_ir::FloatTy::F64) => true, | (ast::FloatTy::F64, chalk_ir::FloatTy::F64)
_ => false, ),
},
(&ty::Tuple(..), Tuple(..)) => true, (&ty::Tuple(..), Tuple(..)) => true,
(&ty::Array(..), Array) => true, (&ty::Array(..), Array) => true,
(&ty::Slice(..), Slice) => 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 // unresolved inference variables here anyway, but there might be
// during typeck under some circumstances.) // during typeck under some circumstances.)
let obligations = wf::obligations(infcx, param_env, hir::CRATE_HIR_ID, 0, arg, DUMMY_SP) 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 // N.B., all of these predicates *ought* to be easily proven
// true. In fact, their correctness is (mostly) implied by // true. In fact, their correctness is (mostly) implied by