Skip to content

Commit

Permalink
Run rustfmt on tests/codegen-units/.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed May 31, 2024
1 parent 72800d3 commit 780a917
Show file tree
Hide file tree
Showing 32 changed files with 208 additions and 229 deletions.
1 change: 0 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 15,6 @@ ignore = [
# - some UI tests are broken by different formatting
# - some require special comments in a particular position (e.g. `EMIT_MIR` comments)
"/tests/codegen/simd-intrinsic/", # Many types like `u8x64` are better hand-formatted.
"/tests/codegen-units/",
"/tests/coverage/",
"/tests/coverage-run-rustdoc/",
"/tests/crashes/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 2,43 @@

#![crate_type = "lib"]

pub trait Trait : Sized {
pub trait Trait: Sized {
fn without_self() -> u32;
fn without_self_default() -> u32 { 0 }
fn without_self_default() -> u32 {
0
}

fn with_default_impl(self) -> Self { self }
fn with_default_impl_generic<T>(self, x: T) -> (Self, T) { (self, x) }
fn with_default_impl(self) -> Self {
self
}
fn with_default_impl_generic<T>(self, x: T) -> (Self, T) {
(self, x)
}

fn without_default_impl(x: u32) -> (Self, u32);
fn without_default_impl_generic<T>(x: T) -> (Self, T);
}

impl Trait for char {
fn without_self() -> u32 { 2 }
fn without_default_impl(x: u32) -> (Self, u32) { ('c', x) }
fn without_default_impl_generic<T>(x: T) -> (Self, T) { ('c', x) }
fn without_self() -> u32 {
2
}
fn without_default_impl(x: u32) -> (Self, u32) {
('c', x)
}
fn without_default_impl_generic<T>(x: T) -> (Self, T) {
('c', x)
}
}

impl Trait for u32 {
fn without_self() -> u32 { 1 }
fn without_default_impl(x: u32) -> (Self, u32) { (0, x) }
fn without_default_impl_generic<T>(x: T) -> (Self, T) { (0, x) }
fn without_self() -> u32 {
1
}
fn without_default_impl(x: u32) -> (Self, u32) {
(0, x)
}
fn without_default_impl_generic<T>(x: T) -> (Self, T) {
(0, x)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 2,19 @@

#[inline]
pub fn inlined_fn(x: i32, y: i32) -> i32 {

let closure = |a, b| { a b };
let closure = |a, b| a b;

closure(x, y)
}

pub fn inlined_fn_generic<T>(x: i32, y: i32, z: T) -> (i32, T) {

let closure = |a, b| { a b };
let closure = |a, b| a b;

(closure(x, y), z)
}

pub fn non_inlined_fn(x: i32, y: i32) -> i32 {

let closure = |a, b| { a b };
let closure = |a, b| a b;

closure(x, y)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,6 @@ extern crate cgu_extern_closures;
//~ MONO_ITEM fn cross_crate_closures::start[0]
#[start]
fn start(_: isize, _: *const *const u8) -> isize {

//~ MONO_ITEM fn cgu_extern_closures::inlined_fn[0]
//~ MONO_ITEM fn cgu_extern_closures::inlined_fn[0]::{{closure}}[0]
let _ = cgu_extern_closures::inlined_fn(1, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 24,6 @@ fn start(_: isize, _: *const *const u8) -> isize {
//~ MONO_ITEM fn <char as cgu_export_trait_method::Trait>::with_default_impl
let _ = Trait::with_default_impl('c');



//~ MONO_ITEM fn <u32 as cgu_export_trait_method::Trait>::with_default_impl_generic::<&str>
let _ = Trait::with_default_impl_generic(0u32, "abc");
//~ MONO_ITEM fn <u32 as cgu_export_trait_method::Trait>::with_default_impl_generic::<bool>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 15,6 @@ impl Drop for StructWithDtor {
//~ MONO_ITEM fn start
#[start]
fn start(_: isize, _: *const *const u8) -> isize {

//~ MONO_ITEM fn std::ptr::drop_in_place::<[StructWithDtor; 2]> - shim(Some([StructWithDtor; 2])) @@ drop_in_place_intrinsic-cgu.0[Internal]
let x = [StructWithDtor(0), StructWithDtor(1)];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 16,6 @@ fn take_fn_pointer<T1, T2>(f: fn(T1, T2), x: T1, y: T2) {
//~ MONO_ITEM fn start
#[start]
fn start(_: isize, _: *const *const u8) -> isize {

//~ MONO_ITEM fn take_fn_once::<u32, &str, fn(u32, &str) {function::<u32, &str>}>
//~ MONO_ITEM fn function::<u32, &str>
//~ MONO_ITEM fn <fn(u32, &str) {function::<u32, &str>} as std::ops::FnOnce<(u32, &str)>>::call_once - shim(fn(u32, &str) {function::<u32, &str>})
Expand Down
13 changes: 6 additions & 7 deletions tests/codegen-units/item-collection/generic-drop-glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 21,7 @@ struct StructNoDrop<T1, T2> {

enum EnumWithDrop<T1, T2> {
A(T1),
B(T2)
B(T2),
}

impl<T1, T2> Drop for EnumWithDrop<T1, T2> {
Expand All @@ -30,10 30,9 @@ impl<T1, T2> Drop for EnumWithDrop<T1, T2> {

enum EnumNoDrop<T1, T2> {
A(T1),
B(T2)
B(T2),
}


struct NonGenericNoDrop(#[allow(dead_code)] i32);

struct NonGenericWithDrop(#[allow(dead_code)] i32);
Expand Down Expand Up @@ -67,24 66,24 @@ fn start(_: isize, _: *const *const u8) -> isize {
//~ MONO_ITEM fn <EnumWithDrop<i32, i64> as std::ops::Drop>::drop
let _ = match EnumWithDrop::A::<i32, i64>(0) {
EnumWithDrop::A(x) => x,
EnumWithDrop::B(x) => x as i32
EnumWithDrop::B(x) => x as i32,
};

//~ MONO_ITEM fn std::ptr::drop_in_place::<EnumWithDrop<f64, f32>> - shim(Some(EnumWithDrop<f64, f32>)) @@ generic_drop_glue-cgu.0[Internal]
//~ MONO_ITEM fn <EnumWithDrop<f64, f32> as std::ops::Drop>::drop
let _ = match EnumWithDrop::B::<f64, f32>(1.0) {
EnumWithDrop::A(x) => x,
EnumWithDrop::B(x) => x as f64
EnumWithDrop::B(x) => x as f64,
};

let _ = match EnumNoDrop::A::<i32, i64>(0) {
EnumNoDrop::A(x) => x,
EnumNoDrop::B(x) => x as i32
EnumNoDrop::B(x) => x as i32,
};

let _ = match EnumNoDrop::B::<f64, f32>(1.0) {
EnumNoDrop::A(x) => x,
EnumNoDrop::B(x) => x as f64
EnumNoDrop::B(x) => x as f64,
};

0
Expand Down
13 changes: 5 additions & 8 deletions tests/codegen-units/item-collection/generic-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 8,13 @@ struct Struct<T> {
f: fn(x: T) -> T,
}

fn id<T>(x: T) -> T { x }
fn id<T>(x: T) -> T {
x
}

impl<T> Struct<T> {

fn new(x: T) -> Struct<T> {
Struct {
x: x,
f: id
}
Struct { x: x, f: id }
}

fn get<T2>(self, x: T2) -> (T, T2) {
Expand All @@ -25,11 23,10 @@ impl<T> Struct<T> {
}

pub struct LifeTimeOnly<'a> {
_a: &'a u32
_a: &'a u32,
}

impl<'a> LifeTimeOnly<'a> {

//~ MONO_ITEM fn LifeTimeOnly::<'_>::foo
pub fn foo(&self) {}
//~ MONO_ITEM fn LifeTimeOnly::<'_>::bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 10,13 @@ trait Trait {
}

struct Struct<T> {
_a: T
_a: T,
}

impl<T> Trait for Struct<T> {
fn foo(&self) -> u32 { 0 }
fn foo(&self) -> u32 {
0
}
fn bar(&self) {}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/codegen-units/item-collection/non-generic-drop-glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 7,7 @@

//~ MONO_ITEM fn std::ptr::drop_in_place::<StructWithDrop> - shim(Some(StructWithDrop)) @@ non_generic_drop_glue-cgu.0[Internal]
struct StructWithDrop {
x: i32
x: i32,
}

impl Drop for StructWithDrop {
Expand All @@ -16,12 16,12 @@ impl Drop for StructWithDrop {
}

struct StructNoDrop {
x: i32
x: i32,
}

//~ MONO_ITEM fn std::ptr::drop_in_place::<EnumWithDrop> - shim(Some(EnumWithDrop)) @@ non_generic_drop_glue-cgu.0[Internal]
enum EnumWithDrop {
A(i32)
A(i32),
}

impl Drop for EnumWithDrop {
Expand All @@ -30,7 30,7 @@ impl Drop for EnumWithDrop {
}

enum EnumNoDrop {
A(i32)
A(i32),
}

//~ MONO_ITEM fn start
Expand All @@ -39,10 39,10 @@ fn start(_: isize, _: *const *const u8) -> isize {
let _ = StructWithDrop { x: 0 }.x;
let _ = StructNoDrop { x: 0 }.x;
let _ = match EnumWithDrop::A(0) {
EnumWithDrop::A(x) => x
EnumWithDrop::A(x) => x,
};
let _ = match EnumNoDrop::A(0) {
EnumNoDrop::A(x) => x
EnumNoDrop::A(x) => x,
};

0
Expand Down
4 changes: 3 additions & 1 deletion tests/codegen-units/item-collection/non-generic-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,9 @@ fn bar() {
baz();
}

struct Struct { _x: i32 }
struct Struct {
_x: i32,
}

impl Struct {
//~ MONO_ITEM fn Struct::foo
Expand Down
20 changes: 5 additions & 15 deletions tests/codegen-units/item-collection/overloaded-operators.rs
Original file line number Diff line number Diff line change
@@ -1,45 1,35 @@
//@ compile-flags:-Zprint-mono-items=eager

#![deny(dead_code)]
#![crate_type="lib"]
#![crate_type = "lib"]

use std::ops::{Index, IndexMut, Add, Deref};
use std::ops::{Add, Deref, Index, IndexMut};

pub struct Indexable {
data: [u8; 3]
data: [u8; 3],
}

impl Index<usize> for Indexable {
type Output = u8;

//~ MONO_ITEM fn <Indexable as std::ops::Index<usize>>::index
fn index(&self, index: usize) -> &Self::Output {
if index >= 3 {
&self.data[0]
} else {
&self.data[index]
}
if index >= 3 { &self.data[0] } else { &self.data[index] }
}
}

impl IndexMut<usize> for Indexable {
//~ MONO_ITEM fn <Indexable as std::ops::IndexMut<usize>>::index_mut
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
if index >= 3 {
&mut self.data[0]
} else {
&mut self.data[index]
}
if index >= 3 { &mut self.data[0] } else { &mut self.data[index] }
}
}


//~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::eq
//~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::ne
#[derive(PartialEq)]
pub struct Equatable(u32);


impl Add<u32> for Equatable {
type Output = u32;

Expand Down
4 changes: 2 additions & 2 deletions tests/codegen-units/item-collection/static-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 2,9 @@

#![feature(start)]

pub static FN : fn() = foo::<i32>;
pub static FN: fn() = foo::<i32>;

pub fn foo<T>() { }
pub fn foo<T>() {}

//~ MONO_ITEM fn foo::<T>
//~ MONO_ITEM static FN
Expand Down
Loading

0 comments on commit 780a917

Please sign in to comment.