Skip to content

Commit

Permalink
Auto merge of #66820 - dtolnay:fmt3, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Format libstd with rustfmt

(Same strategy as #66691.)

This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd *that are not involved in any currently open PR* to minimize merge conflicts, and are not part of libstd/os (#66818) or libstd/sys (#66819). The list of files involved in open PRs was determined by querying GitHub's GraphQL API [with this script](https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8).

With the list of files from the script in outstanding_files, the relevant commands were:

    $ find src/libstd -name '*.rs' \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ rg libstd outstanding_files | xargs git checkout --

Repeating this process several months apart should get us coverage of most of the rest of libstd.

To confirm no funny business:

    $ git checkout $THIS_COMMIT^
    $ git show --pretty= --name-only $THIS_COMMIT \
        | xargs rustfmt --edition=2018 --unstable-features --skip-children
    $ git diff $THIS_COMMIT  # there should be no difference
  • Loading branch information
bors committed Nov 30, 2019
2 parents 9081929 + 688e381 commit 0a0734e
Show file tree
Hide file tree
Showing 50 changed files with 2,889 additions and 2,637 deletions.
2 changes: 1 addition & 1 deletion src/libstd/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#![stable(feature = "rust1", since = "1.0.0")]

#[stable(feature = "rust1", since = "1.0.0")]
pub use core::ascii::{EscapeDefault, escape_default};
pub use core::ascii::{escape_default, EscapeDefault};

/// Extension methods for ASCII-subset only operations.
///
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ use crate::env;
use crate::fmt;
use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use crate::sync::Mutex;
use crate::sys_common::backtrace::{output_filename, lock};
use crate::sys_common::backtrace::{lock, output_filename};
use crate::vec::Vec;
use backtrace_rs as backtrace;
use backtrace::BytesOrWideString;
use backtrace_rs as backtrace;

/// A captured OS thread stack backtrace.
///
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/benches/hash/map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(test)]

use test::Bencher;
use std::collections::HashMap;
use test::Bencher;

#[bench]
fn new_drop(b: &mut Bencher) {
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,20 @@
#[doc(hidden)]
pub use crate::ops::Bound;
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::collections::{BinaryHeap, BTreeMap, BTreeSet};
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::collections::{LinkedList, VecDeque};
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::collections::{binary_heap, btree_map, btree_set};
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::collections::{linked_list, vec_deque};
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::collections::{BTreeMap, BTreeSet, BinaryHeap};
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::collections::{LinkedList, VecDeque};

#[stable(feature = "rust1", since = "1.0.0")]
pub use self::hash_map::HashMap;
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::hash_set::HashSet;

#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
pub use alloc_crate::collections::TryReserveError;

mod hash;
Expand Down
82 changes: 37 additions & 45 deletions src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use crate::intrinsics;
use crate::sys::cmath;

#[stable(feature = "rust1", since = "1.0.0")]
pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON};
pub use core::f32::consts;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::f32::{MIN_EXP, MAX_EXP, MIN_10_EXP};
pub use core::f32::{DIGITS, EPSILON, MANTISSA_DIGITS, RADIX};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::f32::{MAX_10_EXP, NAN, INFINITY, NEG_INFINITY};
pub use core::f32::{INFINITY, MAX_10_EXP, NAN, NEG_INFINITY};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::f32::{MIN, MIN_POSITIVE, MAX};
pub use core::f32::{MAX, MIN, MIN_POSITIVE};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::f32::consts;
pub use core::f32::{MAX_EXP, MIN_10_EXP, MIN_EXP};

#[cfg(not(test))]
#[lang = "f32_runtime"]
Expand Down Expand Up @@ -142,7 +142,9 @@ impl f32 {
#[must_use = "method returns a new number and does not mutate the original value"]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn fract(self) -> f32 { self - self.trunc() }
pub fn fract(self) -> f32 {
self - self.trunc()
}

/// Computes the absolute value of `self`. Returns `NAN` if the
/// number is `NAN`.
Expand Down Expand Up @@ -192,11 +194,7 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn signum(self) -> f32 {
if self.is_nan() {
NAN
} else {
1.0_f32.copysign(self)
}
if self.is_nan() { NAN } else { 1.0_f32.copysign(self) }
}

/// Returns a number composed of the magnitude of `self` and the sign of
Expand Down Expand Up @@ -277,7 +275,7 @@ impl f32 {
pub fn div_euclid(self, rhs: f32) -> f32 {
let q = (self / rhs).trunc();
if self % rhs < 0.0 {
return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }
return if rhs > 0.0 { q - 1.0 } else { q + 1.0 };
}
q
}
Expand Down Expand Up @@ -310,14 +308,9 @@ impl f32 {
#[stable(feature = "euclidean_division", since = "1.38.0")]
pub fn rem_euclid(self, rhs: f32) -> f32 {
let r = self % rhs;
if r < 0.0 {
r + rhs.abs()
} else {
r
}
if r < 0.0 { r + rhs.abs() } else { r }
}


/// Raises a number to an integer power.
///
/// Using this function is generally faster than using `powf`
Expand Down Expand Up @@ -383,11 +376,7 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn sqrt(self) -> f32 {
if self < 0.0 {
NAN
} else {
unsafe { intrinsics::sqrtf32(self) }
}
if self < 0.0 { NAN } else { unsafe { intrinsics::sqrtf32(self) } }
}

/// Returns `e^(self)`, (the exponential function).
Expand Down Expand Up @@ -486,7 +475,9 @@ impl f32 {
#[must_use = "method returns a new number and does not mutate the original value"]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn log(self, base: f32) -> f32 { self.ln() / base.ln() }
pub fn log(self, base: f32) -> f32 {
self.ln() / base.ln()
}

/// Returns the base 2 logarithm of the number.
///
Expand Down Expand Up @@ -559,14 +550,16 @@ impl f32 {
#[must_use = "method returns a new number and does not mutate the original value"]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
#[rustc_deprecated(since = "1.10.0",
reason = "you probably meant `(self - other).abs()`: \
this operation is `(self - other).max(0.0)` \
except that `abs_sub` also propagates NaNs (also \
known as `fdimf` in C). If you truly need the positive \
difference, consider using that expression or the C function \
`fdimf`, depending on how you wish to handle NaN (please consider \
filing an issue describing your use-case too).")]
#[rustc_deprecated(
since = "1.10.0",
reason = "you probably meant `(self - other).abs()`: \
this operation is `(self - other).max(0.0)` \
except that `abs_sub` also propagates NaNs (also \
known as `fdimf` in C). If you truly need the positive \
difference, consider using that expression or the C function \
`fdimf`, depending on how you wish to handle NaN (please consider \
filing an issue describing your use-case too)."
)]
pub fn abs_sub(self, other: f32) -> f32 {
unsafe { cmath::fdimf(self, other) }
}
Expand Down Expand Up @@ -967,11 +960,7 @@ impl f32 {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn acosh(self) -> f32 {
if self < 1.0 {
crate::f32::NAN
} else {
(self + ((self * self) - 1.0).sqrt()).ln()
}
if self < 1.0 { crate::f32::NAN } else { (self + ((self * self) - 1.0).sqrt()).ln() }
}

/// Inverse hyperbolic tangent function.
Expand Down Expand Up @@ -1022,19 +1011,22 @@ impl f32 {
pub fn clamp(self, min: f32, max: f32) -> f32 {
assert!(min <= max);
let mut x = self;
if x < min { x = min; }
if x > max { x = max; }
if x < min {
x = min;
}
if x > max {
x = max;
}
x
}

}

#[cfg(test)]
mod tests {
use crate::f32;
use crate::f32::*;
use crate::num::*;
use crate::num::FpCategory as Fp;
use crate::num::*;

#[test]
fn test_num_f32() {
Expand Down Expand Up @@ -1279,7 +1271,7 @@ mod tests {
assert_eq!((-0f32).abs(), 0f32);
assert_eq!((-1f32).abs(), 1f32);
assert_eq!(NEG_INFINITY.abs(), INFINITY);
assert_eq!((1f32/NEG_INFINITY).abs(), 0f32);
assert_eq!((1f32 / NEG_INFINITY).abs(), 0f32);
assert!(NAN.abs().is_nan());
}

Expand All @@ -1291,7 +1283,7 @@ mod tests {
assert_eq!((-0f32).signum(), -1f32);
assert_eq!((-1f32).signum(), -1f32);
assert_eq!(NEG_INFINITY.signum(), -1f32);
assert_eq!((1f32/NEG_INFINITY).signum(), -1f32);
assert_eq!((1f32 / NEG_INFINITY).signum(), -1f32);
assert!(NAN.signum().is_nan());
}

Expand All @@ -1303,7 +1295,7 @@ mod tests {
assert!(!(-0f32).is_sign_positive());
assert!(!(-1f32).is_sign_positive());
assert!(!NEG_INFINITY.is_sign_positive());
assert!(!(1f32/NEG_INFINITY).is_sign_positive());
assert!(!(1f32 / NEG_INFINITY).is_sign_positive());
assert!(NAN.is_sign_positive());
assert!(!(-NAN).is_sign_positive());
}
Expand All @@ -1316,7 +1308,7 @@ mod tests {
assert!((-0f32).is_sign_negative());
assert!((-1f32).is_sign_negative());
assert!(NEG_INFINITY.is_sign_negative());
assert!((1f32/NEG_INFINITY).is_sign_negative());
assert!((1f32 / NEG_INFINITY).is_sign_negative());
assert!(!NAN.is_sign_negative());
assert!((-NAN).is_sign_negative());
}
Expand Down
Loading

0 comments on commit 0a0734e

Please sign in to comment.