Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
style: upgrade the rustfmt rule version to Version::Two
Browse files Browse the repository at this point in the history
It's unstable at the moment, though:
<rust-lang/rustfmt#3383>
  • Loading branch information
yvt committed Feb 7, 2020
1 parent 8613696 commit 979a35a
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 84 deletions.
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
edition = "2018"
version = "Two"
24 changes: 4 additions & 20 deletions support/alt_fp/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,24 @@ pub trait FloatOrd {
impl FloatOrd for f32 {
#[inline]
fn fmin(self, x: Self) -> Self {
if self < x {
self
} else {
x
}
if self < x { self } else { x }
}

#[inline]
fn fmax(self, x: Self) -> Self {
if self > x {
self
} else {
x
}
if self > x { self } else { x }
}
}

impl FloatOrd for f64 {
#[inline]
fn fmin(self, x: Self) -> Self {
if self < x {
self
} else {
x
}
if self < x { self } else { x }
}

#[inline]
fn fmax(self, x: Self) -> Self {
if self > x {
self
} else {
x
}
if self > x { self } else { x }
}
}

Expand Down
4 changes: 3 additions & 1 deletion support/cggeom/src/average.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ macro_rules! impl_int {
}

impl_float!(f32, f64);
impl_int!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
impl_int!(
u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize
);

macro_rules! impl_struct {
($ty:ty, {$($field:ident),*}) => {
Expand Down
6 changes: 1 addition & 5 deletions support/cggeom/src/boxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,7 @@ pub trait AxisAlignedBox<T>: Sized {
self.min().element_wise_max(&other.min()),
self.max().element_wise_min(&other.max()),
);
if s.is_empty() {
None
} else {
Some(s)
}
if s.is_empty() { None } else { Some(s) }
}

#[inline]
Expand Down
12 changes: 2 additions & 10 deletions support/cggeom/src/elementwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ pub trait ElementWisePartialOrd {

#[inline]
fn num_min<T: BaseNum>(x: T, y: T) -> T {
if y < x {
y
} else {
x
}
if y < x { y } else { x }
}

#[inline]
fn num_max<T: BaseNum>(x: T, y: T) -> T {
if y > x {
y
} else {
x
}
if y > x { y } else { x }
}

impl<T: BaseNum> ElementWiseOp for Point2<T> {
Expand Down
12 changes: 7 additions & 5 deletions support/rope/benches/rope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ fn bench_iter(b: &mut Bencher, count: usize) {

let mut it = rope.iter();

b.iter(|| loop {
if let Some(e) = it.next() {
break e;
} else {
it = rope.iter();
b.iter(|| {
loop {
if let Some(e) = it.next() {
break e;
} else {
it = rope.iter();
}
}
});
}
Expand Down
6 changes: 1 addition & 5 deletions support/rope/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ where

if let Some((c, o)) = co {
// TODO: This is utterly inefficient
if c == self.end() {
None
} else {
Some((c, o))
}
if c == self.end() { None } else { Some((c, o)) }
} else {
None
}
Expand Down
4 changes: 2 additions & 2 deletions tcw3/designer/src/codegen/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl Parse for CompItemOn {
return Err(Error::new_spanned(
vis,
"visibility specification is not allowed for `on`",
))
));
}
}

Expand Down Expand Up @@ -690,7 +690,7 @@ impl Parse for ObjInit {
return Err(Error::new_spanned(
mac,
"Invalid delimiter for object initialization literal",
))
));
}
};

Expand Down
6 changes: 1 addition & 5 deletions tcw3/pal/src/macos/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ impl IdRef {
}

pub fn non_nil(self) -> Option<IdRef> {
if self.0 == nil {
None
} else {
Some(self)
}
if self.0 == nil { None } else { Some(self) }
}
}

Expand Down
6 changes: 1 addition & 5 deletions tcw3/pal/src/swrast/binner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,11 +1182,7 @@ fn saturating_aabb_f32_to_u16(bx: Box2<f32>) -> Option<Box2<u16>> {
max: [bx.max.x.fmax(0.0).fmin(MAX) as u16, bx.max.y.fmax(0.0).fmin(MAX) as u16],
};

if bx.is_empty() {
None
} else {
Some(bx)
}
if bx.is_empty() { None } else { Some(bx) }
}

/// Given a parallelogram, construct clip planes.
Expand Down
6 changes: 1 addition & 5 deletions tcw3/pal/src/swrast/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ mod tests {
fn test_box2_usize_union(coords: Vec<usize>) -> TestResult {
let boxes = coords.chunks_exact(4).map(|coords| {
let bx = box2! { min: [coords[0], coords[1]], max: [coords[2], coords[3]] };
if bx.is_empty() {
None
} else {
Some(bx)
}
if bx.is_empty() { None } else { Some(bx) }
});

let expected = boxes
Expand Down
24 changes: 13 additions & 11 deletions tcw3/pal/src/windows/frameclock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,22 @@ impl DisplayLink {

let inner = self.inner.as_inner_ref().unwrap();

std::thread::spawn(move || loop {
// Suspend if the display link is requested to stop.
if !inner.running.load(Ordering::Relaxed) {
let mut guard = inner.mutex.lock().unwrap();
while !inner.running.load(Ordering::Relaxed) {
guard = inner.cv.wait(guard).unwrap();
std::thread::spawn(move || {
loop {
// Suspend if the display link is requested to stop.
if !inner.running.load(Ordering::Relaxed) {
let mut guard = inner.mutex.lock().unwrap();
while !inner.running.load(Ordering::Relaxed) {
guard = inner.cv.wait(guard).unwrap();
}
}
}

// This is rather surprising, but actually what Firefox
// seems to do.
unsafe { DwmFlush() };
// This is rather surprising, but actually what Firefox
// seems to do.
unsafe { DwmFlush() };

handler();
handler();
}
});

inner
Expand Down
6 changes: 1 addition & 5 deletions tcw3/src/ui/scrolling/lineset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,11 +1815,7 @@ fn line_gr_decim_excl(
/// and below.
fn lod_coverage(lod: u8, scale: Index) -> Index {
debug_assert!(scale >= 0);
if lod > 0 {
scale << (lod - 1)
} else {
0
}
if lod > 0 { scale << (lod - 1) } else { 0 }
}

/// Get the smallest `lod` such that `lod_coverage(lod, scale) >= i`.
Expand Down
6 changes: 1 addition & 5 deletions tcw3/src/ui/views/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,7 @@ mod tests {
trait Transpose: Sized {
fn t(self) -> Self;
fn t_if(self, cond: bool) -> Self {
if cond {
self.t()
} else {
self
}
if cond { self.t() } else { self }
}
}

Expand Down

0 comments on commit 979a35a

Please sign in to comment.