mirror of https://github.com/rust-lang/rust.git
Rollup merge of #76888 - matthiaskrgr:clippy_single_match_2, r=Dylan-DPC
use if let instead of single match arm expressions use if let instead of single match arm expressions to compact code and reduce nesting (clippy::single_match)
This commit is contained in:
commit
dcf4d1f2be
|
@ -488,19 +488,17 @@ impl<'tcx> Visitor<'tcx> for HirTraitObjectVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
|
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
|
||||||
match t.kind {
|
if let TyKind::TraitObject(
|
||||||
TyKind::TraitObject(
|
|
||||||
poly_trait_refs,
|
poly_trait_refs,
|
||||||
Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
|
Lifetime { name: LifetimeName::ImplicitObjectLifetimeDefault, .. },
|
||||||
) => {
|
) = t.kind
|
||||||
|
{
|
||||||
for ptr in poly_trait_refs {
|
for ptr in poly_trait_refs {
|
||||||
if Some(self.1) == ptr.trait_ref.trait_def_id() {
|
if Some(self.1) == ptr.trait_ref.trait_def_id() {
|
||||||
self.0.push(ptr.span);
|
self.0.push(ptr.span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
walk_ty(self, t);
|
walk_ty(self, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -834,15 +834,12 @@ fn foo(&self) -> Self::T { String::new() }
|
||||||
kind: hir::ItemKind::Impl { items, .. }, ..
|
kind: hir::ItemKind::Impl { items, .. }, ..
|
||||||
})) => {
|
})) => {
|
||||||
for item in &items[..] {
|
for item in &items[..] {
|
||||||
match item.kind {
|
if let hir::AssocItemKind::Type = item.kind {
|
||||||
hir::AssocItemKind::Type => {
|
|
||||||
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found {
|
if self.type_of(self.hir().local_def_id(item.id.hir_id)) == found {
|
||||||
db.span_label(item.span, "expected this associated type");
|
db.span_label(item.span, "expected this associated type");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -2125,17 +2125,10 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
|
||||||
// Iterate all local crate items no matter where they are defined.
|
// Iterate all local crate items no matter where they are defined.
|
||||||
let hir = tcx.hir();
|
let hir = tcx.hir();
|
||||||
for item in hir.krate().items.values() {
|
for item in hir.krate().items.values() {
|
||||||
if item.ident.name.as_str().is_empty() {
|
if item.ident.name.as_str().is_empty() || matches!(item.kind, ItemKind::Use(_, _)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
match item.kind {
|
|
||||||
ItemKind::Use(_, _) => {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(local_def_id) = hir.definitions().opt_hir_id_to_local_def_id(item.hir_id) {
|
if let Some(local_def_id) = hir.definitions().opt_hir_id_to_local_def_id(item.hir_id) {
|
||||||
let def_id = local_def_id.to_def_id();
|
let def_id = local_def_id.to_def_id();
|
||||||
let ns = tcx.def_kind(def_id).ns().unwrap_or(Namespace::TypeNS);
|
let ns = tcx.def_kind(def_id).ns().unwrap_or(Namespace::TypeNS);
|
||||||
|
|
|
@ -242,12 +242,9 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
TerminatorKind::InlineAsm { ref operands, .. } => {
|
TerminatorKind::InlineAsm { ref operands, .. } => {
|
||||||
for (index, op) in operands.iter().enumerate() {
|
for (index, op) in operands.iter().enumerate() {
|
||||||
match op {
|
if let InlineAsmOperand::Const { .. } = op {
|
||||||
InlineAsmOperand::Const { .. } => {
|
|
||||||
self.candidates.push(Candidate::InlineAsm { bb: location.block, index })
|
self.candidates.push(Candidate::InlineAsm { bb: location.block, index })
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -612,13 +609,10 @@ impl<'tcx> Validator<'_, 'tcx> {
|
||||||
let operand_ty = operand.ty(self.body, self.tcx);
|
let operand_ty = operand.ty(self.body, self.tcx);
|
||||||
let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast");
|
let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast");
|
||||||
let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
|
let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
|
||||||
match (cast_in, cast_out) {
|
if let (CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) = (cast_in, cast_out) {
|
||||||
(CastTy::Ptr(_) | CastTy::FnPtr, CastTy::Int(_)) => {
|
|
||||||
// ptr-to-int casts are not possible in consts and thus not promotable
|
// ptr-to-int casts are not possible in consts and thus not promotable
|
||||||
return Err(Unpromotable);
|
return Err(Unpromotable);
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Rvalue::BinaryOp(op, ref lhs, _) => {
|
Rvalue::BinaryOp(op, ref lhs, _) => {
|
||||||
|
|
|
@ -149,13 +149,10 @@ impl<'a> TokenTreesReader<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match (open_brace, delim) {
|
|
||||||
//only add braces
|
//only add braces
|
||||||
(DelimToken::Brace, DelimToken::Brace) => {
|
if let (DelimToken::Brace, DelimToken::Brace) = (open_brace, delim) {
|
||||||
self.matching_block_spans.push((open_brace_span, close_brace_span));
|
self.matching_block_spans.push((open_brace_span, close_brace_span));
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.open_braces.is_empty() {
|
if self.open_braces.is_empty() {
|
||||||
// Clear up these spans to avoid suggesting them as we've found
|
// Clear up these spans to avoid suggesting them as we've found
|
||||||
|
|
|
@ -525,13 +525,10 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
// fill character
|
// fill character
|
||||||
if let Some(&(_, c)) = self.cur.peek() {
|
if let Some(&(_, c)) = self.cur.peek() {
|
||||||
match self.cur.clone().nth(1) {
|
if let Some((_, '>' | '<' | '^')) = self.cur.clone().nth(1) {
|
||||||
Some((_, '>' | '<' | '^')) => {
|
|
||||||
spec.fill = Some(c);
|
spec.fill = Some(c);
|
||||||
self.cur.next();
|
self.cur.next();
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Alignment
|
// Alignment
|
||||||
if self.consume('<') {
|
if self.consume('<') {
|
||||||
|
|
|
@ -534,12 +534,9 @@ impl<'a> ModuleData<'a> {
|
||||||
if ns != TypeNS {
|
if ns != TypeNS {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match binding.res() {
|
if let Res::Def(DefKind::Trait | DefKind::TraitAlias, _) = binding.res() {
|
||||||
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
|
|
||||||
collected_traits.push((name, binding))
|
collected_traits.push((name, binding))
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
*traits = Some(collected_traits.into_boxed_slice());
|
*traits = Some(collected_traits.into_boxed_slice());
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,12 +152,9 @@ impl SymbolMangler<'tcx> {
|
||||||
let _ = write!(self.out, "{}", ident.len());
|
let _ = write!(self.out, "{}", ident.len());
|
||||||
|
|
||||||
// Write a separating `_` if necessary (leading digit or `_`).
|
// Write a separating `_` if necessary (leading digit or `_`).
|
||||||
match ident.chars().next() {
|
if let Some('_' | '0'..='9') = ident.chars().next() {
|
||||||
Some('_' | '0'..='9') => {
|
|
||||||
self.push("_");
|
self.push("_");
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.push(ident);
|
self.push(ident);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue