Skip to content

Commit

Permalink
Simplify a few functions in rustc_data_structures
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Jul 24, 2018
1 parent baba500 commit 86d0e9e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/librustc_data_structures/accumulate_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<A> Encodable for AccumulateVec<A>
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
try!(s.emit_seq_elt(i, |s| e.encode(s)));
s.emit_seq_elt(i, |s| e.encode(s))?;
}
Ok(())
})
Expand All @@ -236,8 +236,7 @@ impl<A> Decodable for AccumulateVec<A>
A::Element: Decodable {
fn decode<D: Decoder>(d: &mut D) -> Result<AccumulateVec<A>, D::Error> {
d.read_seq(|d, len| {
Ok(try!((0..len).map(|i| d.read_seq_elt(i, |d| Decodable::decode(d))).collect()))
(0..len).map(|i| d.read_seq_elt(i, |d| Decodable::decode(d))).collect()
})
}
}

3 changes: 1 addition & 2 deletions src/librustc_data_structures/bitslice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String {
assert!(mask <= 0xFF);
let byte = v & mask;

result.push(sep);
result.push_str(&format!("{:02x}", byte));
result.push_str(&format!("{}{:02x}", sep, byte));

if remain <= 8 { break; }
v >>= 8;
Expand Down
8 changes: 2 additions & 6 deletions src/librustc_data_structures/small_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<A> Encodable for SmallVec<A>
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_seq(self.len(), |s| {
for (i, e) in self.iter().enumerate() {
try!(s.emit_seq_elt(i, |s| e.encode(s)));
s.emit_seq_elt(i, |s| e.encode(s))?;
}
Ok(())
})
Expand All @@ -209,11 +209,7 @@ impl<A> Decodable for SmallVec<A>
A::Element: Decodable {
fn decode<D: Decoder>(d: &mut D) -> Result<SmallVec<A>, D::Error> {
d.read_seq(|d, len| {
let mut vec = SmallVec::with_capacity(len);
for i in 0..len {
vec.push(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
}
Ok(vec)
(0..len).map(|i| d.read_seq_elt(i, |d| Decodable::decode(d))).collect()
})
}
}

0 comments on commit 86d0e9e

Please sign in to comment.