2018-08-09 11:46:39 -05:00
|
|
|
//@ edition:2018
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has async_fn/fn.foo.html '//pre[@class="rust item-decl"]' 'pub async fn foo() -> Option<Foo>'
|
2019-02-05 09:12:43 -06:00
|
|
|
pub async fn foo() -> Option<Foo> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has async_fn/fn.bar.html '//pre[@class="rust item-decl"]' 'pub async fn bar(a: i32, b: i32) -> i32'
|
2019-02-05 09:12:43 -06:00
|
|
|
pub async fn bar(a: i32, b: i32) -> i32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has async_fn/fn.baz.html '//pre[@class="rust item-decl"]' 'pub async fn baz<T>(a: T) -> T'
|
2019-02-05 09:12:43 -06:00
|
|
|
pub async fn baz<T>(a: T) -> T {
|
|
|
|
a
|
|
|
|
}
|
|
|
|
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has async_fn/fn.qux.html '//pre[@class="rust item-decl"]' 'pub async unsafe fn qux() -> char'
|
2020-01-20 12:14:51 -06:00
|
|
|
pub async unsafe fn qux() -> char {
|
|
|
|
'⚠'
|
|
|
|
}
|
|
|
|
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has async_fn/fn.mut_args.html '//pre[@class="rust item-decl"]' 'pub async fn mut_args(a: usize)'
|
2020-11-08 10:45:13 -06:00
|
|
|
pub async fn mut_args(mut a: usize) {}
|
|
|
|
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has async_fn/fn.mut_ref.html '//pre[@class="rust item-decl"]' 'pub async fn mut_ref(x: i32)'
|
2020-11-08 10:45:13 -06:00
|
|
|
pub async fn mut_ref(ref mut x: i32) {}
|
|
|
|
|
2019-02-05 09:12:43 -06:00
|
|
|
trait Bar {}
|
|
|
|
|
|
|
|
impl Bar for () {}
|
|
|
|
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has async_fn/fn.quux.html '//pre[@class="rust item-decl"]' 'pub async fn quux() -> impl Bar'
|
2019-02-05 09:12:43 -06:00
|
|
|
pub async fn quux() -> impl Bar {
|
|
|
|
()
|
|
|
|
}
|
|
|
|
|
|
|
|
// @has async_fn/struct.Foo.html
|
2021-07-25 16:41:57 -05:00
|
|
|
// @matches - '//h4[@class="code-header"]' 'pub async fn f\(\)$'
|
|
|
|
// @matches - '//h4[@class="code-header"]' 'pub async unsafe fn g\(\)$'
|
|
|
|
// @matches - '//h4[@class="code-header"]' 'pub async fn mut_self\(self, first: usize\)$'
|
2019-02-05 09:12:43 -06:00
|
|
|
pub struct Foo;
|
2018-08-09 11:46:39 -05:00
|
|
|
|
2019-02-05 09:12:43 -06:00
|
|
|
impl Foo {
|
2018-08-09 11:46:39 -05:00
|
|
|
pub async fn f() {}
|
2020-01-20 12:14:51 -06:00
|
|
|
pub async unsafe fn g() {}
|
2020-11-08 10:45:13 -06:00
|
|
|
pub async fn mut_self(mut self, mut first: usize) {}
|
2018-08-09 11:46:39 -05:00
|
|
|
}
|
2020-11-10 06:49:06 -06:00
|
|
|
|
2020-12-22 20:26:17 -06:00
|
|
|
pub trait Pattern<'a> {}
|
|
|
|
|
2024-01-15 09:47:14 -06:00
|
|
|
impl Pattern<'_> for () {}
|
|
|
|
|
2020-11-10 06:49:06 -06:00
|
|
|
pub trait Trait<const N: usize> {}
|
|
|
|
// @has async_fn/fn.const_generics.html
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has - '//pre[@class="rust item-decl"]' 'pub async fn const_generics<const N: usize>(_: impl Trait<N>)'
|
2020-11-10 06:49:06 -06:00
|
|
|
pub async fn const_generics<const N: usize>(_: impl Trait<N>) {}
|
2020-12-22 19:22:47 -06:00
|
|
|
|
|
|
|
// test that elided lifetimes are properly elided and not displayed as `'_`
|
|
|
|
// regression test for #63037
|
|
|
|
// @has async_fn/fn.elided.html
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has - '//pre[@class="rust item-decl"]' 'pub async fn elided(foo: &str) -> &str'
|
2024-01-15 09:47:14 -06:00
|
|
|
pub async fn elided(foo: &str) -> &str { "" }
|
2020-12-22 19:22:47 -06:00
|
|
|
// This should really be shown as written, but for implementation reasons it's difficult.
|
2022-12-28 11:06:11 -06:00
|
|
|
// See `impl Clean for TyKind::Ref`.
|
2020-12-22 19:22:47 -06:00
|
|
|
// @has async_fn/fn.user_elided.html
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has - '//pre[@class="rust item-decl"]' 'pub async fn user_elided(foo: &str) -> &str'
|
2024-01-15 09:47:14 -06:00
|
|
|
pub async fn user_elided(foo: &'_ str) -> &str { "" }
|
2020-12-22 19:22:47 -06:00
|
|
|
// @has async_fn/fn.static_trait.html
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has - '//pre[@class="rust item-decl"]' 'pub async fn static_trait(foo: &str) -> Box<dyn Bar>'
|
2024-01-15 09:47:14 -06:00
|
|
|
pub async fn static_trait(foo: &str) -> Box<dyn Bar> { Box::new(()) }
|
2020-12-22 19:22:47 -06:00
|
|
|
// @has async_fn/fn.lifetime_for_trait.html
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has - '//pre[@class="rust item-decl"]' "pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_>"
|
2024-01-15 09:47:14 -06:00
|
|
|
pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_> { Box::new(()) }
|
2020-12-22 20:26:17 -06:00
|
|
|
// @has async_fn/fn.elided_in_input_trait.html
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has - '//pre[@class="rust item-decl"]' "pub async fn elided_in_input_trait(t: impl Pattern<'_>)"
|
2020-12-22 20:26:17 -06:00
|
|
|
pub async fn elided_in_input_trait(t: impl Pattern<'_>) {}
|
2020-12-22 19:22:47 -06:00
|
|
|
|
|
|
|
struct AsyncFdReadyGuard<'a, T> { x: &'a T }
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
// @has async_fn/struct.Foo.html
|
2024-06-04 06:49:39 -05:00
|
|
|
// @has - '//*[@class="method"]' 'pub async fn complicated_lifetimes( &self, context: &impl Bar, ) -> impl Iterator<Item = &usize>'
|
2024-01-15 09:47:14 -06:00
|
|
|
pub async fn complicated_lifetimes(&self, context: &impl Bar) -> impl Iterator<Item = &usize> {
|
|
|
|
[0].iter()
|
|
|
|
}
|
2020-12-22 19:22:47 -06:00
|
|
|
// taken from `tokio` as an example of a method that was particularly bad before
|
2023-01-28 17:35:02 -06:00
|
|
|
// @has - '//*[@class="method"]' "pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()>"
|
2024-01-15 09:47:14 -06:00
|
|
|
pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()> { Err(()) }
|
2023-01-28 17:35:02 -06:00
|
|
|
// @has - '//*[@class="method"]' "pub async fn mut_self(&mut self)"
|
2020-12-22 20:26:17 -06:00
|
|
|
pub async fn mut_self(&mut self) {}
|
2020-12-22 19:22:47 -06:00
|
|
|
}
|
2020-12-22 20:26:17 -06:00
|
|
|
|
|
|
|
// test named lifetimes, just in case
|
|
|
|
// @has async_fn/fn.named.html
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has - '//pre[@class="rust item-decl"]' "pub async fn named<'a, 'b>(foo: &'a str) -> &'b str"
|
2024-01-15 09:47:14 -06:00
|
|
|
pub async fn named<'a, 'b>(foo: &'a str) -> &'b str { "" }
|
2020-12-22 20:26:17 -06:00
|
|
|
// @has async_fn/fn.named_trait.html
|
2023-01-30 12:05:12 -06:00
|
|
|
// @has - '//pre[@class="rust item-decl"]' "pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b>"
|
2020-12-22 20:26:17 -06:00
|
|
|
pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b> {}
|