Skip to content

Commit 0fbf7ea

Browse files
committed
Rollup merge of #28896 - mkpankov:core-fmt, r=nrc
<!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/rust-lang/rust/28896) <!-- Reviewable:end -->
2 parents fb09639 + 11a7773 commit 0fbf7ea

File tree

5 files changed

+93
-35
lines changed

5 files changed

+93
-35
lines changed

src/libcore/fmt/builders.rs

+48-14
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub struct DebugStruct<'a, 'b: 'a> {
6161
has_fields: bool,
6262
}
6363

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

8586
if self.is_pretty() {
8687
let mut writer = PadAdapter::new(self.fmt);
87-
fmt::write(&mut writer, format_args!("{}\n{}: {:#?}", prefix, name, value))
88+
fmt::write(&mut writer,
89+
format_args!("{}\n{}: {:#?}", prefix, name, value))
8890
} else {
8991
write!(self.fmt, "{} {}: {:?}", prefix, name, value)
9092
}
@@ -195,10 +197,18 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
195197
self.result = self.result.and_then(|_| {
196198
if self.is_pretty() {
197199
let mut writer = PadAdapter::new(self.fmt);
198-
let prefix = if self.has_fields { "," } else { "" };
200+
let prefix = if self.has_fields {
201+
","
202+
} else {
203+
""
204+
};
199205
fmt::write(&mut writer, format_args!("{}\n{:#?}", prefix, entry))
200206
} else {
201-
let prefix = if self.has_fields { ", " } else { "" };
207+
let prefix = if self.has_fields {
208+
", "
209+
} else {
210+
""
211+
};
202212
write!(self.fmt, "{}{:?}", prefix, entry)
203213
}
204214
});
@@ -207,7 +217,11 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
207217
}
208218

209219
pub fn finish(&mut self) {
210-
let prefix = if self.is_pretty() && self.has_fields { "\n" } else { "" };
220+
let prefix = if self.is_pretty() && self.has_fields {
221+
"\n"
222+
} else {
223+
""
224+
};
211225
self.result = self.result.and_then(|_| self.fmt.write_str(prefix));
212226
}
213227

@@ -232,7 +246,7 @@ pub fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b
232246
fmt: fmt,
233247
result: result,
234248
has_fields: false,
235-
}
249+
},
236250
}
237251
}
238252

@@ -247,7 +261,9 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> {
247261
/// Adds the contents of an iterator of entries to the set output.
248262
#[stable(feature = "debug_builders", since = "1.2.0")]
249263
pub fn entries<D, I>(&mut self, entries: I) -> &mut DebugSet<'a, 'b>
250-
where D: fmt::Debug, I: IntoIterator<Item=D> {
264+
where D: fmt::Debug,
265+
I: IntoIterator<Item = D>
266+
{
251267
for entry in entries {
252268
self.entry(&entry);
253269
}
@@ -278,7 +294,7 @@ pub fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a,
278294
fmt: fmt,
279295
result: result,
280296
has_fields: false,
281-
}
297+
},
282298
}
283299
}
284300

@@ -293,7 +309,9 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {
293309
/// Adds the contents of an iterator of entries to the list output.
294310
#[stable(feature = "debug_builders", since = "1.2.0")]
295311
pub fn entries<D, I>(&mut self, entries: I) -> &mut DebugList<'a, 'b>
296-
where D: fmt::Debug, I: IntoIterator<Item=D> {
312+
where D: fmt::Debug,
313+
I: IntoIterator<Item = D>
314+
{
297315
for entry in entries {
298316
self.entry(&entry);
299317
}
@@ -335,10 +353,19 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
335353
self.result = self.result.and_then(|_| {
336354
if self.is_pretty() {
337355
let mut writer = PadAdapter::new(self.fmt);
338-
let prefix = if self.has_fields { "," } else { "" };
339-
fmt::write(&mut writer, format_args!("{}\n{:#?}: {:#?}", prefix, key, value))
356+
let prefix = if self.has_fields {
357+
","
358+
} else {
359+
""
360+
};
361+
fmt::write(&mut writer,
362+
format_args!("{}\n{:#?}: {:#?}", prefix, key, value))
340363
} else {
341-
let prefix = if self.has_fields { ", " } else { "" };
364+
let prefix = if self.has_fields {
365+
", "
366+
} else {
367+
""
368+
};
342369
write!(self.fmt, "{}{:?}: {:?}", prefix, key, value)
343370
}
344371
});
@@ -350,7 +377,10 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
350377
/// Adds the contents of an iterator of entries to the map output.
351378
#[stable(feature = "debug_builders", since = "1.2.0")]
352379
pub fn entries<K, V, I>(&mut self, entries: I) -> &mut DebugMap<'a, 'b>
353-
where K: fmt::Debug, V: fmt::Debug, I: IntoIterator<Item=(K, V)> {
380+
where K: fmt::Debug,
381+
V: fmt::Debug,
382+
I: IntoIterator<Item = (K, V)>
383+
{
354384
for (k, v) in entries {
355385
self.entry(&k, &v);
356386
}
@@ -360,7 +390,11 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
360390
/// Finishes output and returns any error encountered.
361391
#[stable(feature = "debug_builders", since = "1.2.0")]
362392
pub fn finish(&mut self) -> fmt::Result {
363-
let prefix = if self.is_pretty() && self.has_fields { "\n" } else { "" };
393+
let prefix = if self.is_pretty() && self.has_fields {
394+
"\n"
395+
} else {
396+
""
397+
};
364398
self.result.and_then(|_| write!(self.fmt, "{}}}", prefix))
365399
}
366400

src/libcore/fmt/num.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ trait GenericRadix {
4848
fn base(&self) -> u8;
4949

5050
/// A radix-specific prefix string.
51-
fn prefix(&self) -> &'static str { "" }
51+
fn prefix(&self) -> &'static str {
52+
""
53+
}
5254

5355
/// Converts an integer to corresponding radix digit.
5456
fn digit(&self, x: u8) -> u8;
@@ -70,7 +72,10 @@ trait GenericRadix {
7072
x = x / base; // Deaccumulate the number.
7173
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
7274
curr -= 1;
73-
if x == zero { break }; // No more digits left to accumulate.
75+
if x == zero {
76+
// No more digits left to accumulate.
77+
break
78+
};
7479
}
7580
} else {
7681
// Do the same as above, but accounting for two's complement.
@@ -79,7 +84,10 @@ trait GenericRadix {
7984
x = x / base; // Deaccumulate the number.
8085
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
8186
curr -= 1;
82-
if x == zero { break }; // No more digits left to accumulate.
87+
if x == zero {
88+
// No more digits left to accumulate.
89+
break
90+
};
8391
}
8492
}
8593
let buf = unsafe { str::from_utf8_unchecked(&buf[curr..]) };
@@ -141,13 +149,17 @@ pub struct Radix {
141149

142150
impl Radix {
143151
fn new(base: u8) -> Radix {
144-
assert!(2 <= base && base <= 36, "the base must be in the range of 2..36: {}", base);
152+
assert!(2 <= base && base <= 36,
153+
"the base must be in the range of 2..36: {}",
154+
base);
145155
Radix { base: base }
146156
}
147157
}
148158

149159
impl GenericRadix for Radix {
150-
fn base(&self) -> u8 { self.base }
160+
fn base(&self) -> u8 {
161+
self.base
162+
}
151163
fn digit(&self, x: u8) -> u8 {
152164
match x {
153165
x @ 0 ... 9 => b'0' + x,

src/libcore/fmt/rt/v1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ pub enum Count {
5353
#[derive(Copy, Clone)]
5454
pub enum Position {
5555
Next,
56-
At(usize)
56+
At(usize),
5757
}

src/libcore/hash/mod.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ pub trait Hash {
100100

101101
/// Feeds a slice of this type into the state provided.
102102
#[stable(feature = "hash_slice", since = "1.3.0")]
103-
fn hash_slice<H: Hasher>(data: &[Self], state: &mut H) where Self: Sized {
103+
fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
104+
where Self: Sized
105+
{
104106
for piece in data {
105107
piece.hash(state);
106108
}
@@ -121,7 +123,9 @@ pub trait Hasher {
121123
/// Write a single `u8` into this hasher
122124
#[inline]
123125
#[stable(feature = "hasher_write", since = "1.3.0")]
124-
fn write_u8(&mut self, i: u8) { self.write(&[i]) }
126+
fn write_u8(&mut self, i: u8) {
127+
self.write(&[i])
128+
}
125129
/// Write a single `u16` into this hasher.
126130
#[inline]
127131
#[stable(feature = "hasher_write", since = "1.3.0")]
@@ -145,32 +149,41 @@ pub trait Hasher {
145149
#[stable(feature = "hasher_write", since = "1.3.0")]
146150
fn write_usize(&mut self, i: usize) {
147151
let bytes = unsafe {
148-
::slice::from_raw_parts(&i as *const usize as *const u8,
149-
mem::size_of::<usize>())
152+
::slice::from_raw_parts(&i as *const usize as *const u8, mem::size_of::<usize>())
150153
};
151154
self.write(bytes);
152155
}
153156

154157
/// Write a single `i8` into this hasher.
155158
#[inline]
156159
#[stable(feature = "hasher_write", since = "1.3.0")]
157-
fn write_i8(&mut self, i: i8) { self.write_u8(i as u8) }
160+
fn write_i8(&mut self, i: i8) {
161+
self.write_u8(i as u8)
162+
}
158163
/// Write a single `i16` into this hasher.
159164
#[inline]
160165
#[stable(feature = "hasher_write", since = "1.3.0")]
161-
fn write_i16(&mut self, i: i16) { self.write_u16(i as u16) }
166+
fn write_i16(&mut self, i: i16) {
167+
self.write_u16(i as u16)
168+
}
162169
/// Write a single `i32` into this hasher.
163170
#[inline]
164171
#[stable(feature = "hasher_write", since = "1.3.0")]
165-
fn write_i32(&mut self, i: i32) { self.write_u32(i as u32) }
172+
fn write_i32(&mut self, i: i32) {
173+
self.write_u32(i as u32)
174+
}
166175
/// Write a single `i64` into this hasher.
167176
#[inline]
168177
#[stable(feature = "hasher_write", since = "1.3.0")]
169-
fn write_i64(&mut self, i: i64) { self.write_u64(i as u64) }
178+
fn write_i64(&mut self, i: i64) {
179+
self.write_u64(i as u64)
180+
}
170181
/// Write a single `isize` into this hasher.
171182
#[inline]
172183
#[stable(feature = "hasher_write", since = "1.3.0")]
173-
fn write_isize(&mut self, i: isize) { self.write_usize(i as usize) }
184+
fn write_isize(&mut self, i: isize) {
185+
self.write_usize(i as usize)
186+
}
174187
}
175188

176189
//////////////////////////////////////////////////////////////////////////////

src/libcore/hash/sip.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ pub struct SipHasher {
3737
// and simd implementations of SipHash will use vectors
3838
// of v02 and v13. By placing them in this order in the struct,
3939
// the compiler can pick up on just a few simd optimizations by itself.
40-
v0: u64, // hash state
40+
v0: u64, // hash state
4141
v2: u64,
4242
v1: u64,
4343
v3: u64,
4444
tail: u64, // unprocessed bytes le
45-
ntail: usize, // how many bytes in tail are valid
45+
ntail: usize, // how many bytes in tail are valid
4646
}
4747

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

@@ -152,12 +151,12 @@ impl Hasher for SipHasher {
152151
if self.ntail != 0 {
153152
needed = 8 - self.ntail;
154153
if length < needed {
155-
self.tail |= u8to64_le!(msg, 0, length) << 8*self.ntail;
154+
self.tail |= u8to64_le!(msg, 0, length) << 8 * self.ntail;
156155
self.ntail += length;
157156
return
158157
}
159158

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

162161
self.v3 ^= m;
163162
compress!(self.v0, self.v1, self.v2, self.v3);

0 commit comments

Comments
 (0)