Skip to content

Commit de59844

Browse files
committed
more clippy::complexity fixes
1 parent fbf8b93 commit de59844

File tree

13 files changed

+23
-41
lines changed

13 files changed

+23
-41
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,20 +2466,14 @@ pub enum ModKind {
24662466
Unloaded,
24672467
}
24682468

2469-
#[derive(Copy, Clone, Encodable, Decodable, Debug)]
2469+
#[derive(Copy, Clone, Encodable, Decodable, Debug, Default)]
24702470
pub struct ModSpans {
24712471
/// `inner_span` covers the body of the module; for a file module, its the whole file.
24722472
/// For an inline module, its the span inside the `{ ... }`, not including the curly braces.
24732473
pub inner_span: Span,
24742474
pub inject_use_span: Span,
24752475
}
24762476

2477-
impl Default for ModSpans {
2478-
fn default() -> ModSpans {
2479-
ModSpans { inner_span: Default::default(), inject_use_span: Default::default() }
2480-
}
2481-
}
2482-
24832477
/// Foreign module declaration.
24842478
///
24852479
/// E.g., `extern { .. }` or `extern "C" { .. }`.

compiler/rustc_data_structures/src/sorted_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ impl<K: Ord, V> SortedMap<K, V> {
126126
/// Iterate over the keys, sorted
127127
#[inline]
128128
pub fn keys(&self) -> impl Iterator<Item = &K> + ExactSizeIterator + DoubleEndedIterator {
129-
self.data.iter().map(|&(ref k, _)| k)
129+
self.data.iter().map(|(k, _)| k)
130130
}
131131

132132
/// Iterate over values, sorted by key
133133
#[inline]
134134
pub fn values(&self) -> impl Iterator<Item = &V> + ExactSizeIterator + DoubleEndedIterator {
135-
self.data.iter().map(|&(_, ref v)| v)
135+
self.data.iter().map(|(_, v)| v)
136136
}
137137

138138
#[inline]
@@ -222,7 +222,7 @@ impl<K: Ord, V> SortedMap<K, V> {
222222
K: Borrow<Q>,
223223
Q: Ord + ?Sized,
224224
{
225-
self.data.binary_search_by(|&(ref x, _)| x.borrow().cmp(key))
225+
self.data.binary_search_by(|(x, _)| x.borrow().cmp(key))
226226
}
227227

228228
#[inline]
@@ -300,7 +300,7 @@ impl<K: Ord, V> FromIterator<(K, V)> for SortedMap<K, V> {
300300
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
301301
let mut data: Vec<(K, V)> = iter.into_iter().collect();
302302

303-
data.sort_unstable_by(|&(ref k1, _), &(ref k2, _)| k1.cmp(k2));
303+
data.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2));
304304
data.dedup_by(|&mut (ref k1, _), &mut (ref k2, _)| k1.cmp(k2) == Ordering::Equal);
305305

306306
SortedMap { data }

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ impl FileWithAnnotatedLines {
23132313
}
23142314

23152315
// Find overlapping multiline annotations, put them at different depths
2316-
multiline_annotations.sort_by_key(|&(_, ref ml)| (ml.line_start, usize::MAX - ml.line_end));
2316+
multiline_annotations.sort_by_key(|(_, ml)| (ml.line_start, usize::MAX - ml.line_end));
23172317
for (_, ann) in multiline_annotations.clone() {
23182318
for (_, a) in multiline_annotations.iter_mut() {
23192319
// Move all other multiline annotations overlapping with this one

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl CodeSuggestion {
324324
// Account for the difference between the width of the current code and the
325325
// snippet being suggested, so that the *later* suggestions are correctly
326326
// aligned on the screen.
327-
acc += len as isize - (cur_hi.col.0 - cur_lo.col.0) as isize;
327+
acc += len - (cur_hi.col.0 - cur_lo.col.0) as isize;
328328
}
329329
prev_hi = cur_hi;
330330
prev_line = sf.get_line(prev_hi.line - 1);

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,6 @@ impl<'a> State<'a> {
17571757
self.print_qpath(qpath, true);
17581758
self.popen();
17591759
if let Some(ddpos) = ddpos.as_opt_usize() {
1760-
let ddpos = ddpos as usize;
17611760
self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(p));
17621761
if ddpos != 0 {
17631762
self.word_space(",");

compiler/rustc_macros/src/diagnostics/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl Mismatch {
192192
let crate_name = std::env::var("CARGO_CRATE_NAME").ok()?;
193193

194194
// If we're not in a "rustc_" crate, bail.
195-
let Some(("rustc", slug_prefix)) = crate_name.split_once("_") else { return None };
195+
let Some(("rustc", slug_prefix)) = crate_name.split_once('_') else { return None };
196196

197197
let slug_name = slug.segments.first()?.ident.to_string();
198198
if !slug_name.starts_with(slug_prefix) {

compiler/rustc_session/src/config.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -875,18 +875,12 @@ pub struct PacRet {
875875
pub key: PAuthKey,
876876
}
877877

878-
#[derive(Clone, Copy, Hash, Debug, PartialEq)]
878+
#[derive(Clone, Copy, Hash, Debug, PartialEq, Default)]
879879
pub struct BranchProtection {
880880
pub bti: bool,
881881
pub pac_ret: Option<PacRet>,
882882
}
883883

884-
impl Default for BranchProtection {
885-
fn default() -> Self {
886-
BranchProtection { bti: false, pac_ret: None }
887-
}
888-
}
889-
890884
pub const fn default_lib_output() -> CrateType {
891885
CrateType::Rlib
892886
}
@@ -1875,7 +1869,7 @@ fn parse_opt_level(
18751869
.into_iter()
18761870
.flat_map(|(i, s)| {
18771871
// NB: This can match a string without `=`.
1878-
if let Some("opt-level") = s.splitn(2, '=').next() { Some(i) } else { None }
1872+
if let Some("opt-level") = s.split('=').next() { Some(i) } else { None }
18791873
})
18801874
.max();
18811875
if max_o > max_c {
@@ -1912,7 +1906,7 @@ fn select_debuginfo(
19121906
.into_iter()
19131907
.flat_map(|(i, s)| {
19141908
// NB: This can match a string without `=`.
1915-
if let Some("debuginfo") = s.splitn(2, '=').next() { Some(i) } else { None }
1909+
if let Some("debuginfo") = s.split('=').next() { Some(i) } else { None }
19161910
})
19171911
.max();
19181912
if max_g > max_c {

compiler/rustc_span/src/analyze_source_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ cfg_if::cfg_if! {
175175
// There might still be a tail left to analyze
176176
let tail_start = chunk_count * CHUNK_SIZE + intra_chunk_offset;
177177
if tail_start < src.len() {
178-
analyze_source_file_generic(&src[tail_start as usize ..],
178+
analyze_source_file_generic(&src[tail_start ..],
179179
src.len() - tail_start,
180180
output_offset + BytePos::from_usize(tail_start),
181181
lines,
@@ -219,7 +219,7 @@ fn analyze_source_file_generic(
219219
while i < scan_len {
220220
let byte = unsafe {
221221
// We verified that i < scan_len <= src.len()
222-
*src_bytes.get_unchecked(i as usize)
222+
*src_bytes.get_unchecked(i)
223223
};
224224

225225
// How much to advance in order to get to the next UTF-8 char in the

compiler/rustc_span/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ impl<S: Encoder> Encodable<S> for SourceFile {
13811381
4 => {
13821382
raw_diffs = Vec::with_capacity(bytes_per_diff * num_diffs);
13831383
for diff in diff_iter {
1384-
raw_diffs.extend_from_slice(&(diff.0 as u32).to_le_bytes());
1384+
raw_diffs.extend_from_slice(&(diff.0).to_le_bytes());
13851385
}
13861386
}
13871387
_ => unreachable!(),

compiler/rustc_span/src/source_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ impl SourceMap {
941941
/// Otherwise, the span reached to limit is returned.
942942
pub fn span_look_ahead(&self, span: Span, expect: Option<&str>, limit: Option<usize>) -> Span {
943943
let mut sp = span;
944-
for _ in 0..limit.unwrap_or(100 as usize) {
944+
for _ in 0..limit.unwrap_or(100_usize) {
945945
sp = self.next_point(sp);
946946
if let Ok(ref snippet) = self.span_to_snippet(sp) {
947947
if expect.map_or(false, |es| snippet == es) {

0 commit comments

Comments
 (0)