diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 4ca59144b2990..8c71332bfabb1 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -802,12 +802,9 @@ impl Integer { pub fn for_align(cx: &C, wanted: Align) -> Option { let dl = cx.data_layout(); - for candidate in [I8, I16, I32, I64, I128] { - if wanted == candidate.align(dl).abi && wanted.bytes() == candidate.size().bytes() { - return Some(candidate); - } - } - None + [I8, I16, I32, I64, I128].into_iter().find(|&candidate| { + wanted == candidate.align(dl).abi && wanted.bytes() == candidate.size().bytes() + }) } /// Find the largest integer with the given alignment or less. diff --git a/compiler/rustc_data_structures/src/base_n.rs b/compiler/rustc_data_structures/src/base_n.rs index 3c7bea2712409..4567759c004da 100644 --- a/compiler/rustc_data_structures/src/base_n.rs +++ b/compiler/rustc_data_structures/src/base_n.rs @@ -9,7 +9,7 @@ pub const MAX_BASE: usize = 64; pub const ALPHANUMERIC_ONLY: usize = 62; pub const CASE_INSENSITIVE: usize = 36; -const BASE_64: &[u8; MAX_BASE as usize] = +const BASE_64: &[u8; MAX_BASE] = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$"; #[inline] diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 06bb5edc090f4..0f79bc558bf26 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -802,7 +802,7 @@ impl Diagnostic { debug_assert!( !(suggestions .iter() - .flat_map(|suggs| suggs) + .flatten() .any(|(sp, suggestion)| sp.is_empty() && suggestion.is_empty())), "Span must not be empty and have no suggestion" ); diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 4df2198fb0e9b..aaf0699f0dc41 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1308,7 +1308,7 @@ impl EmitterWriter { // see how it *looks* with // very *weird* formats // see? - for &(ref text, ref style) in msg.iter() { + for (text, style) in msg.iter() { let text = self.translate_message(text, args); let lines = text.split('\n').collect::>(); if lines.len() > 1 { @@ -1370,7 +1370,7 @@ impl EmitterWriter { buffer.append(0, ": ", header_style); label_width += 2; } - for &(ref text, _) in msg.iter() { + for (text, _) in msg.iter() { let text = self.translate_message(text, args); // Account for newlines to align output to its label. for (line, text) in normalize_whitespace(&text).lines().enumerate() { diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 8bc022e1e178e..91825c29258ac 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -548,12 +548,7 @@ impl<'hir> Generics<'hir> { } pub fn get_named(&self, name: Symbol) -> Option<&GenericParam<'hir>> { - for param in self.params { - if name == param.name.ident().name { - return Some(param); - } - } - None + self.params.iter().find(|¶m| name == param.name.ident().name) } pub fn spans(&self) -> MultiSpan { diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index 777112442f010..686cb6dac4962 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -209,7 +209,7 @@ impl BitSet { self.words[start_word_index] |= !(start_mask - 1); // And all trailing bits (i.e. from 0..=end) in the end word, // including the end. - self.words[end_word_index] |= end_mask | end_mask - 1; + self.words[end_word_index] |= end_mask | (end_mask - 1); } else { self.words[start_word_index] |= end_mask | (end_mask - start_mask); } diff --git a/compiler/rustc_lexer/src/unescape.rs b/compiler/rustc_lexer/src/unescape.rs index e405013dcabf8..87c44638a8de1 100644 --- a/compiler/rustc_lexer/src/unescape.rs +++ b/compiler/rustc_lexer/src/unescape.rs @@ -204,14 +204,13 @@ fn scan_escape(chars: &mut Chars<'_>, is_byte: bool) -> Result { - let digit = + let digit: u32 = c.to_digit(16).ok_or(EscapeError::InvalidCharInUnicodeEscape)?; n_digits += 1; if n_digits > 6 { // Stop updating value since we're sure that it's incorrect already. continue; } - let digit = digit as u32; value = value * 16 + digit; } }; diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 43a3172270733..a4e0f54d27670 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -1150,7 +1150,7 @@ impl FilePathMapping { // NOTE: We are iterating over the mapping entries from last to first // because entries specified later on the command line should // take precedence. - for &(ref from, ref to) in mapping.iter().rev() { + for (from, to) in mapping.iter().rev() { debug!("Trying to apply {from:?} => {to:?}"); if let Ok(rest) = path.strip_prefix(from) {