]> git.lizzy.rs Git - rust.git/blob - tests/ui/impl-trait/recursive-impl-trait-type-indirect.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[rust.git] / tests / ui / impl-trait / recursive-impl-trait-type-indirect.rs
1 // revisions: no_drop_tracking drop_tracking drop_tracking_mir
2 // [drop_tracking] compile-flags: -Zdrop-tracking
3 // [drop_tracking_mir] compile-flags: -Zdrop-tracking-mir
4
5 // Test that impl trait does not allow creating recursive types that are
6 // otherwise forbidden.
7
8 #![feature(generators)]
9 #![allow(unconditional_recursion)]
10
11 fn option(i: i32) -> impl Sized {
12     //~^ ERROR cannot resolve opaque type
13     if i < 0 { None } else { Some((option(i - 1), i)) }
14 }
15
16 fn tuple() -> impl Sized {
17     //~^ ERROR
18     (tuple(),)
19 }
20
21 fn array() -> impl Sized {
22     //~^ ERROR
23     [array()]
24 }
25
26 fn ptr() -> impl Sized {
27     //~^ ERROR
28     &ptr() as *const _
29 }
30
31 fn fn_ptr() -> impl Sized {
32     //~^ ERROR
33     fn_ptr as fn() -> _
34 }
35
36 fn closure_capture() -> impl Sized {
37     //~^ ERROR
38     let x = closure_capture();
39     move || {
40         x;
41     }
42 }
43
44 fn closure_ref_capture() -> impl Sized {
45     //~^ ERROR
46     let x = closure_ref_capture();
47     move || {
48         &x;
49     }
50 }
51
52 fn closure_sig() -> impl Sized {
53     //~^ ERROR
54     || closure_sig()
55 }
56
57 fn generator_sig() -> impl Sized {
58     //~^ ERROR
59     || generator_sig()
60 }
61
62 fn generator_capture() -> impl Sized {
63     //~^ ERROR
64     let x = generator_capture();
65     move || {
66         yield;
67         x;
68     }
69 }
70
71 fn substs_change<T: 'static>() -> impl Sized {
72     //~^ ERROR
73     (substs_change::<&T>(),)
74 }
75
76 fn generator_hold() -> impl Sized {
77     //~^ ERROR
78     move || {
79         let x = generator_hold();
80         yield;
81         x;
82     }
83 }
84
85 fn use_fn_ptr() -> impl Sized {
86     // OK, error already reported
87     fn_ptr()
88 }
89
90 fn mutual_recursion() -> impl Sync {
91     //~^ ERROR
92     mutual_recursion_b()
93 }
94
95 fn mutual_recursion_b() -> impl Sized {
96     //~^ ERROR
97     mutual_recursion()
98 }
99
100 fn main() {}