Skip to content

Commit 0933f48

Browse files
Add regression test for #119015 and update tests
1 parent 6237beb commit 0933f48

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

tests/rustdoc/async-fn.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ impl Foo {
4848

4949
pub trait Pattern<'a> {}
5050

51+
impl Pattern<'_> for () {}
52+
5153
pub trait Trait<const N: usize> {}
5254
// @has async_fn/fn.const_generics.html
5355
// @has - '//pre[@class="rust item-decl"]' 'pub async fn const_generics<const N: usize>(_: impl Trait<N>)'
@@ -57,18 +59,18 @@ pub async fn const_generics<const N: usize>(_: impl Trait<N>) {}
5759
// regression test for #63037
5860
// @has async_fn/fn.elided.html
5961
// @has - '//pre[@class="rust item-decl"]' 'pub async fn elided(foo: &str) -> &str'
60-
pub async fn elided(foo: &str) -> &str {}
62+
pub async fn elided(foo: &str) -> &str { "" }
6163
// This should really be shown as written, but for implementation reasons it's difficult.
6264
// See `impl Clean for TyKind::Ref`.
6365
// @has async_fn/fn.user_elided.html
6466
// @has - '//pre[@class="rust item-decl"]' 'pub async fn user_elided(foo: &str) -> &str'
65-
pub async fn user_elided(foo: &'_ str) -> &str {}
67+
pub async fn user_elided(foo: &'_ str) -> &str { "" }
6668
// @has async_fn/fn.static_trait.html
6769
// @has - '//pre[@class="rust item-decl"]' 'pub async fn static_trait(foo: &str) -> Box<dyn Bar>'
68-
pub async fn static_trait(foo: &str) -> Box<dyn Bar> {}
70+
pub async fn static_trait(foo: &str) -> Box<dyn Bar> { Box::new(()) }
6971
// @has async_fn/fn.lifetime_for_trait.html
7072
// @has - '//pre[@class="rust item-decl"]' "pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_>"
71-
pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_> {}
73+
pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_> { Box::new(()) }
7274
// @has async_fn/fn.elided_in_input_trait.html
7375
// @has - '//pre[@class="rust item-decl"]' "pub async fn elided_in_input_trait(t: impl Pattern<'_>)"
7476
pub async fn elided_in_input_trait(t: impl Pattern<'_>) {}
@@ -78,18 +80,20 @@ struct AsyncFdReadyGuard<'a, T> { x: &'a T }
7880
impl Foo {
7981
// @has async_fn/struct.Foo.html
8082
// @has - '//*[@class="method"]' '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> {}
83+
pub async fn complicated_lifetimes(&self, context: &impl Bar) -> impl Iterator<Item = &usize> {
84+
[0].iter()
85+
}
8286
// taken from `tokio` as an example of a method that was particularly bad before
8387
// @has - '//*[@class="method"]' "pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()>"
84-
pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()> {}
88+
pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()> { Err(()) }
8589
// @has - '//*[@class="method"]' "pub async fn mut_self(&mut self)"
8690
pub async fn mut_self(&mut self) {}
8791
}
8892

8993
// test named lifetimes, just in case
9094
// @has async_fn/fn.named.html
9195
// @has - '//pre[@class="rust item-decl"]' "pub async fn named<'a, 'b>(foo: &'a str) -> &'b str"
92-
pub async fn named<'a, 'b>(foo: &'a str) -> &'b str {}
96+
pub async fn named<'a, 'b>(foo: &'a str) -> &'b str { "" }
9397
// @has async_fn/fn.named_trait.html
9498
// @has - '//pre[@class="rust item-decl"]' "pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b>"
9599
pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![crate_name = "foo"]
2+
3+
// @has 'foo/index.html'
4+
// There should be only `type A`.
5+
// @count - '//*[@class="item-table"]//*[@class="item-name"]' 1
6+
// @has - '//*[@class="item-name"]/a[@href="type.A.html"]' 'A'
7+
8+
mod foo {
9+
pub struct S;
10+
}
11+
12+
use foo::S;
13+
14+
pub type A = S;
15+
16+
// @has 'foo/type.A.html'
17+
// @has - '//*[@id="method.default"]/h4' 'fn default() -> Self'
18+
impl Default for A {
19+
fn default() -> Self {
20+
S
21+
}
22+
}
23+
24+
// @has - '//*[@id="method.a"]/h4' 'pub fn a(&self)'
25+
impl A {
26+
pub fn a(&self) {}
27+
}

0 commit comments

Comments
 (0)