]> git.lizzy.rs Git - rust.git/blob - tests/source/type.rs
Merge pull request #3144 from otavio/issues-3143
[rust.git] / tests / source / 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(x: u8, /* comment 4*/ y: String, // comment 3
14                      z: Foo, /* comment */ .../* comment 2*/ ),
15 }
16
17 fn issue_1006(def_id_to_string: for<'a, 'b> unsafe fn(TyCtxt<'b, 'tcx, 'tcx>, DefId) -> String) {}
18
19 fn impl_trait_fn_1() -> impl Fn(i32) -> Option<u8> {}
20
21 fn impl_trait_fn_2<E>() -> impl Future<Item=&'a i64,Error=E> {}
22
23 fn issue_1234() {
24     do_parse!(name: take_while1!(is_token) >> (Header))
25 }
26
27 // #2510
28 impl 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
43 pub 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,
48 impl Future<Item = (), Error = SomeError > + 'a,
49     ),
50     Error = SomeError,
51     >
52     +
53     'a {
54 }
55
56 pub fn do_something<'a, T: Trait1 + Trait2 + 'a>(    &fooo: u32,
57 ) -> impl Future<
58     Item = (
59 impl 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,
68 impl 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 // #3060
87 macro_rules! foo {
88     ($foo_api: ty) => {
89         type Target = ( $foo_api ) + 'static;
90     }
91 }
92
93 type Target = ( FooAPI ) + 'static;
94
95 // #3137
96 fn foo<T>(t: T)
97 where
98     T: ( FnOnce() -> () ) + Clone,
99     U: ( FnOnce() -> () ) + 'static,
100 {
101 }
102
103 // #3117
104 fn issue3117() {
105     {
106         {
107             {
108                 {
109                     {
110                         {
111                             {
112                                 {
113                                     let opt: &mut Option<MyLongTypeHere> =
114                                         unsafe { &mut *self.future.get() };
115                                 }
116                             }
117                         }
118                     }
119                 }
120             }
121         }
122     }
123 }
124
125 // #3139
126 fn issue3139() {
127     assert_eq!(
128         to_json_value(&None ::  <i32>).unwrap(),
129         json!(  { "test": None  ::  <i32> }  )
130     );
131 }