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