Run rustfmt on selectors, servo_arc, and style.

This was generated with:

./mach cargo fmt --package selectors &&
./mach cargo fmt --package servo_arc &&
./mach cargo fmt --package style

Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
This commit is contained in:
Bobby Holley 2018-04-10 17:35:15 -07:00
parent f7ae1a37e3
commit c99bcdd4b8
181 changed files with 9981 additions and 7933 deletions

View file

@ -24,7 +24,8 @@
#![allow(missing_docs)]
extern crate nodrop;
#[cfg(feature = "servo")] extern crate serde;
#[cfg(feature = "servo")]
extern crate serde;
extern crate stable_deref_trait;
use nodrop::NoDrop;
@ -186,7 +187,9 @@ impl<T> Arc<T> {
count: atomic::AtomicUsize::new(1),
data: data,
});
Arc { p: NonZeroPtrMut::new(Box::into_raw(x)) }
Arc {
p: NonZeroPtrMut::new(Box::into_raw(x)),
}
}
#[inline]
@ -217,7 +220,8 @@ impl<T> Arc<T> {
/// provided callback. The refcount is not modified.
#[inline(always)]
pub fn with_raw_offset_arc<F, U>(&self, f: F) -> U
where F: FnOnce(&RawOffsetArc<T>) -> U
where
F: FnOnce(&RawOffsetArc<T>) -> U,
{
// Synthesize transient Arc, which never touches the refcount of the ArcInner.
let transient = unsafe { NoDrop::new(Arc::into_raw_offset(ptr::read(self))) };
@ -256,7 +260,6 @@ impl<T: ?Sized> Arc<T> {
let _ = Box::from_raw(self.ptr());
}
#[inline]
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
this.ptr() == other.ptr()
@ -296,7 +299,9 @@ impl<T: ?Sized> Clone for Arc<T> {
process::abort();
}
Arc { p: NonZeroPtrMut::new(self.ptr()) }
Arc {
p: NonZeroPtrMut::new(self.ptr()),
}
}
}
@ -484,8 +489,7 @@ unsafe impl<T: ?Sized> StableDeref for Arc<T> {}
unsafe impl<T: ?Sized> CloneStableDeref for Arc<T> {}
#[cfg(feature = "servo")]
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc<T>
{
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc<T> {
fn deserialize<D>(deserializer: D) -> Result<Arc<T>, D::Error>
where
D: ::serde::de::Deserializer<'de>,
@ -495,8 +499,7 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Arc<T>
}
#[cfg(feature = "servo")]
impl<T: Serialize> Serialize for Arc<T>
{
impl<T: Serialize> Serialize for Arc<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: ::serde::ser::Serializer,
@ -526,9 +529,10 @@ impl<H, T> Arc<HeaderSlice<H, [T]>> {
/// iterator to generate the slice. The resulting Arc will be fat.
#[inline]
pub fn from_header_and_iter<I>(header: H, mut items: I) -> Self
where I: Iterator<Item=T> + ExactSizeIterator
where
I: Iterator<Item = T> + ExactSizeIterator,
{
use ::std::mem::size_of;
use std::mem::size_of;
assert_ne!(size_of::<T>(), 0, "Need to think about ZST");
// Compute the required size for the allocation.
@ -592,18 +596,32 @@ impl<H, T> Arc<HeaderSlice<H, [T]>> {
ptr::write(&mut ((*ptr).data.header), header);
let mut current: *mut T = &mut (*ptr).data.slice[0];
for _ in 0..num_items {
ptr::write(current, items.next().expect("ExactSizeIterator over-reported length"));
ptr::write(
current,
items
.next()
.expect("ExactSizeIterator over-reported length"),
);
current = current.offset(1);
}
assert!(items.next().is_none(), "ExactSizeIterator under-reported length");
assert!(
items.next().is_none(),
"ExactSizeIterator under-reported length"
);
// We should have consumed the buffer exactly.
debug_assert_eq!(current as *mut u8, buffer.offset(size as isize));
}
// Return the fat Arc.
assert_eq!(size_of::<Self>(), size_of::<usize>() * 2, "The Arc will be fat");
Arc { p: NonZeroPtrMut::new(ptr) }
assert_eq!(
size_of::<Self>(),
size_of::<usize>() * 2,
"The Arc will be fat"
);
Arc {
p: NonZeroPtrMut::new(ptr),
}
}
#[inline]
@ -647,13 +665,11 @@ unsafe impl<H: Sync + Send, T: Sync + Send> Sync for ThinArc<H, T> {}
// Synthesize a fat pointer from a thin pointer.
//
// See the comment around the analogous operation in from_header_and_iter.
fn thin_to_thick<H, T>(thin: *mut ArcInner<HeaderSliceWithLength<H, [T; 1]>>)
-> *mut ArcInner<HeaderSliceWithLength<H, [T]>>
{
fn thin_to_thick<H, T>(
thin: *mut ArcInner<HeaderSliceWithLength<H, [T; 1]>>,
) -> *mut ArcInner<HeaderSliceWithLength<H, [T]>> {
let len = unsafe { (*thin).data.header.length };
let fake_slice: *mut [T] = unsafe {
slice::from_raw_parts_mut(thin as *mut T, len)
};
let fake_slice: *mut [T] = unsafe { slice::from_raw_parts_mut(thin as *mut T, len) };
fake_slice as *mut ArcInner<HeaderSliceWithLength<H, [T]>>
}
@ -663,11 +679,12 @@ impl<H: 'static, T: 'static> ThinArc<H, T> {
/// provided callback. The refcount is not modified.
#[inline]
pub fn with_arc<F, U>(&self, f: F) -> U
where F: FnOnce(&Arc<HeaderSliceWithLength<H, [T]>>) -> U
where
F: FnOnce(&Arc<HeaderSliceWithLength<H, [T]>>) -> U,
{
// Synthesize transient Arc, which never touches the refcount of the ArcInner.
let transient = NoDrop::new(Arc {
p: NonZeroPtrMut::new(thin_to_thick(self.ptr))
p: NonZeroPtrMut::new(thin_to_thick(self.ptr)),
});
// Expose the transient Arc to the callback, which may clone it if it wants.
@ -718,13 +735,16 @@ impl<H: 'static, T: 'static> Arc<HeaderSliceWithLength<H, [T]>> {
/// is not modified.
#[inline]
pub fn into_thin(a: Self) -> ThinArc<H, T> {
assert_eq!(a.header.length, a.slice.len(),
"Length needs to be correct for ThinArc to work");
assert_eq!(
a.header.length,
a.slice.len(),
"Length needs to be correct for ThinArc to work"
);
let fat_ptr: *mut ArcInner<HeaderSliceWithLength<H, [T]>> = a.ptr();
mem::forget(a);
let thin_ptr = fat_ptr as *mut [usize] as *mut usize;
ThinArc {
ptr: thin_ptr as *mut ArcInner<HeaderSliceWithLength<H, [T; 1]>>
ptr: thin_ptr as *mut ArcInner<HeaderSliceWithLength<H, [T; 1]>>,
}
}
@ -735,7 +755,7 @@ impl<H: 'static, T: 'static> Arc<HeaderSliceWithLength<H, [T]>> {
let ptr = thin_to_thick(a.ptr);
mem::forget(a);
Arc {
p: NonZeroPtrMut::new(ptr)
p: NonZeroPtrMut::new(ptr),
}
}
}
@ -743,11 +763,7 @@ impl<H: 'static, T: 'static> Arc<HeaderSliceWithLength<H, [T]>> {
impl<H: PartialEq + 'static, T: PartialEq + 'static> PartialEq for ThinArc<H, T> {
#[inline]
fn eq(&self, other: &ThinArc<H, T>) -> bool {
ThinArc::with_arc(self, |a| {
ThinArc::with_arc(other, |b| {
*a == *b
})
})
ThinArc::with_arc(self, |a| ThinArc::with_arc(other, |b| *a == *b))
}
}
@ -793,11 +809,12 @@ impl<T: 'static> Clone for RawOffsetArc<T> {
impl<T: 'static> Drop for RawOffsetArc<T> {
fn drop(&mut self) {
let _ = Arc::from_raw_offset(RawOffsetArc { ptr: self.ptr.clone() });
let _ = Arc::from_raw_offset(RawOffsetArc {
ptr: self.ptr.clone(),
});
}
}
impl<T: fmt::Debug + 'static> fmt::Debug for RawOffsetArc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
@ -819,7 +836,8 @@ impl<T: 'static> RawOffsetArc<T> {
/// provided callback. The refcount is not modified.
#[inline]
pub fn with_arc<F, U>(&self, f: F) -> U
where F: FnOnce(&Arc<T>) -> U
where
F: FnOnce(&Arc<T>) -> U,
{
// Synthesize transient Arc, which never touches the refcount of the ArcInner.
let transient = unsafe { NoDrop::new(Arc::from_raw(self.ptr.ptr())) };
@ -839,7 +857,10 @@ impl<T: 'static> RawOffsetArc<T> {
/// If uniquely owned, provide a mutable reference
/// Else create a copy, and mutate that
#[inline]
pub fn make_mut(&mut self) -> &mut T where T: Clone {
pub fn make_mut(&mut self) -> &mut T
where
T: Clone,
{
unsafe {
// extract the RawOffsetArc as an owned variable
let this = ptr::read(self);
@ -931,7 +952,11 @@ impl<'a, T> ArcBorrow<'a, T> {
}
#[inline]
pub fn with_arc<F, U>(&self, f: F) -> U where F: FnOnce(&Arc<T>) -> U, T: 'static {
pub fn with_arc<F, U>(&self, f: F) -> U
where
F: FnOnce(&Arc<T>) -> U,
T: 'static,
{
// Synthesize transient Arc, which never touches the refcount.
let transient = unsafe { NoDrop::new(Arc::from_raw(self.0)) };
@ -970,7 +995,9 @@ mod tests {
impl Drop for Canary {
fn drop(&mut self) {
unsafe { (*self.0).fetch_add(1, SeqCst); }
unsafe {
(*self.0).fetch_add(1, SeqCst);
}
}
}