Skip to content

Commit 40688f6

Browse files
committed
Run cargo fmt on all projects
Apply the same formatting rules to both `libm` and `compiler-builtins`.
1 parent 0bd4d0a commit 40688f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1070
-283
lines changed

builtins-test-intrinsics/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ mod intrinsics {
480480

481481
fn run() {
482482
use core::hint::black_box as bb;
483+
483484
use intrinsics::*;
484485

485486
// FIXME(f16_f128): some PPC f128 <-> int conversion functions have the wrong names

builtins-test/benches/float_cmp.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![cfg_attr(f128_enabled, feature(f128))]
22

33
use builtins_test::float_bench;
4-
use criterion::{Criterion, criterion_main};
5-
64
use compiler_builtins::float::cmp;
5+
use criterion::{Criterion, criterion_main};
76

87
/// `gt` symbols are allowed to return differing results, they just get compared
98
/// to 0.

builtins-test/benches/mem_icount.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,10 @@ mod mcmp {
239239
}
240240

241241
mod mmove {
242-
use super::*;
243242
use Spread::{Aligned, Large, Medium, Small};
244243

244+
use super::*;
245+
245246
struct Cfg {
246247
len: usize,
247248
spread: Spread,

builtins-test/src/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use alloc::vec::Vec;
12
use core::cell::RefCell;
23

3-
use alloc::vec::Vec;
44
use compiler_builtins::float::Float;
55

66
/// Fuzz with these many items to ensure equal functions

builtins-test/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ extern crate alloc;
2121

2222
use compiler_builtins::float::Float;
2323
use compiler_builtins::int::{Int, MinInt};
24-
2524
use rand_xoshiro::Xoshiro128StarStar;
2625
use rand_xoshiro::rand_core::{RngCore, SeedableRng};
2726

builtins-test/tests/cmp.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ mod float_comparisons {
9797
__eqkf2 as __eqtf2, __gekf2 as __getf2, __gtkf2 as __gttf2, __lekf2 as __letf2,
9898
__ltkf2 as __lttf2, __nekf2 as __netf2, __unordkf2 as __unordtf2,
9999
};
100-
101100
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
102101
use compiler_builtins::float::cmp::{
103102
__eqtf2, __getf2, __gttf2, __letf2, __lttf2, __netf2, __unordtf2,

builtins-test/tests/div_rem.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#![feature(f128)]
22
#![allow(unused_macros)]
33

4+
use builtins_test::*;
45
use compiler_builtins::int::sdiv::{__divmoddi4, __divmodsi4, __divmodti4};
56
use compiler_builtins::int::udiv::{__udivmoddi4, __udivmodsi4, __udivmodti4, u128_divide_sparc};
67

7-
use builtins_test::*;
8-
98
// Division algorithms have by far the nastiest and largest number of edge cases, and experience shows
109
// that sometimes 100_000 iterations of the random fuzzer is needed.
1110

compiler-builtins/build.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
mod configure;
22

3-
use std::{collections::BTreeMap, env, path::PathBuf, sync::atomic::Ordering};
3+
use std::collections::BTreeMap;
4+
use std::env;
5+
use std::path::PathBuf;
6+
use std::sync::atomic::Ordering;
47

5-
use configure::{configure_aliases, configure_f16_f128, Target};
8+
use configure::{Target, configure_aliases, configure_f16_f128};
69

710
fn main() {
811
println!("cargo::rerun-if-changed=build.rs");

compiler-builtins/src/arm_linux.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use core::arch;
2-
use core::mem;
31
use core::sync::atomic::{AtomicU32, Ordering};
2+
use core::{arch, mem};
43

54
// Kernel-provided user-mode helper functions:
65
// https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt

compiler-builtins/src/float/conv.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use core::ops::Neg;
22

3-
use crate::int::{CastFrom, CastInto, Int, MinInt};
4-
53
use super::Float;
4+
use crate::int::{CastFrom, CastInto, Int, MinInt};
65

76
/// Conversions from integers to floats.
87
///

compiler-builtins/src/float/div.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@
7979
//!
8080
//! [Newton-Raphson method]: https://en.wikipedia.org/wiki/Newton%27s_method
8181
82+
use core::mem::size_of;
83+
use core::ops;
84+
8285
use super::HalfRep;
8386
use crate::float::Float;
8487
use crate::int::{CastFrom, CastInto, DInt, HInt, Int, MinInt};
85-
use core::mem::size_of;
86-
use core::ops;
8788

8889
fn div<F: Float>(a: F, b: F) -> F
8990
where
@@ -487,7 +488,7 @@ where
487488
};
488489

489490
residual_lo += abs_result & one; // tie to even
490-
// conditionally turns the below LT comparison into LTE
491+
// conditionally turns the below LT comparison into LTE
491492
abs_result += u8::from(residual_lo > b_significand).into();
492493

493494
if F::BITS == 128 || (F::BITS == 32 && half_iterations > 0) {

compiler-builtins/src/float/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ pub mod trunc;
1111

1212
#[cfg(not(feature = "public-test-deps"))]
1313
pub(crate) use traits::{Float, HalfRep};
14-
1514
#[cfg(feature = "public-test-deps")]
1615
pub use traits::{Float, HalfRep};

compiler-builtins/src/float/pow.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ fn pow<F: Float>(a: F, b: i32) -> F {
1818
a *= a;
1919
}
2020

21-
if recip {
22-
F::ONE / mul
23-
} else {
24-
mul
25-
}
21+
if recip { F::ONE / mul } else { mul }
2622
}
2723

2824
intrinsics! {

compiler-builtins/src/int/big.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
33
#![allow(unused)]
44

5-
use crate::int::{DInt, HInt, Int, MinInt};
65
use core::{fmt, ops};
76

7+
use crate::int::{DInt, HInt, Int, MinInt};
8+
89
const WORD_LO_MASK: u64 = 0x00000000ffffffff;
910
const WORD_HI_MASK: u64 = 0xffffffff00000000;
1011
const WORD_FULL_MASK: u64 = 0xffffffffffffffff;

compiler-builtins/src/int/leading_zeros.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ mod implementation {
6060
}
6161
// the last two bisections are combined into one conditional
6262
t = x >> 1;
63-
if t != T::ZERO {
64-
z - 2
65-
} else {
66-
z - x.cast()
67-
}
63+
if t != T::ZERO { z - 2 } else { z - x.cast() }
6864

6965
// We could potentially save a few cycles by using the LUT trick from
7066
// "https://embeddedgurus.com/state-space/2014/09/

compiler-builtins/src/int/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ mod traits;
1212
pub mod udiv;
1313

1414
pub use big::{i256, u256};
15-
1615
#[cfg(not(feature = "public-test-deps"))]
1716
pub(crate) use traits::{CastFrom, CastInto, DInt, HInt, Int, MinInt};
18-
1917
#[cfg(feature = "public-test-deps")]
2018
pub use traits::{CastFrom, CastInto, DInt, HInt, Int, MinInt};

compiler-builtins/src/int/specialized_div_rem/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ mod delegate;
5858
#[allow(unused_imports)]
5959
#[cfg(not(feature = "public-test-deps"))]
6060
pub(crate) use self::delegate::u128_divide_sparc;
61-
6261
#[cfg(feature = "public-test-deps")]
6362
pub use self::delegate::u128_divide_sparc;
6463

compiler-builtins/src/int/udiv.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#[cfg(not(feature = "public-test-deps"))]
22
pub(crate) use crate::int::specialized_div_rem::*;
3-
43
#[cfg(feature = "public-test-deps")]
54
pub use crate::int::specialized_div_rem::*;
65

compiler-builtins/src/mem/x86_64.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
// Note that ERMSB does not enhance the backwards (DF=1) "rep movsb".
1818

1919
use core::arch::asm;
20-
use core::intrinsics;
21-
use core::mem;
20+
use core::{intrinsics, mem};
2221

2322
#[inline(always)]
2423
#[cfg(target_feature = "ermsb")]

crates/libm-macros/src/enums.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ pub fn function_enum(
2626
};
2727

2828
if let Some(tt) = attr.next() {
29-
return Err(syn::Error::new(tt.span(), "unexpected token after identifier"));
29+
return Err(syn::Error::new(
30+
tt.span(),
31+
"unexpected token after identifier",
32+
));
3033
}
3134

3235
let enum_name = &item.ident;
@@ -46,8 +49,12 @@ pub fn function_enum(
4649
// Match arm for `fn base_name(self)` matcher
4750
base_arms.push(quote! { Self::#ident => #base_enum::#bname_ident });
4851

49-
let variant =
50-
Variant { attrs: Vec::new(), ident, fields: Fields::Unit, discriminant: None };
52+
let variant = Variant {
53+
attrs: Vec::new(),
54+
ident,
55+
fields: Fields::Unit,
56+
discriminant: None,
57+
};
5158

5259
item.variants.push(variant);
5360
}
@@ -108,7 +115,10 @@ pub fn base_name_enum(
108115
return Err(syn::Error::new(sp.span(), "no attributes expected"));
109116
}
110117

111-
let mut base_names: Vec<_> = ALL_OPERATIONS.iter().map(|func| base_name(func.name)).collect();
118+
let mut base_names: Vec<_> = ALL_OPERATIONS
119+
.iter()
120+
.map(|func| base_name(func.name))
121+
.collect();
112122
base_names.sort_unstable();
113123
base_names.dedup();
114124

@@ -121,8 +131,12 @@ pub fn base_name_enum(
121131
// Match arm for `fn as_str(self)` matcher
122132
as_str_arms.push(quote! { Self::#ident => #base_name });
123133

124-
let variant =
125-
Variant { attrs: Vec::new(), ident, fields: Fields::Unit, discriminant: None };
134+
let variant = Variant {
135+
attrs: Vec::new(),
136+
ident,
137+
fields: Fields::Unit,
138+
discriminant: None,
139+
};
126140

127141
item.variants.push(variant);
128142
}
@@ -147,7 +161,10 @@ pub fn base_name_enum(
147161
/// Verify that an enum is empty, otherwise return an error
148162
fn expect_empty_enum(item: &ItemEnum) -> syn::Result<()> {
149163
if !item.variants.is_empty() {
150-
Err(syn::Error::new(item.variants.span(), "expected an empty enum"))
164+
Err(syn::Error::new(
165+
item.variants.span(),
166+
"expected an empty enum",
167+
))
151168
} else {
152169
Ok(())
153170
}

crates/libm-macros/src/lib.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use syn::spanned::Spanned;
1111
use syn::visit_mut::VisitMut;
1212
use syn::{Ident, ItemEnum};
1313

14-
const KNOWN_TYPES: &[&str] = &["FTy", "CFn", "CArgs", "CRet", "RustFn", "RustArgs", "RustRet"];
14+
const KNOWN_TYPES: &[&str] = &[
15+
"FTy", "CFn", "CArgs", "CRet", "RustFn", "RustArgs", "RustRet",
16+
];
1517

1618
/// Populate an enum with a variant representing function. Names are in upper camel case.
1719
///
@@ -142,10 +144,17 @@ fn validate(input: &mut StructuredInput) -> syn::Result<Vec<&'static MathOpInfo>
142144
.flat_map(|map_list| map_list.iter())
143145
.flat_map(|attr_map| attr_map.names.iter());
144146
let only_mentions = input.only.iter().flat_map(|only_list| only_list.iter());
145-
let fn_extra_mentions =
146-
input.fn_extra.iter().flat_map(|v| v.keys()).filter(|name| *name != "_");
147-
let all_mentioned_fns =
148-
input.skip.iter().chain(only_mentions).chain(attr_mentions).chain(fn_extra_mentions);
147+
let fn_extra_mentions = input
148+
.fn_extra
149+
.iter()
150+
.flat_map(|v| v.keys())
151+
.filter(|name| *name != "_");
152+
let all_mentioned_fns = input
153+
.skip
154+
.iter()
155+
.chain(only_mentions)
156+
.chain(attr_mentions)
157+
.chain(fn_extra_mentions);
149158

150159
// Make sure that every function mentioned is a real function
151160
for mentioned in all_mentioned_fns {
@@ -171,7 +180,11 @@ fn validate(input: &mut StructuredInput) -> syn::Result<Vec<&'static MathOpInfo>
171180
for func in ALL_OPERATIONS.iter() {
172181
let fn_name = func.name;
173182
// If we have an `only` list and it does _not_ contain this function name, skip it
174-
if input.only.as_ref().is_some_and(|only| !only.iter().any(|o| o == fn_name)) {
183+
if input
184+
.only
185+
.as_ref()
186+
.is_some_and(|only| !only.iter().any(|o| o == fn_name))
187+
{
175188
continue;
176189
}
177190

@@ -296,8 +309,11 @@ fn expand(input: StructuredInput, fn_list: &[&MathOpInfo]) -> syn::Result<pm2::T
296309
// Prepare function-specific extra in a `fn_extra: ...` field, running the replacer
297310
let fn_extra_field = match input.fn_extra {
298311
Some(ref map) => {
299-
let mut fn_extra =
300-
map.get(&fn_name).or_else(|| map.get(&default_ident)).unwrap().clone();
312+
let mut fn_extra = map
313+
.get(&fn_name)
314+
.or_else(|| map.get(&default_ident))
315+
.unwrap()
316+
.clone();
301317

302318
let mut v = MacroReplace::new(func.name);
303319
v.visit_expr_mut(&mut fn_extra);
@@ -357,7 +373,11 @@ struct MacroReplace {
357373
impl MacroReplace {
358374
fn new(name: &'static str) -> Self {
359375
let norm_name = base_name(name);
360-
Self { fn_name: name, norm_name: norm_name.to_owned(), error: None }
376+
Self {
377+
fn_name: name,
378+
norm_name: norm_name.to_owned(),
379+
error: None,
380+
}
361381
}
362382

363383
fn finish(self) -> syn::Result<()> {
@@ -377,8 +397,10 @@ impl MacroReplace {
377397
"MACRO_FN_NAME" => *i = Ident::new(self.fn_name, i.span()),
378398
"MACRO_FN_NAME_NORMALIZED" => *i = Ident::new(&self.norm_name, i.span()),
379399
_ => {
380-
self.error =
381-
Some(syn::Error::new(i.span(), format!("unrecognized meta expression `{s}`")));
400+
self.error = Some(syn::Error::new(
401+
i.span(),
402+
format!("unrecognized meta expression `{s}`"),
403+
));
382404
}
383405
}
384406
}

0 commit comments

Comments
 (0)