Skip to content

Commit 73aa2bd

Browse files
authored
Rollup merge of rust-lang#64942 - JohnTitor:fix-clippy, r=eddyb
Fix clippy warnings * Use `match` instead of `if` chain * Remove redundant `into_iter()` * Use `copied()` instead of `map()` etc.
2 parents 76fb91b + f10d2e2 commit 73aa2bd

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

src/libarena/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ impl DroplessArena {
500500
// though it was supposed to give us `len`
501501
return slice::from_raw_parts_mut(mem, i);
502502
}
503-
ptr::write(mem.offset(i as isize), value.unwrap());
503+
ptr::write(mem.add(i), value.unwrap());
504504
i += 1;
505505
}
506506
}

src/librustc_apfloat/ieee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1199,8 +1199,8 @@ impl<S: Semantics> Float for IeeeFloat<S> {
11991199
}
12001200

12011201
// Handle a leading minus sign.
1202-
let minus = s.starts_with("-");
1203-
if minus || s.starts_with("+") {
1202+
let minus = s.starts_with('-');
1203+
if minus || s.starts_with('+') {
12041204
s = &s[1..];
12051205
if s.is_empty() {
12061206
return Err(ParseError("String has no digits"));

src/librustc_data_structures/graph/implementation/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ pub struct AdjacentEdges<'g, N, E> {
303303

304304
impl<'g, N: Debug, E: Debug> AdjacentEdges<'g, N, E> {
305305
fn targets(self) -> impl Iterator<Item = NodeIndex> + 'g {
306-
self.into_iter().map(|(_, edge)| edge.target)
306+
self.map(|(_, edge)| edge.target)
307307
}
308308

309309
fn sources(self) -> impl Iterator<Item = NodeIndex> + 'g {
310-
self.into_iter().map(|(_, edge)| edge.source)
310+
self.map(|(_, edge)| edge.source)
311311
}
312312
}
313313

src/librustc_index/bit_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ impl<'a, T: Idx> Iterator for HybridIter<'a, T> {
621621

622622
fn next(&mut self) -> Option<T> {
623623
match self {
624-
HybridIter::Sparse(sparse) => sparse.next().map(|e| *e),
624+
HybridIter::Sparse(sparse) => sparse.next().copied(),
625625
HybridIter::Dense(dense) => dense.next(),
626626
}
627627
}

src/libserialize/json.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1053,12 +1053,12 @@ impl Json {
10531053
/// a value associated with the provided key is found. If no value is found
10541054
/// or the Json value is not an Object, returns `None`.
10551055
pub fn search(&self, key: &str) -> Option<&Json> {
1056-
match self {
1057-
&Json::Object(ref map) => {
1056+
match *self {
1057+
Json::Object(ref map) => {
10581058
match map.get(key) {
10591059
Some(json_value) => Some(json_value),
10601060
None => {
1061-
for (_, v) in map {
1061+
for v in map.values() {
10621062
match v.search(key) {
10631063
x if x.is_some() => return x,
10641064
_ => ()
@@ -1487,12 +1487,12 @@ impl<T: Iterator<Item=char>> Parser<T> {
14871487
}
14881488

14891489
fn parse_number(&mut self) -> JsonEvent {
1490-
let mut neg = false;
1491-
1492-
if self.ch_is('-') {
1490+
let neg = if self.ch_is('-') {
14931491
self.bump();
1494-
neg = true;
1495-
}
1492+
true
1493+
} else {
1494+
false
1495+
};
14961496

14971497
let res = match self.parse_u64() {
14981498
Ok(res) => res,
@@ -2162,10 +2162,9 @@ impl crate::Decoder for Decoder {
21622162
let s = self.read_str()?;
21632163
{
21642164
let mut it = s.chars();
2165-
match (it.next(), it.next()) {
2165+
if let (Some(c), None) = (it.next(), it.next()) {
21662166
// exactly one character
2167-
(Some(c), None) => return Ok(c),
2168-
_ => ()
2167+
return Ok(c);
21692168
}
21702169
}
21712170
Err(ExpectedError("single character string".to_owned(), s.to_string()))

0 commit comments

Comments
 (0)