summaryrefslogtreecommitdiff
path: root/src/tools/rustfmt/tests/target/type.rs
blob: c789ecb055a7df642549b525326661b628a0af27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// rustfmt-normalize_comments: true
fn types() {
    let x: [Vec<_>] = [];
    let y: *mut [SomeType; konst_funk()] = expr();
    let z: (/* #digits */ usize, /* exp */ i16) = funk();
    let z: (usize /* #digits */, i16 /* exp */) = funk();
}

struct F {
    f: extern "C" fn(x: u8, ... /* comment */),
    g: extern "C" fn(x: u8, /* comment */ ...),
    h: extern "C" fn(x: u8, ...),
    i: extern "C" fn(
        x: u8,
        // comment 4
        y: String, // comment 3
        z: Foo,
        // comment
        ... // comment 2
    ),
}

fn issue_1006(def_id_to_string: for<'a, 'b> unsafe fn(TyCtxt<'b, 'tcx, 'tcx>, DefId) -> String) {}

fn impl_trait_fn_1() -> impl Fn(i32) -> Option<u8> {}

fn impl_trait_fn_2<E>() -> impl Future<Item = &'a i64, Error = E> {}

fn issue_1234() {
    do_parse!(name: take_while1!(is_token) >> (Header))
}

// #2510
impl CombineTypes {
    pub fn pop_callback(
        &self,
        query_id: Uuid,
    ) -> Option<(
        ProjectId,
        Box<FnMut(&ProjectState, serde_json::Value, bool) -> () + Sync + Send>,
    )> {
        self.query_callbacks()(&query_id)
    }
}

// #2859
pub fn do_something<'a, T: Trait1 + Trait2 + 'a>(
    &fooo: u32,
) -> impl Future<
    Item = (
        impl Future<Item = (), Error = SomeError> + 'a,
        impl Future<Item = (), Error = SomeError> + 'a,
        impl Future<Item = (), Error = SomeError> + 'a,
    ),
    Error = SomeError,
> + 'a {
}

pub fn do_something<'a, T: Trait1 + Trait2 + 'a>(
    &fooo: u32,
) -> impl Future<
    Item = (
        impl Future<Item = (), Error = SomeError> + 'a,
        impl Future<Item = (), Error = SomeError> + 'a,
        impl Future<Item = (), Error = SomeError> + 'a,
    ),
    Error = SomeError,
> + Future<
    Item = (
        impl Future<Item = (), Error = SomeError> + 'a,
        impl Future<Item = (), Error = SomeError> + 'a,
        impl Future<Item = (), Error = SomeError> + 'a,
    ),
    Error = SomeError,
> + Future<
    Item = (
        impl Future<Item = (), Error = SomeError> + 'a,
        impl Future<Item = (), Error = SomeError> + 'a,
        impl Future<Item = (), Error = SomeError> + 'a,
    ),
    Error = SomeError,
> + 'a + 'b + 'c {
}

// #3051
token![impl];
token![impl];

// #3060
macro_rules! foo {
    ($foo_api: ty) => {
        type Target = ($foo_api) + 'static;
    };
}

type Target = (FooAPI) + 'static;

// #3137
fn foo<T>(t: T)
where
    T: (FnOnce() -> ()) + Clone,
    U: (FnOnce() -> ()) + 'static,
{
}

// #3117
fn issue3117() {
    {
        {
            {
                {
                    {
                        {
                            {
                                {
                                    let opt: &mut Option<MyLongTypeHere> =
                                        unsafe { &mut *self.future.get() };
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

// #3139
fn issue3139() {
    assert_eq!(
        to_json_value(&None::<i32>).unwrap(),
        json!(  { "test": None  ::  <i32> }  )
    );
}

// #3180
fn foo(
    a: SomeLongComplexType,
    b: SomeOtherLongComplexType,
) -> Box<Future<Item = AnotherLongType, Error = ALongErrorType>> {
}

type MyFn = fn(
    a: SomeLongComplexType,
    b: SomeOtherLongComplexType,
) -> Box<Future<Item = AnotherLongType, Error = ALongErrorType>>;

// Const bound

trait T: ~const Super {}

const fn not_quite_const<S: ~const T>() -> i32 {
    <S as T>::CONST
}

struct S<T: ~const ?Sized>(std::marker::PhantomData<T>);

impl ~const T {}

fn apit(_: impl ~const T) {}

fn rpit() -> impl ~const T {
    S
}

pub struct Foo<T: Trait>(T);
impl<T: ~const Trait> Foo<T> {
    fn new(t: T) -> Self {
        Self(t)
    }
}

// #4357
type T = typeof(1);
impl T for .. {}