]> git.lizzy.rs Git - rust.git/blob - src/test/ui/async-await/generics-and-bounds.rs
Override rustc version in ui and mir-opt tests to get stable hashes
[rust.git] / src / test / ui / async-await / generics-and-bounds.rs
1 // build-pass (FIXME(62277): could be check-pass?)
2 // edition:2018
3 // compile-flags: --crate-type lib
4
5 #![feature(in_band_lifetimes)]
6
7 use std::future::Future;
8
9 pub async fn simple_generic<T>() {}
10
11 pub trait Foo {
12     fn foo(&self) {}
13 }
14
15 struct FooType;
16 impl Foo for FooType {}
17
18 pub async fn call_generic_bound<F: Foo>(f: F) {
19     f.foo()
20 }
21
22 pub async fn call_where_clause<F>(f: F)
23 where
24     F: Foo,
25 {
26     f.foo()
27 }
28
29 pub async fn call_impl_trait(f: impl Foo) {
30     f.foo()
31 }
32
33 pub async fn call_with_ref(f: &impl Foo) {
34     f.foo()
35 }
36
37 pub fn async_fn_with_same_generic_params_unifies() {
38     let mut a = call_generic_bound(FooType);
39     a = call_generic_bound(FooType);
40
41     let mut b = call_where_clause(FooType);
42     b = call_where_clause(FooType);
43
44     let mut c = call_impl_trait(FooType);
45     c = call_impl_trait(FooType);
46
47     let f_one = FooType;
48     let f_two = FooType;
49     let mut d = call_with_ref(&f_one);
50     d = call_with_ref(&f_two);
51 }
52
53 pub fn simple_generic_block<T>() -> impl Future<Output = ()> {
54     async move {}
55 }
56
57 pub fn call_generic_bound_block<F: Foo>(f: F) -> impl Future<Output = ()> {
58     async move { f.foo() }
59 }
60
61 pub fn call_where_clause_block<F>(f: F) -> impl Future<Output = ()>
62 where
63     F: Foo,
64 {
65     async move { f.foo() }
66 }
67
68 pub fn call_impl_trait_block(f: impl Foo) -> impl Future<Output = ()> {
69     async move { f.foo() }
70 }
71
72 pub fn call_with_ref_block<'a>(f: &'a (impl Foo + 'a)) -> impl Future<Output = ()> + 'a {
73     async move { f.foo() }
74 }
75
76 pub fn call_with_ref_block_in_band(f: &'a (impl Foo + 'a)) -> impl Future<Output = ()> + 'a {
77     async move { f.foo() }
78 }
79
80 pub fn async_block_with_same_generic_params_unifies() {
81     let mut a = call_generic_bound_block(FooType);
82     a = call_generic_bound_block(FooType);
83
84     let mut b = call_where_clause_block(FooType);
85     b = call_where_clause_block(FooType);
86
87     let mut c = call_impl_trait_block(FooType);
88     c = call_impl_trait_block(FooType);
89
90     let f_one = FooType;
91     let f_two = FooType;
92     let mut d = call_with_ref_block(&f_one);
93     d = call_with_ref_block(&f_two);
94
95     let f_one = FooType;
96     let f_two = FooType;
97     let mut d = call_with_ref_block_in_band(&f_one);
98     d = call_with_ref_block_in_band(&f_two);
99 }