Skip to content

rustfmt some submodules of libcore #28896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 48 additions & 14 deletions src/libcore/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ pub struct DebugStruct<'a, 'b: 'a> {
has_fields: bool,
}

pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, name: &str)
pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>,
name: &str)
-> DebugStruct<'a, 'b> {
let result = fmt.write_str(name);
DebugStruct {
Expand All @@ -84,7 +85,8 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {

if self.is_pretty() {
let mut writer = PadAdapter::new(self.fmt);
fmt::write(&mut writer, format_args!("{}\n{}: {:#?}", prefix, name, value))
fmt::write(&mut writer,
format_args!("{}\n{}: {:#?}", prefix, name, value))
} else {
write!(self.fmt, "{} {}: {:?}", prefix, name, value)
}
Expand Down Expand Up @@ -195,10 +197,18 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
self.result = self.result.and_then(|_| {
if self.is_pretty() {
let mut writer = PadAdapter::new(self.fmt);
let prefix = if self.has_fields { "," } else { "" };
let prefix = if self.has_fields {
","
} else {
""
};
fmt::write(&mut writer, format_args!("{}\n{:#?}", prefix, entry))
} else {
let prefix = if self.has_fields { ", " } else { "" };
let prefix = if self.has_fields {
", "
} else {
""
};
write!(self.fmt, "{}{:?}", prefix, entry)
}
});
Expand All @@ -207,7 +217,11 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
}

pub fn finish(&mut self) {
let prefix = if self.is_pretty() && self.has_fields { "\n" } else { "" };
let prefix = if self.is_pretty() && self.has_fields {
"\n"
} else {
""
};
self.result = self.result.and_then(|_| self.fmt.write_str(prefix));
}

Expand All @@ -232,7 +246,7 @@ pub fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b
fmt: fmt,
result: result,
has_fields: false,
}
},
}
}

Expand All @@ -247,7 +261,9 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> {
/// Adds the contents of an iterator of entries to the set output.
#[stable(feature = "debug_builders", since = "1.2.0")]
pub fn entries<D, I>(&mut self, entries: I) -> &mut DebugSet<'a, 'b>
where D: fmt::Debug, I: IntoIterator<Item=D> {
where D: fmt::Debug,
I: IntoIterator<Item = D>
{
for entry in entries {
self.entry(&entry);
}
Expand Down Expand Up @@ -278,7 +294,7 @@ pub fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a,
fmt: fmt,
result: result,
has_fields: false,
}
},
}
}

Expand All @@ -293,7 +309,9 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {
/// Adds the contents of an iterator of entries to the list output.
#[stable(feature = "debug_builders", since = "1.2.0")]
pub fn entries<D, I>(&mut self, entries: I) -> &mut DebugList<'a, 'b>
where D: fmt::Debug, I: IntoIterator<Item=D> {
where D: fmt::Debug,
I: IntoIterator<Item = D>
{
for entry in entries {
self.entry(&entry);
}
Expand Down Expand Up @@ -335,10 +353,19 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
self.result = self.result.and_then(|_| {
if self.is_pretty() {
let mut writer = PadAdapter::new(self.fmt);
let prefix = if self.has_fields { "," } else { "" };
fmt::write(&mut writer, format_args!("{}\n{:#?}: {:#?}", prefix, key, value))
let prefix = if self.has_fields {
","
} else {
""
};
fmt::write(&mut writer,
format_args!("{}\n{:#?}: {:#?}", prefix, key, value))
} else {
let prefix = if self.has_fields { ", " } else { "" };
let prefix = if self.has_fields {
", "
} else {
""
};
write!(self.fmt, "{}{:?}: {:?}", prefix, key, value)
}
});
Expand All @@ -350,7 +377,10 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
/// Adds the contents of an iterator of entries to the map output.
#[stable(feature = "debug_builders", since = "1.2.0")]
pub fn entries<K, V, I>(&mut self, entries: I) -> &mut DebugMap<'a, 'b>
where K: fmt::Debug, V: fmt::Debug, I: IntoIterator<Item=(K, V)> {
where K: fmt::Debug,
V: fmt::Debug,
I: IntoIterator<Item = (K, V)>
{
for (k, v) in entries {
self.entry(&k, &v);
}
Expand All @@ -360,7 +390,11 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
/// Finishes output and returns any error encountered.
#[stable(feature = "debug_builders", since = "1.2.0")]
pub fn finish(&mut self) -> fmt::Result {
let prefix = if self.is_pretty() && self.has_fields { "\n" } else { "" };
let prefix = if self.is_pretty() && self.has_fields {
"\n"
} else {
""
};
self.result.and_then(|_| write!(self.fmt, "{}}}", prefix))
}

Expand Down
22 changes: 17 additions & 5 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ trait GenericRadix {
fn base(&self) -> u8;

/// A radix-specific prefix string.
fn prefix(&self) -> &'static str { "" }
fn prefix(&self) -> &'static str {
""
}

/// Converts an integer to corresponding radix digit.
fn digit(&self, x: u8) -> u8;
Expand All @@ -70,7 +72,10 @@ trait GenericRadix {
x = x / base; // Deaccumulate the number.
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
curr -= 1;
if x == zero { break }; // No more digits left to accumulate.
if x == zero {
// No more digits left to accumulate.
break
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @nrc, perhaps rustfmt could auto-remove these semicolons?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
} else {
// Do the same as above, but accounting for two's complement.
Expand All @@ -79,7 +84,10 @@ trait GenericRadix {
x = x / base; // Deaccumulate the number.
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
curr -= 1;
if x == zero { break }; // No more digits left to accumulate.
if x == zero {
// No more digits left to accumulate.
break
};
}
}
let buf = unsafe { str::from_utf8_unchecked(&buf[curr..]) };
Expand Down Expand Up @@ -141,13 +149,17 @@ pub struct Radix {

impl Radix {
fn new(base: u8) -> Radix {
assert!(2 <= base && base <= 36, "the base must be in the range of 2..36: {}", base);
assert!(2 <= base && base <= 36,
"the base must be in the range of 2..36: {}",
base);
Radix { base: base }
}
}

impl GenericRadix for Radix {
fn base(&self) -> u8 { self.base }
fn base(&self) -> u8 {
self.base
}
fn digit(&self, x: u8) -> u8 {
match x {
x @ 0 ... 9 => b'0' + x,
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/rt/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ pub enum Count {
#[derive(Copy, Clone)]
pub enum Position {
Next,
At(usize)
At(usize),
}
31 changes: 22 additions & 9 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ pub trait Hash {

/// Feeds a slice of this type into the state provided.
#[stable(feature = "hash_slice", since = "1.3.0")]
fn hash_slice<H: Hasher>(data: &[Self], state: &mut H) where Self: Sized {
fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
where Self: Sized
{
for piece in data {
piece.hash(state);
}
Expand All @@ -121,7 +123,9 @@ pub trait Hasher {
/// Write a single `u8` into this hasher
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_u8(&mut self, i: u8) { self.write(&[i]) }
fn write_u8(&mut self, i: u8) {
self.write(&[i])
}
/// Write a single `u16` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
Expand All @@ -145,32 +149,41 @@ pub trait Hasher {
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_usize(&mut self, i: usize) {
let bytes = unsafe {
::slice::from_raw_parts(&i as *const usize as *const u8,
mem::size_of::<usize>())
::slice::from_raw_parts(&i as *const usize as *const u8, mem::size_of::<usize>())
};
self.write(bytes);
}

/// Write a single `i8` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i8(&mut self, i: i8) { self.write_u8(i as u8) }
fn write_i8(&mut self, i: i8) {
self.write_u8(i as u8)
}
/// Write a single `i16` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i16(&mut self, i: i16) { self.write_u16(i as u16) }
fn write_i16(&mut self, i: i16) {
self.write_u16(i as u16)
}
/// Write a single `i32` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i32(&mut self, i: i32) { self.write_u32(i as u32) }
fn write_i32(&mut self, i: i32) {
self.write_u32(i as u32)
}
/// Write a single `i64` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i64(&mut self, i: i64) { self.write_u64(i as u64) }
fn write_i64(&mut self, i: i64) {
self.write_u64(i as u64)
}
/// Write a single `isize` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_isize(&mut self, i: isize) { self.write_usize(i as usize) }
fn write_isize(&mut self, i: isize) {
self.write_usize(i as usize)
}
}

//////////////////////////////////////////////////////////////////////////////
Expand Down
11 changes: 5 additions & 6 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ pub struct SipHasher {
// and simd implementations of SipHash will use vectors
// of v02 and v13. By placing them in this order in the struct,
// the compiler can pick up on just a few simd optimizations by itself.
v0: u64, // hash state
v0: u64, // hash state
v2: u64,
v1: u64,
v3: u64,
tail: u64, // unprocessed bytes le
ntail: usize, // how many bytes in tail are valid
ntail: usize, // how many bytes in tail are valid
}

// sadly, these macro definitions can't appear later,
Expand Down Expand Up @@ -80,8 +80,7 @@ macro_rules! u8to64_le {
unsafe fn load_u64_le(buf: &[u8], i: usize) -> u64 {
debug_assert!(i + 8 <= buf.len());
let mut data = 0u64;
ptr::copy_nonoverlapping(buf.get_unchecked(i),
&mut data as *mut _ as *mut u8, 8);
ptr::copy_nonoverlapping(buf.get_unchecked(i), &mut data as *mut _ as *mut u8, 8);
data.to_le()
}

Expand Down Expand Up @@ -152,12 +151,12 @@ impl Hasher for SipHasher {
if self.ntail != 0 {
needed = 8 - self.ntail;
if length < needed {
self.tail |= u8to64_le!(msg, 0, length) << 8*self.ntail;
self.tail |= u8to64_le!(msg, 0, length) << 8 * self.ntail;
self.ntail += length;
return
}

let m = self.tail | u8to64_le!(msg, 0, needed) << 8*self.ntail;
let m = self.tail | u8to64_le!(msg, 0, needed) << 8 * self.ntail;

self.v3 ^= m;
compress!(self.v0, self.v1, self.v2, self.v3);
Expand Down