From 979a35a9726be2ed3b9b0ca98a8b271256d0f120 Mon Sep 17 00:00:00 2001 From: yvt Date: Fri, 7 Feb 2020 14:58:13 +0900 Subject: [PATCH] style: upgrade the rustfmt rule version to `Version::Two` It's unstable at the moment, though: --- .rustfmt.toml | 1 + support/alt_fp/src/cmp.rs | 24 ++++-------------------- support/cggeom/src/average.rs | 4 +++- support/cggeom/src/boxes.rs | 6 +----- support/cggeom/src/elementwise.rs | 12 ++---------- support/rope/benches/rope.rs | 12 +++++++----- support/rope/src/ops.rs | 6 +----- tcw3/designer/src/codegen/parser.rs | 4 ++-- tcw3/pal/src/macos/utils.rs | 6 +----- tcw3/pal/src/swrast/binner.rs | 6 +----- tcw3/pal/src/swrast/utils.rs | 6 +----- tcw3/pal/src/windows/frameclock.rs | 24 +++++++++++++----------- tcw3/src/ui/scrolling/lineset.rs | 6 +----- tcw3/src/ui/views/scrollbar.rs | 6 +----- 14 files changed, 39 insertions(+), 84 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index 32a9786f..634d9b6a 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1 +1,2 @@ edition = "2018" +version = "Two" diff --git a/support/alt_fp/src/cmp.rs b/support/alt_fp/src/cmp.rs index a3a69f48..2385b288 100644 --- a/support/alt_fp/src/cmp.rs +++ b/support/alt_fp/src/cmp.rs @@ -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 } } } diff --git a/support/cggeom/src/average.rs b/support/cggeom/src/average.rs index cde8654d..54fc0afe 100644 --- a/support/cggeom/src/average.rs +++ b/support/cggeom/src/average.rs @@ -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),*}) => { diff --git a/support/cggeom/src/boxes.rs b/support/cggeom/src/boxes.rs index 42907157..1b4941f5 100644 --- a/support/cggeom/src/boxes.rs +++ b/support/cggeom/src/boxes.rs @@ -191,11 +191,7 @@ pub trait AxisAlignedBox: 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] diff --git a/support/cggeom/src/elementwise.rs b/support/cggeom/src/elementwise.rs index 72e18385..cb06208c 100644 --- a/support/cggeom/src/elementwise.rs +++ b/support/cggeom/src/elementwise.rs @@ -23,20 +23,12 @@ pub trait ElementWisePartialOrd { #[inline] fn num_min(x: T, y: T) -> T { - if y < x { - y - } else { - x - } + if y < x { y } else { x } } #[inline] fn num_max(x: T, y: T) -> T { - if y > x { - y - } else { - x - } + if y > x { y } else { x } } impl ElementWiseOp for Point2 { diff --git a/support/rope/benches/rope.rs b/support/rope/benches/rope.rs index 4e323080..3809b35d 100644 --- a/support/rope/benches/rope.rs +++ b/support/rope/benches/rope.rs @@ -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(); + } } }); } diff --git a/support/rope/src/ops.rs b/support/rope/src/ops.rs index 0617320f..4fe2ae14 100644 --- a/support/rope/src/ops.rs +++ b/support/rope/src/ops.rs @@ -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 } diff --git a/tcw3/designer/src/codegen/parser.rs b/tcw3/designer/src/codegen/parser.rs index dff571ee..6a3aca76 100644 --- a/tcw3/designer/src/codegen/parser.rs +++ b/tcw3/designer/src/codegen/parser.rs @@ -444,7 +444,7 @@ impl Parse for CompItemOn { return Err(Error::new_spanned( vis, "visibility specification is not allowed for `on`", - )) + )); } } @@ -690,7 +690,7 @@ impl Parse for ObjInit { return Err(Error::new_spanned( mac, "Invalid delimiter for object initialization literal", - )) + )); } }; diff --git a/tcw3/pal/src/macos/utils.rs b/tcw3/pal/src/macos/utils.rs index fe977b54..6bdbc9eb 100644 --- a/tcw3/pal/src/macos/utils.rs +++ b/tcw3/pal/src/macos/utils.rs @@ -28,11 +28,7 @@ impl IdRef { } pub fn non_nil(self) -> Option { - if self.0 == nil { - None - } else { - Some(self) - } + if self.0 == nil { None } else { Some(self) } } } diff --git a/tcw3/pal/src/swrast/binner.rs b/tcw3/pal/src/swrast/binner.rs index 8f36c8f0..d30f17f9 100644 --- a/tcw3/pal/src/swrast/binner.rs +++ b/tcw3/pal/src/swrast/binner.rs @@ -1182,11 +1182,7 @@ fn saturating_aabb_f32_to_u16(bx: Box2) -> Option> { 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. diff --git a/tcw3/pal/src/swrast/utils.rs b/tcw3/pal/src/swrast/utils.rs index 949370de..9af2cbcc 100644 --- a/tcw3/pal/src/swrast/utils.rs +++ b/tcw3/pal/src/swrast/utils.rs @@ -95,11 +95,7 @@ mod tests { fn test_box2_usize_union(coords: Vec) -> 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 diff --git a/tcw3/pal/src/windows/frameclock.rs b/tcw3/pal/src/windows/frameclock.rs index 99e0ea98..8b119e72 100644 --- a/tcw3/pal/src/windows/frameclock.rs +++ b/tcw3/pal/src/windows/frameclock.rs @@ -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 diff --git a/tcw3/src/ui/scrolling/lineset.rs b/tcw3/src/ui/scrolling/lineset.rs index 5538e8bb..0ec71a0a 100644 --- a/tcw3/src/ui/scrolling/lineset.rs +++ b/tcw3/src/ui/scrolling/lineset.rs @@ -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`. diff --git a/tcw3/src/ui/views/scrollbar.rs b/tcw3/src/ui/views/scrollbar.rs index 1132c92f..0f45728f 100644 --- a/tcw3/src/ui/views/scrollbar.rs +++ b/tcw3/src/ui/views/scrollbar.rs @@ -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 } } }