Skip to content

Commit

Permalink
Format all tests in example/
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Mar 18, 2023
1 parent 53d4428 commit 18184d8
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 312 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
run: |
cargo fmt --check
rustfmt --check build_system/mod.rs
rustfmt --check example/*
test:
Expand Down
3 changes: 1 addition & 2 deletions example/arbitrary_self_types_pointers_and_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#![feature(arbitrary_self_types, unsize, coerce_unsized, dispatch_from_dyn)]

use std::{
ops::{Deref, CoerceUnsized, DispatchFromDyn},
marker::Unsize,
ops::{CoerceUnsized, Deref, DispatchFromDyn},
};

struct Ptr<T: ?Sized>(Box<T>);
Expand Down Expand Up @@ -33,7 +33,6 @@ impl<T: ?Sized> Deref for Wrapper<T> {
impl<T: CoerceUnsized<U>, U> CoerceUnsized<Wrapper<U>> for Wrapper<T> {}
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T> {}


trait Trait {
// This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable
// without unsized_locals), but wrappers around `Self` currently are not.
Expand Down
41 changes: 20 additions & 21 deletions example/dst-field-align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,65 @@
#![allow(dead_code)]
struct Foo<T: ?Sized> {
a: u16,
b: T
b: T,
}

trait Bar {
fn get(&self) -> usize;
}

impl Bar for usize {
fn get(&self) -> usize { *self }
fn get(&self) -> usize {
*self
}
}

struct Baz<T: ?Sized> {
a: T
a: T,
}

struct HasDrop<T: ?Sized> {
ptr: Box<usize>,
data: T
data: T,
}

fn main() {
// Test that zero-offset works properly
let b : Baz<usize> = Baz { a: 7 };
let b: Baz<usize> = Baz { a: 7 };
assert_eq!(b.a.get(), 7);
let b : &Baz<dyn Bar> = &b;
let b: &Baz<dyn Bar> = &b;
assert_eq!(b.a.get(), 7);

// Test that the field is aligned properly
let f : Foo<usize> = Foo { a: 0, b: 11 };
let f: Foo<usize> = Foo { a: 0, b: 11 };
assert_eq!(f.b.get(), 11);
let ptr1 : *const u8 = &f.b as *const _ as *const u8;
let ptr1: *const u8 = &f.b as *const _ as *const u8;

let f : &Foo<dyn Bar> = &f;
let ptr2 : *const u8 = &f.b as *const _ as *const u8;
let f: &Foo<dyn Bar> = &f;
let ptr2: *const u8 = &f.b as *const _ as *const u8;
assert_eq!(f.b.get(), 11);

// The pointers should be the same
assert_eq!(ptr1, ptr2);

// Test that nested DSTs work properly
let f : Foo<Foo<usize>> = Foo { a: 0, b: Foo { a: 1, b: 17 }};
let f: Foo<Foo<usize>> = Foo { a: 0, b: Foo { a: 1, b: 17 } };
assert_eq!(f.b.b.get(), 17);
let f : &Foo<Foo<dyn Bar>> = &f;
let f: &Foo<Foo<dyn Bar>> = &f;
assert_eq!(f.b.b.get(), 17);

// Test that get the pointer via destructuring works

let f : Foo<usize> = Foo { a: 0, b: 11 };
let f : &Foo<dyn Bar> = &f;
let f: Foo<usize> = Foo { a: 0, b: 11 };
let f: &Foo<dyn Bar> = &f;
let &Foo { a: _, b: ref bar } = f;
assert_eq!(bar.get(), 11);

// Make sure that drop flags don't screw things up

let d : HasDrop<Baz<[i32; 4]>> = HasDrop {
ptr: Box::new(0),
data: Baz { a: [1,2,3,4] }
};
assert_eq!([1,2,3,4], d.data.a);
let d: HasDrop<Baz<[i32; 4]>> = HasDrop { ptr: Box::new(0), data: Baz { a: [1, 2, 3, 4] } };
assert_eq!([1, 2, 3, 4], d.data.a);

let d : &HasDrop<Baz<[i32]>> = &d;
assert_eq!(&[1,2,3,4], &d.data.a);
let d: &HasDrop<Baz<[i32]>> = &d;
assert_eq!(&[1, 2, 3, 4], &d.data.a);
}
6 changes: 1 addition & 5 deletions example/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ pub fn abc(a: u8) -> u8 {
}

pub fn bcd(b: bool, a: u8) -> u8 {
if b {
a * 2
} else {
a * 3
}
if b { a * 2 } else { a * 3 }
}

pub fn call() {
Expand Down
4 changes: 3 additions & 1 deletion example/issue-72793.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#![feature(type_alias_impl_trait)]

trait T { type Item; }
trait T {
type Item;
}

type Alias<'a> = impl T<Item = &'a ()>;

Expand Down
5 changes: 1 addition & 4 deletions example/issue-91827-extern-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ impl<T, const N: usize> ListImpl<T, N> {
}
}

pub static A: ListImpl<u128, 3> = ListImpl {
len: 3,
data: [5, 6, 7],
};
pub static A: ListImpl<u128, 3> = ListImpl { len: 3, data: [5, 6, 7] };
pub static A_REF: &'static List<u128> = A.as_list();
pub static A_TAIL_OFFSET: isize = tail_offset(A.as_list());

Expand Down
41 changes: 27 additions & 14 deletions example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
pub trait DispatchFromDyn<T> {}

// &T -> &U
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
// &mut T -> &mut U
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
// *const T -> *const U
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
// *mut T -> *mut U
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U>> for Box<T> {}

#[lang = "receiver"]
Expand Down Expand Up @@ -288,7 +288,6 @@ impl PartialEq for u32 {
}
}


impl PartialEq for u64 {
fn eq(&self, other: &u64) -> bool {
(*self) == (*other)
Expand Down Expand Up @@ -361,7 +360,7 @@ impl<T: ?Sized> PartialEq for *const T {
}
}

impl <T: PartialEq> PartialEq for Option<T> {
impl<T: PartialEq> PartialEq for Option<T> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Some(lhs), Some(rhs)) => *lhs == *rhs,
Expand Down Expand Up @@ -472,7 +471,11 @@ pub fn panic(_msg: &'static str) -> ! {
#[track_caller]
fn panic_bounds_check(index: usize, len: usize) -> ! {
unsafe {
libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index);
libc::printf(
"index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8,
len,
index,
);
intrinsics::abort();
}
}
Expand Down Expand Up @@ -599,7 +602,7 @@ pub mod libc {
// functions. legacy_stdio_definitions.lib which provides the printf wrapper functions as normal
// symbols to link against.
#[cfg_attr(unix, link(name = "c"))]
#[cfg_attr(target_env="msvc", link(name="legacy_stdio_definitions"))]
#[cfg_attr(target_env = "msvc", link(name = "legacy_stdio_definitions"))]
extern "C" {
pub fn printf(format: *const i8, ...) -> i32;
}
Expand Down Expand Up @@ -638,7 +641,7 @@ impl<T> Index<usize> for [T] {
}
}

extern {
extern "C" {
type VaListImpl;
}

Expand All @@ -648,23 +651,33 @@ pub struct VaList<'a>(&'a mut VaListImpl);

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro stringify($($t:tt)*) { /* compiler built-in */ }
pub macro stringify($($t:tt)*) {
/* compiler built-in */
}

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro file() { /* compiler built-in */ }
pub macro file() {
/* compiler built-in */
}

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro line() { /* compiler built-in */ }
pub macro line() {
/* compiler built-in */
}

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro cfg() { /* compiler built-in */ }
pub macro cfg() {
/* compiler built-in */
}

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro global_asm() { /* compiler built-in */ }
pub macro global_asm() {
/* compiler built-in */
}

pub static A_STATIC: u8 = 42;

Expand Down
Loading

0 comments on commit 18184d8

Please sign in to comment.