]>
git.proxmox.com Git - rustc.git/blob - src/test/rustdoc/async-fn.rs
1 // ignore-tidy-linelength
3 #![feature(min_const_generics)]
5 // @has async_fn/fn.foo.html '//pre[@class="rust fn"]' 'pub async fn foo() -> Option<Foo>'
6 pub async
fn foo() -> Option
<Foo
> {
10 // @has async_fn/fn.bar.html '//pre[@class="rust fn"]' 'pub async fn bar(a: i32, b: i32) -> i32'
11 pub async
fn bar(a
: i32, b
: i32) -> i32 {
15 // @has async_fn/fn.baz.html '//pre[@class="rust fn"]' 'pub async fn baz<T>(a: T) -> T'
16 pub async
fn baz
<T
>(a
: T
) -> T
{
20 // @has async_fn/fn.qux.html '//pre[@class="rust fn"]' 'pub async unsafe fn qux() -> char'
21 pub async
unsafe fn qux() -> char {
25 // @has async_fn/fn.mut_args.html '//pre[@class="rust fn"]' 'pub async fn mut_args(a: usize)'
26 pub async
fn mut_args(mut a
: usize) {}
28 // @has async_fn/fn.mut_ref.html '//pre[@class="rust fn"]' 'pub async fn mut_ref(x: i32)'
29 pub async
fn mut_ref(ref mut x
: i32) {}
35 // @has async_fn/fn.quux.html '//pre[@class="rust fn"]' 'pub async fn quux() -> impl Bar'
36 pub async
fn quux() -> impl Bar
{
40 // @has async_fn/struct.Foo.html
41 // @matches - '//code' 'pub async fn f\(\)$'
42 // @matches - '//code' 'pub async unsafe fn g\(\)$'
43 // @matches - '//code' 'pub async fn mut_self\(self, first: usize\)$'
48 pub async
unsafe fn g() {}
49 pub async
fn mut_self(mut self, mut first
: usize) {}
52 pub trait Pattern
<'a
> {}
54 pub trait Trait
<const N
: usize> {}
55 // @has async_fn/fn.const_generics.html
56 // @has - '//pre[@class="rust fn"]' 'pub async fn const_generics<const N: usize>(_: impl Trait<N>)'
57 pub async
fn const_generics
<const N
: usize>(_
: impl Trait
<N
>) {}
59 // test that elided lifetimes are properly elided and not displayed as `'_`
60 // regression test for #63037
61 // @has async_fn/fn.elided.html
62 // @has - '//pre[@class="rust fn"]' 'pub async fn elided(foo: &str) -> &str'
63 pub async
fn elided(foo
: &str) -> &str {}
64 // This should really be shown as written, but for implementation reasons it's difficult.
65 // See `impl Clean for TyKind::Rptr`.
66 // @has async_fn/fn.user_elided.html
67 // @has - '//pre[@class="rust fn"]' 'pub async fn user_elided(foo: &str) -> &str'
68 pub async
fn user_elided(foo
: &'_
str) -> &str {}
69 // @has async_fn/fn.static_trait.html
70 // @has - '//pre[@class="rust fn"]' 'pub async fn static_trait(foo: &str) -> Box<dyn Bar>'
71 pub async
fn static_trait(foo
: &str) -> Box
<dyn Bar
> {}
72 // @has async_fn/fn.lifetime_for_trait.html
73 // @has - '//pre[@class="rust fn"]' "pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_>"
74 pub async
fn lifetime_for_trait(foo
: &str) -> Box
<dyn Bar
+ '_
> {}
75 // @has async_fn/fn.elided_in_input_trait.html
76 // @has - '//pre[@class="rust fn"]' "pub async fn elided_in_input_trait(t: impl Pattern<'_>)"
77 pub async
fn elided_in_input_trait(t
: impl Pattern
<'_
>) {}
79 struct AsyncFdReadyGuard
<'a
, T
> { x: &'a T }
82 // @has async_fn/struct.Foo.html
83 // @has - '//h4[@class="method"]' 'pub async fn complicated_lifetimes( &self, context: &impl Bar) -> impl Iterator<Item = &usize>'
84 pub async
fn complicated_lifetimes(&self, context
: &impl Bar
) -> impl Iterator
<Item
= &usize> {}
85 // taken from `tokio` as an example of a method that was particularly bad before
86 // @has - '//h4[@class="method"]' "pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()>"
87 pub async
fn readable
<T
>(&self) -> Result
<AsyncFdReadyGuard
<'_
, T
>, ()> {}
88 // @has - '//h4[@class="method"]' "pub async fn mut_self(&mut self)"
89 pub async
fn mut_self(&mut self) {}
92 // test named lifetimes, just in case
93 // @has async_fn/fn.named.html
94 // @has - '//pre[@class="rust fn"]' "pub async fn named<'a, 'b>(foo: &'a str) -> &'b str"
95 pub async
fn named
<'a
, 'b
>(foo
: &'a
str) -> &'b
str {}
96 // @has async_fn/fn.named_trait.html
97 // @has - '//pre[@class="rust fn"]' "pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b>"
98 pub async
fn named_trait
<'a
, 'b
>(foo
: impl Pattern
<'a
>) -> impl Pattern
<'b
> {}