From de59844c98f7925242a798a72c59dc3610dd0e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Thu, 15 Dec 2022 00:06:34 +0100 Subject: [PATCH] more clippy::complexity fixes --- compiler/rustc_ast/src/ast.rs | 8 +------- compiler/rustc_data_structures/src/sorted_map.rs | 8 ++++---- compiler/rustc_errors/src/emitter.rs | 2 +- compiler/rustc_errors/src/lib.rs | 2 +- compiler/rustc_hir_pretty/src/lib.rs | 1 - compiler/rustc_macros/src/diagnostics/diagnostic.rs | 2 +- compiler/rustc_session/src/config.rs | 12 +++--------- compiler/rustc_span/src/analyze_source_file.rs | 4 ++-- compiler/rustc_span/src/lib.rs | 2 +- compiler/rustc_span/src/source_map.rs | 2 +- compiler/rustc_target/src/spec/apple_base.rs | 2 +- compiler/rustc_target/src/spec/powerpc64_ibm_aix.rs | 7 +------ compiler/rustc_type_ir/src/sty.rs | 12 ++++++------ 13 files changed, 23 insertions(+), 41 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 2e86970bcfd..f933b9b161c 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2466,7 +2466,7 @@ pub enum ModKind { Unloaded, } -#[derive(Copy, Clone, Encodable, Decodable, Debug)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)] pub struct ModSpans { /// `inner_span` covers the body of the module; for a file module, its the whole file. /// For an inline module, its the span inside the `{ ... }`, not including the curly braces. @@ -2474,12 +2474,6 @@ pub struct ModSpans { pub inject_use_span: Span, } -impl Default for ModSpans { - fn default() -> ModSpans { - ModSpans { inner_span: Default::default(), inject_use_span: Default::default() } - } -} - /// Foreign module declaration. /// /// E.g., `extern { .. }` or `extern "C" { .. }`. diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs index 03ff5e5b375..05f059c89d5 100644 --- a/compiler/rustc_data_structures/src/sorted_map.rs +++ b/compiler/rustc_data_structures/src/sorted_map.rs @@ -126,13 +126,13 @@ pub fn iter(&self) -> std::slice::Iter<'_, (K, V)> { /// Iterate over the keys, sorted #[inline] pub fn keys(&self) -> impl Iterator + ExactSizeIterator + DoubleEndedIterator { - self.data.iter().map(|&(ref k, _)| k) + self.data.iter().map(|(k, _)| k) } /// Iterate over values, sorted by key #[inline] pub fn values(&self) -> impl Iterator + ExactSizeIterator + DoubleEndedIterator { - self.data.iter().map(|&(_, ref v)| v) + self.data.iter().map(|(_, v)| v) } #[inline] @@ -222,7 +222,7 @@ fn lookup_index_for(&self, key: &Q) -> Result K: Borrow, Q: Ord + ?Sized, { - self.data.binary_search_by(|&(ref x, _)| x.borrow().cmp(key)) + self.data.binary_search_by(|(x, _)| x.borrow().cmp(key)) } #[inline] @@ -300,7 +300,7 @@ impl FromIterator<(K, V)> for SortedMap { fn from_iter>(iter: T) -> Self { let mut data: Vec<(K, V)> = iter.into_iter().collect(); - data.sort_unstable_by(|&(ref k1, _), &(ref k2, _)| k1.cmp(k2)); + data.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2)); data.dedup_by(|&mut (ref k1, _), &mut (ref k2, _)| k1.cmp(k2) == Ordering::Equal); SortedMap { data } diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index c62e358e804..e2a0e436fd5 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2313,7 +2313,7 @@ fn add_annotation_to_file( } // Find overlapping multiline annotations, put them at different depths - multiline_annotations.sort_by_key(|&(_, ref ml)| (ml.line_start, usize::MAX - ml.line_end)); + multiline_annotations.sort_by_key(|(_, ml)| (ml.line_start, usize::MAX - ml.line_end)); for (_, ann) in multiline_annotations.clone() { for (_, a) in multiline_annotations.iter_mut() { // Move all other multiline annotations overlapping with this one diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index eb0506c459a..518b5ec10f8 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -324,7 +324,7 @@ fn push_trailing( // Account for the difference between the width of the current code and the // snippet being suggested, so that the *later* suggestions are correctly // aligned on the screen. - acc += len as isize - (cur_hi.col.0 - cur_lo.col.0) as isize; + acc += len - (cur_hi.col.0 - cur_lo.col.0) as isize; } prev_hi = cur_hi; prev_line = sf.get_line(prev_hi.line - 1); diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index ef98c4ba54c..29a6902ccb0 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -1757,7 +1757,6 @@ pub fn print_pat(&mut self, pat: &hir::Pat<'_>) { self.print_qpath(qpath, true); self.popen(); if let Some(ddpos) = ddpos.as_opt_usize() { - let ddpos = ddpos as usize; self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(p)); if ddpos != 0 { self.word_space(","); diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index 684835d8c5c..13f06fe7473 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -192,7 +192,7 @@ fn check(slug: &syn::Path) -> Option { let crate_name = std::env::var("CARGO_CRATE_NAME").ok()?; // If we're not in a "rustc_" crate, bail. - let Some(("rustc", slug_prefix)) = crate_name.split_once("_") else { return None }; + let Some(("rustc", slug_prefix)) = crate_name.split_once('_') else { return None }; let slug_name = slug.segments.first()?.ident.to_string(); if !slug_name.starts_with(slug_prefix) { diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 6de564a3a06..3bafd3730bd 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -875,18 +875,12 @@ pub struct PacRet { pub key: PAuthKey, } -#[derive(Clone, Copy, Hash, Debug, PartialEq)] +#[derive(Clone, Copy, Hash, Debug, PartialEq, Default)] pub struct BranchProtection { pub bti: bool, pub pac_ret: Option, } -impl Default for BranchProtection { - fn default() -> Self { - BranchProtection { bti: false, pac_ret: None } - } -} - pub const fn default_lib_output() -> CrateType { CrateType::Rlib } @@ -1875,7 +1869,7 @@ fn parse_opt_level( .into_iter() .flat_map(|(i, s)| { // NB: This can match a string without `=`. - if let Some("opt-level") = s.splitn(2, '=').next() { Some(i) } else { None } + if let Some("opt-level") = s.split('=').next() { Some(i) } else { None } }) .max(); if max_o > max_c { @@ -1912,7 +1906,7 @@ fn select_debuginfo( .into_iter() .flat_map(|(i, s)| { // NB: This can match a string without `=`. - if let Some("debuginfo") = s.splitn(2, '=').next() { Some(i) } else { None } + if let Some("debuginfo") = s.split('=').next() { Some(i) } else { None } }) .max(); if max_g > max_c { diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index d3c2c5113bc..26cd54210d0 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -175,7 +175,7 @@ unsafe fn analyze_source_file_sse2(src: &str, // There might still be a tail left to analyze let tail_start = chunk_count * CHUNK_SIZE + intra_chunk_offset; if tail_start < src.len() { - analyze_source_file_generic(&src[tail_start as usize ..], + analyze_source_file_generic(&src[tail_start ..], src.len() - tail_start, output_offset + BytePos::from_usize(tail_start), lines, @@ -219,7 +219,7 @@ fn analyze_source_file_generic( while i < scan_len { let byte = unsafe { // We verified that i < scan_len <= src.len() - *src_bytes.get_unchecked(i as usize) + *src_bytes.get_unchecked(i) }; // How much to advance in order to get to the next UTF-8 char in the diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 335bfc3302f..5525eb5331c 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1381,7 +1381,7 @@ fn encode(&self, s: &mut S) { 4 => { raw_diffs = Vec::with_capacity(bytes_per_diff * num_diffs); for diff in diff_iter { - raw_diffs.extend_from_slice(&(diff.0 as u32).to_le_bytes()); + raw_diffs.extend_from_slice(&(diff.0).to_le_bytes()); } } _ => unreachable!(), diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index a4e0f54d276..fb3e4a6c083 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -941,7 +941,7 @@ pub fn next_point(&self, sp: Span) -> Span { /// Otherwise, the span reached to limit is returned. pub fn span_look_ahead(&self, span: Span, expect: Option<&str>, limit: Option) -> Span { let mut sp = span; - for _ in 0..limit.unwrap_or(100 as usize) { + for _ in 0..limit.unwrap_or(100_usize) { sp = self.next_point(sp); if let Ok(ref snippet) = self.span_to_snippet(sp) { if expect.map_or(false, |es| snippet == es) { diff --git a/compiler/rustc_target/src/spec/apple_base.rs b/compiler/rustc_target/src/spec/apple_base.rs index fc6a2edabb7..44644c4733e 100644 --- a/compiler/rustc_target/src/spec/apple_base.rs +++ b/compiler/rustc_target/src/spec/apple_base.rs @@ -81,7 +81,7 @@ fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs { _ => os.into(), }; - let platform_version: StaticCow = match os.as_ref() { + let platform_version: StaticCow = match os { "ios" => ios_lld_platform_version(), "tvos" => tvos_lld_platform_version(), "watchos" => watchos_lld_platform_version(), diff --git a/compiler/rustc_target/src/spec/powerpc64_ibm_aix.rs b/compiler/rustc_target/src/spec/powerpc64_ibm_aix.rs index e3eb9bccd5e..34934379c7e 100644 --- a/compiler/rustc_target/src/spec/powerpc64_ibm_aix.rs +++ b/compiler/rustc_target/src/spec/powerpc64_ibm_aix.rs @@ -5,12 +5,7 @@ pub fn target() -> Target { base.max_atomic_width = Some(64); base.add_pre_link_args( LinkerFlavor::Unix(Cc::No), - &[ - "-b64".into(), - "-bpT:0x100000000".into(), - "-bpD:0x110000000".into(), - "-bcdtors:all:0:s".into(), - ], + &["-b64", "-bpT:0x100000000", "-bpD:0x110000000", "-bcdtors:all:0:s"], ); Target { diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index e9ffbca9628..f30ae82d7cd 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -250,9 +250,9 @@ fn clone(&self) -> Self { match self { Bool => Bool, Char => Char, - Int(i) => Int(i.clone()), - Uint(u) => Uint(u.clone()), - Float(f) => Float(f.clone()), + Int(i) => Int(*i), + Uint(u) => Uint(*u), + Float(f) => Float(*f), Adt(d, s) => Adt(d.clone(), s.clone()), Foreign(d) => Foreign(d.clone()), Str => Str, @@ -262,7 +262,7 @@ fn clone(&self) -> Self { Ref(r, t, m) => Ref(r.clone(), t.clone(), m.clone()), FnDef(d, s) => FnDef(d.clone(), s.clone()), FnPtr(s) => FnPtr(s.clone()), - Dynamic(p, r, repr) => Dynamic(p.clone(), r.clone(), repr.clone()), + Dynamic(p, r, repr) => Dynamic(p.clone(), r.clone(), *repr), Closure(d, s) => Closure(d.clone(), s.clone()), Generator(d, s, m) => Generator(d.clone(), s.clone(), m.clone()), GeneratorWitness(g) => GeneratorWitness(g.clone()), @@ -270,7 +270,7 @@ fn clone(&self) -> Self { Tuple(t) => Tuple(t.clone()), Alias(k, p) => Alias(*k, p.clone()), Param(p) => Param(p.clone()), - Bound(d, b) => Bound(d.clone(), b.clone()), + Bound(d, b) => Bound(*d, b.clone()), Placeholder(p) => Placeholder(p.clone()), Infer(t) => Infer(t.clone()), Error(e) => Error(e.clone()), @@ -936,7 +936,7 @@ impl Clone for RegionKind { fn clone(&self) -> Self { match self { ReEarlyBound(r) => ReEarlyBound(r.clone()), - ReLateBound(d, r) => ReLateBound(d.clone(), r.clone()), + ReLateBound(d, r) => ReLateBound(*d, r.clone()), ReFree(r) => ReFree(r.clone()), ReStatic => ReStatic, ReVar(r) => ReVar(r.clone()),