Skip to content

Commit

Permalink
Rollup merge of #105625 - matthiaskrgr:clippy_dec12, r=compiler-errors
Browse files Browse the repository at this point in the history
minor code cleanups

r? `@compiler-errors`
  • Loading branch information
matthiaskrgr authored Dec 13, 2022
2 parents 4069792 + 2ea368e commit 2707801
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 20 deletions.
9 changes: 3 additions & 6 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,9 @@ impl Integer {
pub fn for_align<C: HasDataLayout>(cx: &C, wanted: Align) -> Option<Integer> {
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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/base_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,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"
);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
if lines.len() > 1 {
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|&param| name == param.name.ident().name)
}

pub fn spans(&self) -> MultiSpan {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<T: Idx> BitSet<T> {
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);
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lexer/src/unescape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,13 @@ fn scan_escape(chars: &mut Chars<'_>, is_byte: bool) -> Result<char, EscapeError
})?;
}
Some(c) => {
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;
}
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2707801

Please sign in to comment.