1 // ignore-tidy-linelength
3 // @has async_fn/fn.foo.html '//pre[@class="rust fn"]' 'pub async fn foo() -> Option<Foo>'
4 pub async fn foo() -> Option<Foo> {
8 // @has async_fn/fn.bar.html '//pre[@class="rust fn"]' 'pub async fn bar(a: i32, b: i32) -> i32'
9 pub async fn bar(a: i32, b: i32) -> i32 {
13 // @has async_fn/fn.baz.html '//pre[@class="rust fn"]' 'pub async fn baz<T>(a: T) -> T'
14 pub async fn baz<T>(a: T) -> T {
18 // @has async_fn/fn.qux.html '//pre[@class="rust fn"]' 'pub async unsafe fn qux() -> char'
19 pub async unsafe fn qux() -> char {
23 // @has async_fn/fn.mut_args.html '//pre[@class="rust fn"]' 'pub async fn mut_args(a: usize)'
24 pub async fn mut_args(mut a: usize) {}
26 // @has async_fn/fn.mut_ref.html '//pre[@class="rust fn"]' 'pub async fn mut_ref(x: i32)'
27 pub async fn mut_ref(ref mut x: i32) {}
33 // @has async_fn/fn.quux.html '//pre[@class="rust fn"]' 'pub async fn quux() -> impl Bar'
34 pub async fn quux() -> impl Bar {
38 // @has async_fn/struct.Foo.html
39 // @matches - '//code' 'pub async fn f\(\)$'
40 // @matches - '//code' 'pub async unsafe fn g\(\)$'
41 // @matches - '//code' 'pub async fn mut_self\(self, first: usize\)$'
46 pub async unsafe fn g() {}
47 pub async fn mut_self(mut self, mut first: usize) {}
50 pub trait Pattern<'a> {}
52 pub trait Trait<const N: usize> {}
53 // @has async_fn/fn.const_generics.html
54 // @has - '//pre[@class="rust fn"]' 'pub async fn const_generics<const N: usize>(_: impl Trait<N>)'
55 pub async fn const_generics<const N: usize>(_: impl Trait<N>) {}
57 // test that elided lifetimes are properly elided and not displayed as `'_`
58 // regression test for #63037
59 // @has async_fn/fn.elided.html
60 // @has - '//pre[@class="rust fn"]' 'pub async fn elided(foo: &str) -> &str'
61 pub async fn elided(foo: &str) -> &str {}
62 // This should really be shown as written, but for implementation reasons it's difficult.
63 // See `impl Clean for TyKind::Rptr`.
64 // @has async_fn/fn.user_elided.html
65 // @has - '//pre[@class="rust fn"]' 'pub async fn user_elided(foo: &str) -> &str'
66 pub async fn user_elided(foo: &'_ str) -> &str {}
67 // @has async_fn/fn.static_trait.html
68 // @has - '//pre[@class="rust fn"]' 'pub async fn static_trait(foo: &str) -> Box<dyn Bar>'
69 pub async fn static_trait(foo: &str) -> Box<dyn Bar> {}
70 // @has async_fn/fn.lifetime_for_trait.html
71 // @has - '//pre[@class="rust fn"]' "pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_>"
72 pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_> {}
73 // @has async_fn/fn.elided_in_input_trait.html
74 // @has - '//pre[@class="rust fn"]' "pub async fn elided_in_input_trait(t: impl Pattern<'_>)"
75 pub async fn elided_in_input_trait(t: impl Pattern<'_>) {}
77 struct AsyncFdReadyGuard<'a, T> { x: &'a T }
80 // @has async_fn/struct.Foo.html
81 // @has - '//h4[@class="method"]' 'pub async fn complicated_lifetimes( &self, context: &impl Bar) -> impl Iterator<Item = &usize>'
82 pub async fn complicated_lifetimes(&self, context: &impl Bar) -> impl Iterator<Item = &usize> {}
83 // taken from `tokio` as an example of a method that was particularly bad before
84 // @has - '//h4[@class="method"]' "pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()>"
85 pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()> {}
86 // @has - '//h4[@class="method"]' "pub async fn mut_self(&mut self)"
87 pub async fn mut_self(&mut self) {}
90 // test named lifetimes, just in case
91 // @has async_fn/fn.named.html
92 // @has - '//pre[@class="rust fn"]' "pub async fn named<'a, 'b>(foo: &'a str) -> &'b str"
93 pub async fn named<'a, 'b>(foo: &'a str) -> &'b str {}
94 // @has async_fn/fn.named_trait.html
95 // @has - '//pre[@class="rust fn"]' "pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b>"
96 pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b> {}