Skip to content

Commit 2ea368e

Browse files
committed
minor code cleanups
1 parent 37d7de3 commit 2ea368e

File tree

8 files changed

+11
-20
lines changed

8 files changed

+11
-20
lines changed

compiler/rustc_abi/src/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -802,12 +802,9 @@ impl Integer {
802802
pub fn for_align<C: HasDataLayout>(cx: &C, wanted: Align) -> Option<Integer> {
803803
let dl = cx.data_layout();
804804

805-
for candidate in [I8, I16, I32, I64, I128] {
806-
if wanted == candidate.align(dl).abi && wanted.bytes() == candidate.size().bytes() {
807-
return Some(candidate);
808-
}
809-
}
810-
None
805+
[I8, I16, I32, I64, I128].into_iter().find(|&candidate| {
806+
wanted == candidate.align(dl).abi && wanted.bytes() == candidate.size().bytes()
807+
})
811808
}
812809

813810
/// Find the largest integer with the given alignment or less.

compiler/rustc_data_structures/src/base_n.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub const MAX_BASE: usize = 64;
99
pub const ALPHANUMERIC_ONLY: usize = 62;
1010
pub const CASE_INSENSITIVE: usize = 36;
1111

12-
const BASE_64: &[u8; MAX_BASE as usize] =
12+
const BASE_64: &[u8; MAX_BASE] =
1313
b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$";
1414

1515
#[inline]

compiler/rustc_errors/src/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ impl Diagnostic {
802802
debug_assert!(
803803
!(suggestions
804804
.iter()
805-
.flat_map(|suggs| suggs)
805+
.flatten()
806806
.any(|(sp, suggestion)| sp.is_empty() && suggestion.is_empty())),
807807
"Span must not be empty and have no suggestion"
808808
);

compiler/rustc_errors/src/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ impl EmitterWriter {
13081308
// see how it *looks* with
13091309
// very *weird* formats
13101310
// see?
1311-
for &(ref text, ref style) in msg.iter() {
1311+
for (text, style) in msg.iter() {
13121312
let text = self.translate_message(text, args);
13131313
let lines = text.split('\n').collect::<Vec<_>>();
13141314
if lines.len() > 1 {
@@ -1370,7 +1370,7 @@ impl EmitterWriter {
13701370
buffer.append(0, ": ", header_style);
13711371
label_width += 2;
13721372
}
1373-
for &(ref text, _) in msg.iter() {
1373+
for (text, _) in msg.iter() {
13741374
let text = self.translate_message(text, args);
13751375
// Account for newlines to align output to its label.
13761376
for (line, text) in normalize_whitespace(&text).lines().enumerate() {

compiler/rustc_hir/src/hir.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,7 @@ impl<'hir> Generics<'hir> {
548548
}
549549

550550
pub fn get_named(&self, name: Symbol) -> Option<&GenericParam<'hir>> {
551-
for param in self.params {
552-
if name == param.name.ident().name {
553-
return Some(param);
554-
}
555-
}
556-
None
551+
self.params.iter().find(|&param| name == param.name.ident().name)
557552
}
558553

559554
pub fn spans(&self) -> MultiSpan {

compiler/rustc_index/src/bit_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<T: Idx> BitSet<T> {
209209
self.words[start_word_index] |= !(start_mask - 1);
210210
// And all trailing bits (i.e. from 0..=end) in the end word,
211211
// including the end.
212-
self.words[end_word_index] |= end_mask | end_mask - 1;
212+
self.words[end_word_index] |= end_mask | (end_mask - 1);
213213
} else {
214214
self.words[start_word_index] |= end_mask | (end_mask - start_mask);
215215
}

compiler/rustc_lexer/src/unescape.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,13 @@ fn scan_escape(chars: &mut Chars<'_>, is_byte: bool) -> Result<char, EscapeError
204204
})?;
205205
}
206206
Some(c) => {
207-
let digit =
207+
let digit: u32 =
208208
c.to_digit(16).ok_or(EscapeError::InvalidCharInUnicodeEscape)?;
209209
n_digits += 1;
210210
if n_digits > 6 {
211211
// Stop updating value since we're sure that it's incorrect already.
212212
continue;
213213
}
214-
let digit = digit as u32;
215214
value = value * 16 + digit;
216215
}
217216
};

compiler/rustc_span/src/source_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ impl FilePathMapping {
11501150
// NOTE: We are iterating over the mapping entries from last to first
11511151
// because entries specified later on the command line should
11521152
// take precedence.
1153-
for &(ref from, ref to) in mapping.iter().rev() {
1153+
for (from, to) in mapping.iter().rev() {
11541154
debug!("Trying to apply {from:?} => {to:?}");
11551155

11561156
if let Ok(rest) = path.strip_prefix(from) {

0 commit comments

Comments
 (0)