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