]> git.lizzy.rs Git - rust.git/blob - tests/ui/type-alias-impl-trait/issue-96572-unconstrained.rs
Rollup merge of #106766 - GuillaumeGomez:rm-stripper-dead-code, r=notriddle
[rust.git] / tests / ui / type-alias-impl-trait / issue-96572-unconstrained.rs
1 #![feature(type_alias_impl_trait)]
2 // check-pass
3
4 fn main() {
5     type T = impl Copy;
6     let foo: T = Some((1u32, 2u32));
7     match foo {
8         None => (),
9         Some((a, b)) => (),
10     }
11 }
12
13 fn upvar() {
14     #[derive(Copy, Clone)]
15     struct Foo((u32, u32));
16
17     type T = impl Copy;
18     let foo: T = Foo((1u32, 2u32));
19     let x = move || {
20         let Foo((a, b)) = foo;
21     };
22 }
23
24 fn enum_upvar() {
25     type T = impl Copy;
26     let foo: T = Some((1u32, 2u32));
27     let x = move || {
28         match foo {
29             None => (),
30             Some((a, b)) => (),
31         }
32     };
33 }
34
35 fn r#struct() {
36     #[derive(Copy, Clone)]
37     struct Foo((u32, u32));
38
39     type U = impl Copy;
40     let foo: U = Foo((1u32, 2u32));
41     let Foo((a, b)) = foo;
42 }
43
44 mod only_pattern {
45     type T = impl Copy;
46
47     fn foo(foo: T) {
48         let (mut x, mut y) = foo;
49         x = 42;
50         y = "foo";
51     }
52
53     type U = impl Copy;
54
55     fn bar(bar: Option<U>) {
56         match bar {
57             Some((mut x, mut y)) => {
58                 x = 42;
59                 y = "foo";
60             }
61             None => {}
62         }
63     }
64 }
65
66 mod only_pattern_rpit {
67     #[allow(unconditional_recursion)]
68     fn foo(b: bool) -> impl Copy {
69         let (mut x, mut y) = foo(false);
70         x = 42;
71         y = "foo";
72         if b {
73             panic!()
74         } else {
75             foo(true)
76         }
77     }
78
79     fn bar(b: bool) -> Option<impl Copy> {
80         if b {
81             return None;
82         }
83         match bar(!b) {
84             Some((mut x, mut y)) => {
85                 x = 42;
86                 y = "foo";
87             }
88             None => {}
89         }
90         None
91     }
92 }