]>
git.proxmox.com Git - rustc.git/blob - src/test/rustdoc/async-fn.rs
2 // @has async_fn/fn.foo.html '//pre[@class="rust fn"]' 'pub async fn foo() -> Option<Foo>'
3 pub async
fn foo() -> Option
<Foo
> {
7 // @has async_fn/fn.bar.html '//pre[@class="rust fn"]' 'pub async fn bar(a: i32, b: i32) -> i32'
8 pub async
fn bar(a
: i32, b
: i32) -> i32 {
12 // @has async_fn/fn.baz.html '//pre[@class="rust fn"]' 'pub async fn baz<T>(a: T) -> T'
13 pub async
fn baz
<T
>(a
: T
) -> T
{
17 // @has async_fn/fn.qux.html '//pre[@class="rust fn"]' 'pub async unsafe fn qux() -> char'
18 pub async
unsafe fn qux() -> char {
22 // @has async_fn/fn.mut_args.html '//pre[@class="rust fn"]' 'pub async fn mut_args(a: usize)'
23 pub async
fn mut_args(mut a
: usize) {}
25 // @has async_fn/fn.mut_ref.html '//pre[@class="rust fn"]' 'pub async fn mut_ref(x: i32)'
26 pub async
fn mut_ref(ref mut x
: i32) {}
32 // @has async_fn/fn.quux.html '//pre[@class="rust fn"]' 'pub async fn quux() -> impl Bar'
33 pub async
fn quux() -> impl Bar
{
37 // @has async_fn/struct.Foo.html
38 // @matches - '//h4[@class="code-header"]' 'pub async fn f\(\)$'
39 // @matches - '//h4[@class="code-header"]' 'pub async unsafe fn g\(\)$'
40 // @matches - '//h4[@class="code-header"]' 'pub async fn mut_self\(self, first: usize\)$'
45 pub async
unsafe fn g() {}
46 pub async
fn mut_self(mut self, mut first
: usize) {}
49 pub trait Pattern
<'a
> {}
51 pub trait Trait
<const N
: usize> {}
52 // @has async_fn/fn.const_generics.html
53 // @has - '//pre[@class="rust fn"]' 'pub async fn const_generics<const N: usize>(_: impl Trait<N>)'
54 pub async
fn const_generics
<const N
: usize>(_
: impl Trait
<N
>) {}
56 // test that elided lifetimes are properly elided and not displayed as `'_`
57 // regression test for #63037
58 // @has async_fn/fn.elided.html
59 // @has - '//pre[@class="rust fn"]' 'pub async fn elided(foo: &str) -> &str'
60 pub async
fn elided(foo
: &str) -> &str {}
61 // This should really be shown as written, but for implementation reasons it's difficult.
62 // See `impl Clean for TyKind::Rptr`.
63 // @has async_fn/fn.user_elided.html
64 // @has - '//pre[@class="rust fn"]' 'pub async fn user_elided(foo: &str) -> &str'
65 pub async
fn user_elided(foo
: &'_
str) -> &str {}
66 // @has async_fn/fn.static_trait.html
67 // @has - '//pre[@class="rust fn"]' 'pub async fn static_trait(foo: &str) -> Box<dyn Bar>'
68 pub async
fn static_trait(foo
: &str) -> Box
<dyn Bar
> {}
69 // @has async_fn/fn.lifetime_for_trait.html
70 // @has - '//pre[@class="rust fn"]' "pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_>"
71 pub async
fn lifetime_for_trait(foo
: &str) -> Box
<dyn Bar
+ '_
> {}
72 // @has async_fn/fn.elided_in_input_trait.html
73 // @has - '//pre[@class="rust fn"]' "pub async fn elided_in_input_trait(t: impl Pattern<'_>)"
74 pub async
fn elided_in_input_trait(t
: impl Pattern
<'_
>) {}
76 struct AsyncFdReadyGuard
<'a
, T
> { x: &'a T }
79 // @has async_fn/struct.Foo.html
80 // @has - '//div[@class="method has-srclink"]' 'pub async fn complicated_lifetimes( &self, context: &impl Bar) -> impl Iterator<Item = &usize>'
81 pub async
fn complicated_lifetimes(&self, context
: &impl Bar
) -> impl Iterator
<Item
= &usize> {}
82 // taken from `tokio` as an example of a method that was particularly bad before
83 // @has - '//div[@class="method has-srclink"]' "pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()>"
84 pub async
fn readable
<T
>(&self) -> Result
<AsyncFdReadyGuard
<'_
, T
>, ()> {}
85 // @has - '//div[@class="method has-srclink"]' "pub async fn mut_self(&mut self)"
86 pub async
fn mut_self(&mut self) {}
89 // test named lifetimes, just in case
90 // @has async_fn/fn.named.html
91 // @has - '//pre[@class="rust fn"]' "pub async fn named<'a, 'b>(foo: &'a str) -> &'b str"
92 pub async
fn named
<'a
, 'b
>(foo
: &'a
str) -> &'b
str {}
93 // @has async_fn/fn.named_trait.html
94 // @has - '//pre[@class="rust fn"]' "pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b>"
95 pub async
fn named_trait
<'a
, 'b
>(foo
: impl Pattern
<'a
>) -> impl Pattern
<'b
> {}