Skip to content

Commit

Permalink
Auto merge of rust-lang#2247 - dtolnay-contrib:rustfmt2, r=RalfJung
Browse files Browse the repository at this point in the history
Format tests with rustfmt (101-150 of 300)

Extracted from rust-lang#2097.

Like rust-lang/miri#2244, these are "easy" cases that do not involve moving around comments.
  • Loading branch information
bors committed Jun 21, 2022
2 parents 4d712a3 + 6b8c371 commit bdf2a8a
Show file tree
Hide file tree
Showing 50 changed files with 395 additions and 273 deletions.
30 changes: 21 additions & 9 deletions tests/pass/generator.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#![feature(generators, generator_trait, never_type)]

use std::ops::{GeneratorState::{self, *}, Generator};
use std::pin::Pin;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::fmt::Debug;
use std::mem::ManuallyDrop;
use std::ops::{
Generator,
GeneratorState::{self, *},
};
use std::pin::Pin;
use std::ptr;
use std::sync::atomic::{AtomicUsize, Ordering};

fn basic() {
fn finish<T>(mut amt: usize, mut t: T) -> T::Return
where T: Generator<Yield = usize>
where
T: Generator<Yield = usize>,
{
// We are not moving the `t` around until it gets dropped, so this is okay.
let mut t = unsafe { Pin::new_unchecked(&mut t) };
Expand All @@ -23,7 +27,7 @@ fn basic() {
}
GeneratorState::Complete(ret) => {
assert_eq!(amt, 0);
return ret
return ret;
}
}
}
Expand All @@ -46,7 +50,7 @@ fn basic() {
assert_eq!(x, 2);
});

finish(7*8/2, || {
finish(7 * 8 / 2, || {
for i in 0..8 {
yield i;
}
Expand All @@ -67,7 +71,10 @@ fn basic() {
});

finish(2, || {
if { yield 1; false } {
if {
yield 1;
false
} {
yield 1;
panic!()
}
Expand All @@ -90,7 +97,9 @@ fn basic() {
let b = true;
finish(1, || {
yield 1;
if b { return; }
if b {
return;
}
#[allow(unused)]
let x = never();
#[allow(unreachable_code)]
Expand All @@ -101,7 +110,10 @@ fn basic() {
finish(3, || {
yield 1;
#[allow(unreachable_code)]
let _x: (String, !) = (String::new(), { yield 2; return });
let _x: (String, !) = (String::new(), {
yield 2;
return;
});
});
}

Expand Down
8 changes: 4 additions & 4 deletions tests/pass/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>

fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
map.insert(0, 0);
assert_eq!(map.values().fold(0, |x, y| x+y), 0);
assert_eq!(map.values().fold(0, |x, y| x + y), 0);

let num = 25;
for i in 1..num {
map.insert(i, i);
}
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); // check the right things are in the table now
assert_eq!(map.values().fold(0, |x, y| x + y), num * (num - 1) / 2); // check the right things are in the table now

// Inserting again replaces the existing entries
for i in 0..num {
map.insert(i, num-1-i);
map.insert(i, num - 1 - i);
}
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2);
assert_eq!(map.values().fold(0, |x, y| x + y), num * (num - 1) / 2);

test_all_refs(&mut 13, map.values_mut());
}
Expand Down
10 changes: 5 additions & 5 deletions tests/pass/integer-ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn main() {
let m = -0xFEDCBA987654322i64;
assert_eq!(n.rotate_right(4), m);

let n = 0x0123456789ABCDEFi64;
let n = 0x0123456789ABCDEFi64;
let m = -0x1032547698BADCFFi64;
assert_eq!(n.swap_bytes(), m);

Expand Down Expand Up @@ -169,9 +169,9 @@ pub fn main() {
assert_eq!(0x10i32.overflowing_shr(4), (0x1, false));
assert_eq!(0x10i32.overflowing_shr(36), (0x1, true));

assert_eq!(10i8.overflowing_abs(), (10,false));
assert_eq!((-10i8).overflowing_abs(), (10,false));
assert_eq!((-128i8).overflowing_abs(), (-128,true));
assert_eq!(10i8.overflowing_abs(), (10, false));
assert_eq!((-10i8).overflowing_abs(), (10, false));
assert_eq!((-128i8).overflowing_abs(), (-128, true));

// Logarithms
macro_rules! test_log {
Expand All @@ -180,7 +180,7 @@ pub fn main() {
assert_eq!($type::MIN.checked_log10(), None);
assert_eq!($type::MAX.checked_log2(), Some($max_log2));
assert_eq!($type::MAX.checked_log10(), Some($max_log10));
}
};
}

test_log!(i8, 6, 2);
Expand Down
9 changes: 4 additions & 5 deletions tests/pass/intrinsics-math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
// except according to those terms.

macro_rules! assert_approx_eq {
($a:expr, $b:expr) => ({
($a:expr, $b:expr) => {{
let (a, b) = (&$a, &$b);
assert!((*a - *b).abs() < 1.0e-6,
"{} is not approximately equal to {}", *a, *b);
})
assert!((*a - *b).abs() < 1.0e-6, "{} is not approximately equal to {}", *a, *b);
}};
}

fn ldexp(a: f64, b: i32) -> f64 {
extern {
extern "C" {
fn ldexp(x: f64, n: i32) -> f64;
}
unsafe { ldexp(a, b) }
Expand Down
10 changes: 7 additions & 3 deletions tests/pass/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ fn main() {
assert_eq!(size_of_val(&[1, 2, 3] as &[i32]), 12);
assert_eq!(size_of_val("foobar"), 6);

unsafe { assert_eq!(size_of_val_raw(&[1] as &[i32] as *const [i32]), 4); }
unsafe { assert_eq!(size_of_val_raw(0x100 as *const i32), 4); }
unsafe {
assert_eq!(size_of_val_raw(&[1] as &[i32] as *const [i32]), 4);
}
unsafe {
assert_eq!(size_of_val_raw(0x100 as *const i32), 4);
}

assert_eq!(intrinsics::type_name::<Option<i32>>(), "core::option::Option<i32>");

Expand All @@ -33,7 +37,7 @@ fn main() {
let _v = intrinsics::discriminant_value(&Some(()));
let _v = intrinsics::discriminant_value(&0);
let _v = intrinsics::discriminant_value(&true);
let _v = intrinsics::discriminant_value(&vec![1,2,3]);
let _v = intrinsics::discriminant_value(&vec![1, 2, 3]);

let addr = &13 as *const i32;
let addr2 = (addr as usize).wrapping_add(usize::MAX).wrapping_add(1);
Expand Down
4 changes: 2 additions & 2 deletions tests/pass/ints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn indirect_add() -> i64 {
}

fn arith() -> i32 {
3*3 + 4*4
3 * 3 + 4 * 4
}

fn match_int() -> i16 {
Expand Down Expand Up @@ -48,7 +48,7 @@ fn main() {
assert_eq!(neg(), -1);
assert_eq!(add(), 3);
assert_eq!(indirect_add(), 3);
assert_eq!(arith(), 5*5);
assert_eq!(arith(), 5 * 5);
assert_eq!(match_int(), 20);
assert_eq!(match_int_range(), 4);
assert_eq!(i64::MIN.overflowing_mul(-1), (i64::MIN, true));
Expand Down
8 changes: 5 additions & 3 deletions tests/pass/issues/issue-15063.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#[allow(dead_code)]
enum Two { A, B }
enum Two {
A,
B,
}
impl Drop for Two {
fn drop(&mut self) {
}
fn drop(&mut self) {}
}
fn main() {
let _k = Two::A;
Expand Down
5 changes: 2 additions & 3 deletions tests/pass/issues/issue-15080.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
let mut x: &[_] = &[1, 2, 3, 4];

let mut result = vec!();
let mut result = vec![];
loop {
x = match *x {
[1, n, 3, ref rest @ ..] => {
Expand All @@ -12,8 +12,7 @@ fn main() {
result.push(n);
rest
}
[] =>
break
[] => break,
}
}
assert_eq!(result, [2, 4]);
Expand Down
1 change: 0 additions & 1 deletion tests/pass/issues/issue-15523-big.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fn main() {
assert!(Eu64::Pos2 < Eu64::PosMax);
assert!(Eu64::Pos1 < Eu64::PosMax);


assert!(Ei64::Pos2 > Ei64::Pos1);
assert!(Ei64::Pos2 > Ei64::Neg1);
assert!(Ei64::Pos1 > Ei64::Neg1);
Expand Down
22 changes: 14 additions & 8 deletions tests/pass/issues/issue-17877.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
fn main() {
assert_eq!(match [0u8; 16*1024] {
_ => 42_usize,
}, 42_usize);
assert_eq!(
match [0u8; 16 * 1024] {
_ => 42_usize,
},
42_usize,
);

assert_eq!(match [0u8; 16*1024] {
[1, ..] => 0_usize,
[0, ..] => 1_usize,
_ => 2_usize
}, 1_usize);
assert_eq!(
match [0u8; 16 * 1024] {
[1, ..] => 0_usize,
[0, ..] => 1_usize,
_ => 2_usize,
},
1_usize,
);
}
2 changes: 1 addition & 1 deletion tests/pass/issues/issue-23261.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

struct Foo<T: ?Sized> {
a: i32,
inner: T
inner: T,
}

trait Get {
Expand Down
8 changes: 6 additions & 2 deletions tests/pass/issues/issue-27901.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
trait Stream { type Item; }
impl<'a> Stream for &'a str { type Item = u8; }
trait Stream {
type Item;
}
impl<'a> Stream for &'a str {
type Item = u8;
}
fn f<'s>(s: &'s str) -> (&'s str, <&'s str as Stream>::Item) {
(s, 42)
}
Expand Down
10 changes: 5 additions & 5 deletions tests/pass/issues/issue-29746.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ macro_rules! zip {
}

fn main() {
let p1 = vec![1i32, 2].into_iter();
let p2 = vec!["10", "20"].into_iter();
let p3 = vec![100u16, 200].into_iter();
let p1 = vec![1i32, 2].into_iter();
let p2 = vec!["10", "20"].into_iter();
let p3 = vec![100u16, 200].into_iter();
let p4 = vec![1000i64, 2000].into_iter();

let e = zip!([p1,p2,p3,p4]).collect::<Vec<_>>();
assert_eq!(e[0], (1i32,"10",100u16,1000i64));
let e = zip!([p1, p2, p3, p4]).collect::<Vec<_>>();
assert_eq!(e[0], (1i32, "10", 100u16, 1000i64));
}
3 changes: 2 additions & 1 deletion tests/pass/issues/issue-30530.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub enum Handler {
}

fn main() {
#[allow(unused_must_use)] {
#[allow(unused_must_use)]
{
take(Handler::Default, Box::new(main));
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pass/issues/issue-34571.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ enum Foo {

fn main() {
match Foo::Foo(1) {
_ => ()
_ => (),
}
}
5 changes: 3 additions & 2 deletions tests/pass/issues/issue-36278-prefix-nesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ struct P<T: ?Sized>([u8; SZ], T);
type Ack<T> = P<P<T>>;

fn main() {
let size_of_sized; let size_of_unsized;
let size_of_sized;
let size_of_unsized;
let x: Box<Ack<[u8; 0]>> = Box::new(P([0; SZ], P([0; SZ], [0; 0])));
size_of_sized = mem::size_of_val::<Ack<_>>(&x);
let align_of_sized = mem::align_of_val::<Ack<_>>(&x);
let y: Box<Ack<[u8 ]>> = x;
let y: Box<Ack<[u8]>> = x;
size_of_unsized = mem::size_of_val::<Ack<_>>(&y);
assert_eq!(size_of_sized, size_of_unsized);
assert_eq!(align_of_sized, 1);
Expand Down
7 changes: 3 additions & 4 deletions tests/pass/issues/issue-5917.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

struct T (&'static [isize]);
static STATIC : T = T (&[5, 4, 3]);
pub fn main () {
struct T(&'static [isize]);
static STATIC: T = T(&[5, 4, 3]);
pub fn main() {
let T(ref v) = STATIC;
assert_eq!(v[0], 5);
}
9 changes: 2 additions & 7 deletions tests/pass/issues/issue-miri-133.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ struct S<U, V> {
_u: U,
size_of_u: usize,
_v: V,
size_of_v: usize
size_of_v: usize,
}

impl<U, V> S<U, V> {
fn new(u: U, v: V) -> Self {
S {
_u: u,
size_of_u: size_of::<U>(),
_v: v,
size_of_v: size_of::<V>()
}
S { _u: u, size_of_u: size_of::<U>(), _v: v, size_of_v: size_of::<V>() }
}
}

Expand Down
22 changes: 12 additions & 10 deletions tests/pass/issues/issue-miri-2068-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

use std::mem::MaybeUninit;

fn main() { unsafe {
let mut x = MaybeUninit::<i64>::uninit();
// Put in a ptr.
x.as_mut_ptr().cast::<&i32>().write_unaligned(&0);
// Overwrite parts of that pointer with 'uninit' through a Scalar.
let ptr = x.as_mut_ptr().cast::<i32>();
*ptr = MaybeUninit::uninit().assume_init();
// Reading this back should hence work fine.
let _c = *ptr;
} }
fn main() {
unsafe {
let mut x = MaybeUninit::<i64>::uninit();
// Put in a ptr.
x.as_mut_ptr().cast::<&i32>().write_unaligned(&0);
// Overwrite parts of that pointer with 'uninit' through a Scalar.
let ptr = x.as_mut_ptr().cast::<i32>();
*ptr = MaybeUninit::uninit().assume_init();
// Reading this back should hence work fine.
let _c = *ptr;
}
}
Loading

0 comments on commit bdf2a8a

Please sign in to comment.