Skip to content

Commit

Permalink
Auto merge of rust-lang#125948 - nnethercote:rustfmt-more-tests, r=lqd
Browse files Browse the repository at this point in the history
rustfmt more tests

This finishes the formatting of tests begun in rust-lang#125759 and continued in rust-lang#125912.

r? `@lqd`
  • Loading branch information
bors committed Jun 4, 2024
2 parents 85f90a4 + d2ea692 commit bc33782
Show file tree
Hide file tree
Showing 48 changed files with 351 additions and 189 deletions.
17 changes: 6 additions & 11 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@ ignore = [
"/tests/crashes/", # Many of these tests contain syntax errors.
"/tests/debuginfo/", # These tests are somewhat sensitive to source code layout.
"/tests/incremental/", # These tests are somewhat sensitive to source code layout.
"/tests/pretty/",
"/tests/pretty/", # These tests are very sensitive to source code layout.
"/tests/run-make/translation/test.rs", # This test contains syntax errors.
"/tests/run-make-fulldeps/",
"/tests/run-pass-valgrind/",
"/tests/rustdoc/",
"/tests/rustdoc-gui/",
"/tests/rustdoc-js/",
"/tests/rustdoc-json/",
"/tests/rustdoc-js-std/",
"/tests/rustdoc-ui/",
"/tests/ui/",
"/tests/ui-fulldeps/",
"/tests/rustdoc/", # Some have syntax errors, some are whitespace-sensitive.
"/tests/rustdoc-gui/", # Some tests are sensitive to source code layout.
"/tests/rustdoc-ui/", # Some have syntax errors, some are whitespace-sensitive.
"/tests/ui/", # Some have syntax errors, some are whitespace-sensitive.
"/tests/ui-fulldeps/", # Some are whitespace-sensitive (e.g. `// ~ERROR` comments).

# Do not format submodules.
# FIXME: sync submodule list with tidy/bootstrap/etc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use std::any::Any;
struct TheBackend;

impl CodegenBackend for TheBackend {
fn locale_resource(&self) -> &'static str { "" }
fn locale_resource(&self) -> &'static str {
""
}

fn codegen_crate<'a, 'tcx>(
&self,
Expand Down Expand Up @@ -62,7 +64,10 @@ impl CodegenBackend for TheBackend {
codegen_results: CodegenResults,
outputs: &OutputFilenames,
) -> Result<(), ErrorGuaranteed> {
use rustc_session::{config::{CrateType, OutFileName}, output::out_filename};
use rustc_session::{
config::{CrateType, OutFileName},
output::out_filename,
};
use std::io::Write;
let crate_name = codegen_results.crate_info.local_crate_name;
for &crate_type in sess.opts.crate_types.iter() {
Expand Down
29 changes: 23 additions & 6 deletions tests/run-make-fulldeps/pretty-expanded/input.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
// #13544

#[derive(Debug)] pub struct A;
#[derive(Debug)] pub struct B(isize);
#[derive(Debug)] pub struct C { x: isize }
#[derive(Debug)] pub enum D {}
#[derive(Debug)] pub enum E { y }
#[derive(Debug)] pub enum F { z(isize) }
#[derive(Debug)]
pub struct A;

#[derive(Debug)]
pub struct B(isize);

#[derive(Debug)]
pub struct C {
x: isize,
}

#[derive(Debug)]
pub enum D {}

#[derive(Debug)]
pub enum E {
y,
}

#[derive(Debug)]
pub enum F {
z(isize),
}
6 changes: 3 additions & 3 deletions tests/run-pass-valgrind/cast-enum-with-dtor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

// check dtor calling order when casting enums.

use std::mem;
use std::sync::atomic;
use std::sync::atomic::Ordering;
use std::mem;

enum E {
A = 0,
B = 1,
C = 2
C = 2,
}

static FLAG: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
Expand All @@ -19,7 +19,7 @@ impl Drop for E {
// avoid dtor loop
unsafe { mem::forget(mem::replace(self, E::B)) };

FLAG.store(FLAG.load(Ordering::SeqCst)+1, Ordering::SeqCst);
FLAG.store(FLAG.load(Ordering::SeqCst) + 1, Ordering::SeqCst);
}
}

Expand Down
9 changes: 6 additions & 3 deletions tests/run-pass-valgrind/cleanup-auto-borrow-obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ static mut DROP_RAN: bool = false;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
unsafe { DROP_RAN = true; }
unsafe {
DROP_RAN = true;
}
}
}


trait Trait { fn dummy(&self) { } }
trait Trait {
fn dummy(&self) {}
}
impl Trait for Foo {}

pub fn main() {
Expand Down
10 changes: 8 additions & 2 deletions tests/run-pass-valgrind/coerce-match-calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ use std::boxed::Box;
pub fn main() {
let _: Box<[isize]> = if true { Box::new([1, 2, 3]) } else { Box::new([1]) };

let _: Box<[isize]> = match true { true => Box::new([1, 2, 3]), false => Box::new([1]) };
let _: Box<[isize]> = match true {
true => Box::new([1, 2, 3]),
false => Box::new([1]),
};

// Check we don't get over-keen at propagating coercions in the case of casts.
let x = if true { 42 } else { 42u8 } as u16;
let x = match true { true => 42, false => 42u8 } as u16;
let x = match true {
true => 42,
false => 42u8,
} as u16;
}
15 changes: 12 additions & 3 deletions tests/run-pass-valgrind/coerce-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ pub fn main() {
};

let _: Box<[isize]> = match true {
true => { let b: Box<_> = Box::new([1, 2, 3]); b }
false => { let b: Box<_> = Box::new([1]); b }
true => {
let b: Box<_> = Box::new([1, 2, 3]);
b
}
false => {
let b: Box<_> = Box::new([1]);
b
}
};

// Check we don't get over-keen at propagating coercions in the case of casts.
let x = if true { 42 } else { 42u8 } as u16;
let x = match true { true => 42, false => 42u8 } as u16;
let x = match true {
true => 42,
false => 42u8,
} as u16;
}
8 changes: 6 additions & 2 deletions tests/run-pass-valgrind/down-with-thread-dtors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ impl Drop for Bar {

impl Drop for Baz {
fn drop(&mut self) {
unsafe { HIT = true; }
unsafe {
HIT = true;
}
}
}

fn main() {
std::thread::spawn(|| {
FOO.with(|_| {});
}).join().unwrap();
})
.join()
.unwrap();
assert!(unsafe { HIT });
}
10 changes: 7 additions & 3 deletions tests/run-pass-valgrind/dst-dtor-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ static mut DROP_RAN: bool = false;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
unsafe { DROP_RAN = true; }
unsafe {
DROP_RAN = true;
}
}
}

trait Trait { fn dummy(&self) { } }
trait Trait {
fn dummy(&self) {}
}
impl Trait for Foo {}

struct Fat<T: ?Sized> {
f: T
f: T,
}

pub fn main() {
Expand Down
6 changes: 4 additions & 2 deletions tests/run-pass-valgrind/dst-dtor-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ static mut DROP_RAN: isize = 0;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
unsafe { DROP_RAN += 1; }
unsafe {
DROP_RAN += 1;
}
}
}

struct Fat<T: ?Sized> {
f: T
f: T,
}

pub fn main() {
Expand Down
8 changes: 6 additions & 2 deletions tests/run-pass-valgrind/dst-dtor-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ static mut DROP_RAN: bool = false;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
unsafe { DROP_RAN = true; }
unsafe {
DROP_RAN = true;
}
}
}

trait Trait { fn dummy(&self) { } }
trait Trait {
fn dummy(&self) {}
}
impl Trait for Foo {}

pub fn main() {
Expand Down
4 changes: 3 additions & 1 deletion tests/run-pass-valgrind/dst-dtor-4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ static mut DROP_RAN: isize = 0;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
unsafe { DROP_RAN += 1; }
unsafe {
DROP_RAN += 1;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ impl FnOnce<()> for D {
}
}


fn main() {
let x = *(Box::new(A) as Box<dyn FnOnce<(), Output = String>>);
assert_eq!(x.call_once(()), format!("hello"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ impl FnOnce<(String, Box<str>)> for D {
}
}


fn main() {
let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
let x = *(Box::new(A) as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
Expand All @@ -61,10 +60,10 @@ fn main() {
assert_eq!(x.call_once((s1, s2)), format!("42"));
let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
let x = *(Box::new(C(format!("jumping fox")))
as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
assert_eq!(x.call_once((s1, s2)), format!("jumping fox"));
let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
let x = *(Box::new(D(Box::new(format!("lazy dog"))))
as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
assert_eq!(x.call_once((s1, s2)), format!("lazy dog"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl Foo for D {
}
}


fn main() {
let x = *(Box::new(A) as Box<dyn Foo>);
assert_eq!(x.foo(), format!("hello"));
Expand Down
21 changes: 13 additions & 8 deletions tests/rustdoc-js/assoc-type-backtrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ pub trait MyTrait2<X> {
pub trait MyTrait {
type Item;
fn next(&mut self) -> Option<Self::Item>;
fn fold<B, F>(self, init: B, f: F) -> B where
fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
F: MyTrait2<(B, Self::Item), Output=B>;
F: MyTrait2<(B, Self::Item), Output = B>;
}

pub struct Cloned<I>(I);

impl<'a, T, I> MyTrait for Cloned<I> where
impl<'a, T, I> MyTrait for Cloned<I>
where
T: 'a + Clone,
I: MyTrait<Item = &'a T>
I: MyTrait<Item = &'a T>,
{
type Item = T;
fn next(&mut self) -> Option<Self::Item> { loop {} }
fn fold<B, F>(self, init: B, f: F) -> B where
fn next(&mut self) -> Option<Self::Item> {
loop {}
}
fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
F: MyTrait2<(B, Self::Item), Output=B>
F: MyTrait2<(B, Self::Item), Output = B>,
{
loop {}
}
Expand All @@ -32,7 +37,7 @@ pub trait MyFuture {

pub trait MyIntoFuture {
type Output;
type Fut: MyFuture<Output=Self::Output>;
type Fut: MyFuture<Output = Self::Output>;
fn into_future(self) -> Self::Fut;
fn into_future_2(self, other: Self) -> Self::Fut;
}
9 changes: 5 additions & 4 deletions tests/rustdoc-js/assoc-type-loop.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![crate_name="foo"]
#![crate_name = "foo"]

// reduced from sqlx 0.7.3
use std::future::Future;
use std::pin::Pin;
use std::ops::{Deref, DerefMut};
use std::pin::Pin;
pub enum Error {}
pub trait Acquire<'c> {
type Database: Database;
Expand All @@ -16,7 +16,7 @@ pub trait Connection {
type Database: Database;
type Options: ConnectionOptions<Connection = Self>;
fn begin(
&mut self
&mut self,
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, Self::Database>, Error>> + Send + '_>>
where
Self: Sized;
Expand All @@ -28,7 +28,8 @@ pub struct Transaction<'c, DB: Database> {
_db: &'c DB,
}
impl<'t, 'c, DB: Database> Acquire<'t> for &'t mut Transaction<'c, DB>
where <DB as Database>::Connection: Send
where
<DB as Database>::Connection: Send,
{
type Database = DB;
type Connection = &'t mut <DB as Database>::Connection;
Expand Down
Loading

0 comments on commit bc33782

Please sign in to comment.