Skip to content

Commit 3b8a7de

Browse files
authored
Merge pull request rust-lang#327 from tgross35/config-rustfmt
Add a rustfmt.toml file matching rust-lang/rust
2 parents f4e5b38 + 719b487 commit 3b8a7de

Some content is hidden

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

60 files changed

+142
-394
lines changed

.git-blame-ignore-revs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Use `git config blame.ignorerevsfile .git-blame-ignore-revs` to make
2+
# `git blame` ignore the following commits.
3+
4+
# Reformat with a new `.rustfmt.toml`
5+
5882cabb83c30bf7c36023f9a55a80583636b0e8

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
steps:
4242
- uses: actions/checkout@master
4343
- name: Install Rust
44-
run: rustup update stable && rustup default stable && rustup component add rustfmt
44+
run: rustup update nightly && rustup default nightly && rustup component add rustfmt
4545
- run: cargo fmt -- --check
4646

4747
wasm:

.rustfmt.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This matches rustc
2+
style_edition = "2024"
3+
use_small_heuristics = "Max"
4+
group_imports = "StdExternalCrate"
5+
imports_granularity = "Module"

crates/libm-test/build.rs

+11-32
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ fn main() {
55

66
#[cfg(feature = "test-musl-serialized")]
77
mod musl_reference_tests {
8-
use rand::seq::SliceRandom;
9-
use rand::Rng;
10-
use std::env;
11-
use std::fs;
128
use std::path::PathBuf;
139
use std::process::Command;
10+
use std::{env, fs};
11+
12+
use rand::Rng;
13+
use rand::seq::SliceRandom;
1414

1515
// Number of tests to generate for each function
1616
const NTESTS: usize = 500;
@@ -60,10 +60,7 @@ mod musl_reference_tests {
6060
return;
6161
}
6262

63-
let files = fs::read_dir(math_src)
64-
.unwrap()
65-
.map(|f| f.unwrap().path())
66-
.collect::<Vec<_>>();
63+
let files = fs::read_dir(math_src).unwrap().map(|f| f.unwrap().path()).collect::<Vec<_>>();
6764

6865
let mut math = Vec::new();
6966
for file in files {
@@ -112,12 +109,7 @@ mod musl_reference_tests {
112109
let tail = eat(tail, " -> ");
113110
let ret = parse_retty(tail.replace("{", "").trim());
114111

115-
return Function {
116-
name: name.to_string(),
117-
args,
118-
ret,
119-
tests: Vec::new(),
120-
};
112+
return Function { name: name.to_string(), args, ret, tests: Vec::new() };
121113

122114
fn parse_ty(s: &str) -> Ty {
123115
match s {
@@ -156,11 +148,7 @@ mod musl_reference_tests {
156148
}
157149

158150
fn generate_test<R: Rng>(function: &Function, rng: &mut R) -> Test {
159-
let mut inputs = function
160-
.args
161-
.iter()
162-
.map(|ty| ty.gen_i64(rng))
163-
.collect::<Vec<_>>();
151+
let mut inputs = function.args.iter().map(|ty| ty.gen_i64(rng)).collect::<Vec<_>>();
164152

165153
// First argument to this function appears to be a number of
166154
// iterations, so passing in massive random numbers causes it to
@@ -180,25 +168,20 @@ mod musl_reference_tests {
180168

181169
impl Ty {
182170
fn gen_i64<R: Rng>(&self, r: &mut R) -> i64 {
183-
use std::f32;
184-
use std::f64;
171+
use std::{f32, f64};
185172

186173
return match self {
187174
Ty::F32 => {
188175
if r.gen_range(0..20) < 1 {
189-
let i = *[f32::NAN, f32::INFINITY, f32::NEG_INFINITY]
190-
.choose(r)
191-
.unwrap();
176+
let i = *[f32::NAN, f32::INFINITY, f32::NEG_INFINITY].choose(r).unwrap();
192177
i.to_bits().into()
193178
} else {
194179
r.gen::<f32>().to_bits().into()
195180
}
196181
}
197182
Ty::F64 => {
198183
if r.gen_range(0..20) < 1 {
199-
let i = *[f64::NAN, f64::INFINITY, f64::NEG_INFINITY]
200-
.choose(r)
201-
.unwrap();
184+
let i = *[f64::NAN, f64::INFINITY, f64::NEG_INFINITY].choose(r).unwrap();
202185
i.to_bits() as i64
203186
} else {
204187
r.gen::<f64>().to_bits() as i64
@@ -424,11 +407,7 @@ mod musl_reference_tests {
424407
src.push_str(");");
425408

426409
for (i, ret) in function.ret.iter().enumerate() {
427-
let get = if function.ret.len() == 1 {
428-
String::new()
429-
} else {
430-
format!(".{}", i)
431-
};
410+
let get = if function.ret.len() == 1 { String::new() } else { format!(".{}", i) };
432411
src.push_str(&(match ret {
433412
Ty::F32 => format!("if libm::_eqf(output{}, f32::from_bits(expected[{}] as u32)).is_ok() {{ continue }}", get, i),
434413
Ty::F64 => format!("if libm::_eq(output{}, f64::from_bits(expected[{}] as u64)).is_ok() {{ continue }}", get, i),

src/lib.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ mod math;
1717

1818
use core::{f32, f64};
1919

20-
pub use self::math::*;
2120
pub use libm_helper::*;
2221

22+
pub use self::math::*;
23+
2324
/// Approximate equality with 1 ULP of tolerance
2425
#[doc(hidden)]
2526
#[inline]
@@ -29,11 +30,7 @@ pub fn _eqf(a: f32, b: f32) -> Result<(), u32> {
2930
} else {
3031
let err = (a.to_bits() as i32).wrapping_sub(b.to_bits() as i32).abs();
3132

32-
if err <= 1 {
33-
Ok(())
34-
} else {
35-
Err(err as u32)
36-
}
33+
if err <= 1 { Ok(()) } else { Err(err as u32) }
3734
}
3835
}
3936

@@ -45,10 +42,6 @@ pub fn _eq(a: f64, b: f64) -> Result<(), u64> {
4542
} else {
4643
let err = (a.to_bits() as i64).wrapping_sub(b.to_bits() as i64).abs();
4744

48-
if err <= 1 {
49-
Ok(())
50-
} else {
51-
Err(err as u64)
52-
}
45+
if err <= 1 { Ok(()) } else { Err(err as u64) }
5346
}
5447
}

src/math/asin.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,5 @@ pub fn asin(mut x: f64) -> f64 {
111111
c = (z - f * f) / (s + f);
112112
x = 0.5 * PIO2_HI - (2.0 * s * r - (PIO2_LO - 2.0 * c) - (0.5 * PIO2_HI - 2.0 * f));
113113
}
114-
if hx >> 31 != 0 {
115-
-x
116-
} else {
117-
x
118-
}
114+
if hx >> 31 != 0 { -x } else { x }
119115
}

src/math/asinf.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,5 @@ pub fn asinf(mut x: f32) -> f32 {
6464
let z = (1. - fabsf(x)) * 0.5;
6565
let s = sqrt(z as f64);
6666
x = (PIO2 - 2. * (s + s * (r(z) as f64))) as f32;
67-
if (hx >> 31) != 0 {
68-
-x
69-
} else {
70-
x
71-
}
67+
if (hx >> 31) != 0 { -x } else { x }
7268
}

src/math/asinh.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,5 @@ pub fn asinh(mut x: f64) -> f64 {
3232
force_eval!(x + x1p120);
3333
}
3434

35-
if sign {
36-
-x
37-
} else {
38-
x
39-
}
35+
if sign { -x } else { x }
4036
}

src/math/asinhf.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,5 @@ pub fn asinhf(mut x: f32) -> f32 {
3131
force_eval!(x + x1p120);
3232
}
3333

34-
if sign {
35-
-x
36-
} else {
37-
x
38-
}
34+
if sign { -x } else { x }
3935
}

src/math/atan.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
* to produce the hexadecimal values shown.
3030
*/
3131

32-
use super::fabs;
3332
use core::f64;
3433

34+
use super::fabs;
35+
3536
const ATANHI: [f64; 4] = [
3637
4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */
3738
7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */
@@ -128,18 +129,15 @@ pub fn atan(x: f64) -> f64 {
128129

129130
let z = i!(ATANHI, id as usize) - (x * (s1 + s2) - i!(ATANLO, id as usize) - x);
130131

131-
if sign != 0 {
132-
-z
133-
} else {
134-
z
135-
}
132+
if sign != 0 { -z } else { z }
136133
}
137134

138135
#[cfg(test)]
139136
mod tests {
140-
use super::atan;
141137
use core::f64;
142138

139+
use super::atan;
140+
143141
#[test]
144142
fn sanity_check() {
145143
for (input, answer) in [

src/math/atan2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
* to produce the hexadecimal values shown.
3838
*/
3939

40-
use super::atan;
41-
use super::fabs;
40+
use super::{atan, fabs};
4241

4342
const PI: f64 = 3.1415926535897931160E+00; /* 0x400921FB, 0x54442D18 */
4443
const PI_LO: f64 = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */

src/math/atan2f.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
* ====================================================
1414
*/
1515

16-
use super::atanf;
17-
use super::fabsf;
16+
use super::{atanf, fabsf};
1817

1918
const PI: f32 = 3.1415927410e+00; /* 0x40490fdb */
2019
const PI_LO: f32 = -8.7422776573e-08; /* 0xb3bbbd2e */

src/math/atanf.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,8 @@ const ATAN_LO: [f32; 4] = [
2929
7.5497894159e-08, /* atan(inf)lo 0x33a22168 */
3030
];
3131

32-
const A_T: [f32; 5] = [
33-
3.3333328366e-01,
34-
-1.9999158382e-01,
35-
1.4253635705e-01,
36-
-1.0648017377e-01,
37-
6.1687607318e-02,
38-
];
32+
const A_T: [f32; 5] =
33+
[3.3333328366e-01, -1.9999158382e-01, 1.4253635705e-01, -1.0648017377e-01, 6.1687607318e-02];
3934

4035
/// Arctangent (f32)
4136
///
@@ -104,9 +99,5 @@ pub fn atanf(mut x: f32) -> f32 {
10499
}
105100
let id = id as usize;
106101
let z = i!(ATAN_HI, id) - ((x * (s1 + s2) - i!(ATAN_LO, id)) - x);
107-
if sign {
108-
-z
109-
} else {
110-
z
111-
}
102+
if sign { -z } else { z }
112103
}

src/math/atanh.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,5 @@ pub fn atanh(x: f64) -> f64 {
2929
y = 0.5 * log1p(2.0 * (y / (1.0 - y)));
3030
}
3131

32-
if sign {
33-
-y
34-
} else {
35-
y
36-
}
32+
if sign { -y } else { y }
3733
}

src/math/atanhf.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,5 @@ pub fn atanhf(mut x: f32) -> f32 {
2929
x = 0.5 * log1pf(2.0 * (x / (1.0 - x)));
3030
}
3131

32-
if sign {
33-
-x
34-
} else {
35-
x
36-
}
32+
if sign { -x } else { x }
3733
}

src/math/ceil.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,21 @@ pub fn ceil(x: f64) -> f64 {
4242
return x;
4343
}
4444
// y = int(x) - x, where int(x) is an integer neighbor of x
45-
y = if (u >> 63) != 0 {
46-
x - TOINT + TOINT - x
47-
} else {
48-
x + TOINT - TOINT - x
49-
};
45+
y = if (u >> 63) != 0 { x - TOINT + TOINT - x } else { x + TOINT - TOINT - x };
5046
// special case because of non-nearest rounding modes
5147
if e < 0x3ff {
5248
force_eval!(y);
5349
return if (u >> 63) != 0 { -0. } else { 1. };
5450
}
55-
if y < 0. {
56-
x + y + 1.
57-
} else {
58-
x + y
59-
}
51+
if y < 0. { x + y + 1. } else { x + y }
6052
}
6153

6254
#[cfg(test)]
6355
mod tests {
64-
use super::*;
6556
use core::f64::*;
6657

58+
use super::*;
59+
6760
#[test]
6861
fn sanity_check() {
6962
assert_eq!(ceil(1.1), 2.0);

src/math/ceilf.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ pub fn ceilf(x: f32) -> f32 {
4444
#[cfg(not(target_arch = "powerpc64"))]
4545
#[cfg(test)]
4646
mod tests {
47-
use super::*;
4847
use core::f32::*;
4948

49+
use super::*;
50+
5051
#[test]
5152
fn sanity_check() {
5253
assert_eq!(ceilf(1.1), 2.0);

src/math/cosf.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* ====================================================
1515
*/
1616

17-
use super::{k_cosf, k_sinf, rem_pio2f};
18-
1917
use core::f64::consts::FRAC_PI_2;
2018

19+
use super::{k_cosf, k_sinf, rem_pio2f};
20+
2121
/* Small multiples of pi/2 rounded to double precision. */
2222
const C1_PIO2: f64 = 1. * FRAC_PI_2; /* 0x3FF921FB, 0x54442D18 */
2323
const C2_PIO2: f64 = 2. * FRAC_PI_2; /* 0x400921FB, 0x54442D18 */

src/math/cosh.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use super::exp;
2-
use super::expm1;
3-
use super::k_expo2;
1+
use super::{exp, expm1, k_expo2};
42

53
/// Hyperbolic cosine (f64)
64
///

src/math/coshf.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use super::expf;
2-
use super::expm1f;
3-
use super::k_expo2f;
1+
use super::{expf, expm1f, k_expo2f};
42

53
/// Hyperbolic cosine (f64)
64
///

0 commit comments

Comments
 (0)