]> git.lizzy.rs Git - rust.git/blob - src/tools/rustfmt/tests/target/type.rs
Auto merge of #83342 - Count-Count:win-console-incomplete-utf8, r=m-ou-se
[rust.git] / src / tools / rustfmt / tests / target / type.rs
1 // rustfmt-normalize_comments: true
2 fn types() {
3     let x: [Vec<_>] = [];
4     let y: *mut [SomeType; konst_funk()] = expr();
5     let z: (/* #digits */ usize, /* exp */ i16) = funk();
6     let z: (usize /* #digits */, i16 /* exp */) = funk();
7 }
8
9 struct F {
10     f: extern "C" fn(x: u8, ... /* comment */),
11     g: extern "C" fn(x: u8, /* comment */ ...),
12     h: extern "C" fn(x: u8, ...),
13     i: extern "C" fn(
14         x: u8,
15         // comment 4
16         y: String, // comment 3
17         z: Foo,
18         // comment
19         ... // comment 2
20     ),
21 }
22
23 fn issue_1006(def_id_to_string: for<'a, 'b> unsafe fn(TyCtxt<'b, 'tcx, 'tcx>, DefId) -> String) {}
24
25 fn impl_trait_fn_1() -> impl Fn(i32) -> Option<u8> {}
26
27 fn impl_trait_fn_2<E>() -> impl Future<Item = &'a i64, Error = E> {}
28
29 fn issue_1234() {
30     do_parse!(name: take_while1!(is_token) >> (Header))
31 }
32
33 // #2510
34 impl CombineTypes {
35     pub fn pop_callback(
36         &self,
37         query_id: Uuid,
38     ) -> Option<(
39         ProjectId,
40         Box<FnMut(&ProjectState, serde_json::Value, bool) -> () + Sync + Send>,
41     )> {
42         self.query_callbacks()(&query_id)
43     }
44 }
45
46 // #2859
47 pub fn do_something<'a, T: Trait1 + Trait2 + 'a>(
48     &fooo: u32,
49 ) -> impl Future<
50     Item = (
51         impl Future<Item = (), Error = SomeError> + 'a,
52         impl Future<Item = (), Error = SomeError> + 'a,
53         impl Future<Item = (), Error = SomeError> + 'a,
54     ),
55     Error = SomeError,
56 > + 'a {
57 }
58
59 pub fn do_something<'a, T: Trait1 + Trait2 + 'a>(
60     &fooo: u32,
61 ) -> impl Future<
62     Item = (
63         impl Future<Item = (), Error = SomeError> + 'a,
64         impl Future<Item = (), Error = SomeError> + 'a,
65         impl Future<Item = (), Error = SomeError> + 'a,
66     ),
67     Error = SomeError,
68 > + Future<
69     Item = (
70         impl Future<Item = (), Error = SomeError> + 'a,
71         impl Future<Item = (), Error = SomeError> + 'a,
72         impl Future<Item = (), Error = SomeError> + 'a,
73     ),
74     Error = SomeError,
75 > + Future<
76     Item = (
77         impl Future<Item = (), Error = SomeError> + 'a,
78         impl Future<Item = (), Error = SomeError> + 'a,
79         impl Future<Item = (), Error = SomeError> + 'a,
80     ),
81     Error = SomeError,
82 > + 'a + 'b + 'c {
83 }
84
85 // #3051
86 token![impl];
87 token![impl];
88
89 // #3060
90 macro_rules! foo {
91     ($foo_api: ty) => {
92         type Target = ($foo_api) + 'static;
93     };
94 }
95
96 type Target = (FooAPI) + 'static;
97
98 // #3137
99 fn foo<T>(t: T)
100 where
101     T: (FnOnce() -> ()) + Clone,
102     U: (FnOnce() -> ()) + 'static,
103 {
104 }
105
106 // #3117
107 fn issue3117() {
108     {
109         {
110             {
111                 {
112                     {
113                         {
114                             {
115                                 {
116                                     let opt: &mut Option<MyLongTypeHere> =
117                                         unsafe { &mut *self.future.get() };
118                                 }
119                             }
120                         }
121                     }
122                 }
123             }
124         }
125     }
126 }
127
128 // #3139
129 fn issue3139() {
130     assert_eq!(
131         to_json_value(&None::<i32>).unwrap(),
132         json!({ "test": None::<i32> })
133     );
134 }
135
136 // #3180
137 fn foo(
138     a: SomeLongComplexType,
139     b: SomeOtherLongComplexType,
140 ) -> Box<Future<Item = AnotherLongType, Error = ALongErrorType>> {
141 }
142
143 type MyFn = fn(
144     a: SomeLongComplexType,
145     b: SomeOtherLongComplexType,
146 ) -> Box<Future<Item = AnotherLongType, Error = ALongErrorType>>;
147
148 // Const bound
149
150 trait T: ~const Super {}
151
152 const fn not_quite_const<S: ~const T>() -> i32 {
153     <S as T>::CONST
154 }
155
156 struct S<T: ~const ?Sized>(std::marker::PhantomData<T>);
157
158 impl ~const T {}
159
160 fn apit(_: impl ~const T) {}
161
162 fn rpit() -> impl ~const T {
163     S
164 }
165
166 pub struct Foo<T: Trait>(T);
167 impl<T: ~const Trait> Foo<T> {
168     fn new(t: T) -> Self {
169         Self(t)
170     }
171 }
172
173 // #4357
174 type T = typeof(1);
175 impl T for .. {}