diff options
Diffstat (limited to 'tests/rustdoc/async')
| -rw-r--r-- | tests/rustdoc/async/async-fn-opaque-item.rs | 15 | ||||
| -rw-r--r-- | tests/rustdoc/async/async-fn.rs | 99 | ||||
| -rw-r--r-- | tests/rustdoc/async/async-move-doctest.rs | 12 | ||||
| -rw-r--r-- | tests/rustdoc/async/async-trait-sig.rs | 13 | ||||
| -rw-r--r-- | tests/rustdoc/async/async-trait.rs | 15 | ||||
| -rw-r--r-- | tests/rustdoc/async/auxiliary/async-trait-dep.rs | 8 |
6 files changed, 162 insertions, 0 deletions
diff --git a/tests/rustdoc/async/async-fn-opaque-item.rs b/tests/rustdoc/async/async-fn-opaque-item.rs new file mode 100644 index 00000000000..d45183f96dd --- /dev/null +++ b/tests/rustdoc/async/async-fn-opaque-item.rs @@ -0,0 +1,15 @@ +//@ compile-flags: --document-private-items --crate-type=lib +//@ edition: 2021 + +// Issue 109931 -- test against accidentally documenting the `impl Future` +// that comes from an async fn desugaring. + +// Check that we don't document an unnamed opaque type +//@ !has async_fn_opaque_item/opaque..html + +// Checking there is only a "Functions" header and no "Opaque types". +//@ has async_fn_opaque_item/index.html +//@ count - '//*[@class="section-header"]' 1 +//@ has - '//*[@class="section-header"]' 'Functions' + +pub async fn test() {} diff --git a/tests/rustdoc/async/async-fn.rs b/tests/rustdoc/async/async-fn.rs new file mode 100644 index 00000000000..3d49766c55e --- /dev/null +++ b/tests/rustdoc/async/async-fn.rs @@ -0,0 +1,99 @@ +//@ edition:2018 +//@ has async_fn/fn.foo.html '//pre[@class="rust item-decl"]' 'pub async fn foo() -> Option<Foo>' +pub async fn foo() -> Option<Foo> { + None +} + +//@ has async_fn/fn.bar.html '//pre[@class="rust item-decl"]' 'pub async fn bar(a: i32, b: i32) -> i32' +pub async fn bar(a: i32, b: i32) -> i32 { + 0 +} + +//@ has async_fn/fn.baz.html '//pre[@class="rust item-decl"]' 'pub async fn baz<T>(a: T) -> T' +pub async fn baz<T>(a: T) -> T { + a +} + +//@ has async_fn/fn.qux.html '//pre[@class="rust item-decl"]' 'pub async unsafe fn qux() -> char' +pub async unsafe fn qux() -> char { + '⚠' +} + +//@ has async_fn/fn.mut_args.html '//pre[@class="rust item-decl"]' 'pub async fn mut_args(a: usize)' +pub async fn mut_args(mut a: usize) {} + +//@ has async_fn/fn.mut_ref.html '//pre[@class="rust item-decl"]' 'pub async fn mut_ref(x: i32)' +pub async fn mut_ref(ref mut x: i32) {} + +trait Bar {} + +impl Bar for () {} + +//@ has async_fn/fn.quux.html '//pre[@class="rust item-decl"]' 'pub async fn quux() -> impl Bar' +pub async fn quux() -> impl Bar { + () +} + +//@ has async_fn/struct.Foo.html +//@ 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\)$' +pub struct Foo; + +impl Foo { + pub async fn f() {} + pub async unsafe fn g() {} + pub async fn mut_self(mut self, mut first: usize) {} +} + +pub trait Pattern<'a> {} + +impl Pattern<'_> for () {} + +pub trait Trait<const N: usize> {} +//@ has async_fn/fn.const_generics.html +//@ has - '//pre[@class="rust item-decl"]' 'pub async fn const_generics<const N: usize>(_: impl Trait<N>)' +pub async fn const_generics<const N: usize>(_: impl Trait<N>) {} + +// test that elided lifetimes are properly elided and not displayed as `'_` +// regression test for #63037 +//@ has async_fn/fn.elided.html +//@ has - '//pre[@class="rust item-decl"]' 'pub async fn elided(foo: &str) -> &str' +pub async fn elided(foo: &str) -> &str { "" } +// This should really be shown as written, but for implementation reasons it's difficult. +// See `impl Clean for TyKind::Ref`. +//@ has async_fn/fn.user_elided.html +//@ has - '//pre[@class="rust item-decl"]' 'pub async fn user_elided(foo: &str) -> &str' +pub async fn user_elided(foo: &'_ str) -> &str { "" } +//@ has async_fn/fn.static_trait.html +//@ has - '//pre[@class="rust item-decl"]' 'pub async fn static_trait(foo: &str) -> Box<dyn Bar>' +pub async fn static_trait(foo: &str) -> Box<dyn Bar> { Box::new(()) } +//@ has async_fn/fn.lifetime_for_trait.html +//@ has - '//pre[@class="rust item-decl"]' "pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_>" +pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_> { Box::new(()) } +//@ has async_fn/fn.elided_in_input_trait.html +//@ has - '//pre[@class="rust item-decl"]' "pub async fn elided_in_input_trait(t: impl Pattern<'_>)" +pub async fn elided_in_input_trait(t: impl Pattern<'_>) {} + +struct AsyncFdReadyGuard<'a, T> { x: &'a T } + +impl Foo { + //@ has async_fn/struct.Foo.html + //@ has - '//*[@class="method"]' 'pub async fn complicated_lifetimes( &self, context: &impl Bar, ) -> impl Iterator<Item = &usize>' + pub async fn complicated_lifetimes(&self, context: &impl Bar) -> impl Iterator<Item = &usize> { + [0].iter() + } + // taken from `tokio` as an example of a method that was particularly bad before + //@ has - '//*[@class="method"]' "pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()>" + pub async fn readable<T>(&self) -> Result<AsyncFdReadyGuard<'_, T>, ()> { Err(()) } + //@ has - '//*[@class="method"]' "pub async fn mut_self(&mut self)" + pub async fn mut_self(&mut self) {} +} + +// test named lifetimes, just in case +//@ has async_fn/fn.named.html +//@ has - '//pre[@class="rust item-decl"]' "pub async fn named<'a, 'b>(foo: &'a str) -> &'b str" +pub async fn named<'a, 'b>(foo: &'a str) -> &'b str { "" } +//@ has async_fn/fn.named_trait.html +//@ has - '//pre[@class="rust item-decl"]' "pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b>" +pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b> {} diff --git a/tests/rustdoc/async/async-move-doctest.rs b/tests/rustdoc/async/async-move-doctest.rs new file mode 100644 index 00000000000..e18ec353533 --- /dev/null +++ b/tests/rustdoc/async/async-move-doctest.rs @@ -0,0 +1,12 @@ +//@ compile-flags:--test +//@ edition:2018 + +// Prior to setting the default edition for the doctest pre-parser, +// this doctest would fail due to a fatal parsing error. +// see https://github.com/rust-lang/rust/issues/59313 + +//! ``` +//! fn foo() { +//! drop(async move {}); +//! } +//! ``` diff --git a/tests/rustdoc/async/async-trait-sig.rs b/tests/rustdoc/async/async-trait-sig.rs new file mode 100644 index 00000000000..be790f6ed7f --- /dev/null +++ b/tests/rustdoc/async/async-trait-sig.rs @@ -0,0 +1,13 @@ +//@ edition:2021 + +#![allow(incomplete_features)] + +pub trait Foo { + //@ has async_trait_sig/trait.Foo.html '//h4[@class="code-header"]' "async fn bar() -> i32" + async fn bar() -> i32; + + //@ has async_trait_sig/trait.Foo.html '//h4[@class="code-header"]' "async fn baz() -> i32" + async fn baz() -> i32 { + 1 + } +} diff --git a/tests/rustdoc/async/async-trait.rs b/tests/rustdoc/async/async-trait.rs new file mode 100644 index 00000000000..a6ee340e2dd --- /dev/null +++ b/tests/rustdoc/async/async-trait.rs @@ -0,0 +1,15 @@ +//@ aux-build:async-trait-dep.rs +//@ edition:2021 + +#![allow(incomplete_features)] + +extern crate async_trait_dep; + +pub struct Oink {} + +//@ has 'async_trait/struct.Oink.html' '//h4[@class="code-header"]' "async fn woof()" +impl async_trait_dep::Meow for Oink { + async fn woof() { + todo!() + } +} diff --git a/tests/rustdoc/async/auxiliary/async-trait-dep.rs b/tests/rustdoc/async/auxiliary/async-trait-dep.rs new file mode 100644 index 00000000000..d89ec6d2998 --- /dev/null +++ b/tests/rustdoc/async/auxiliary/async-trait-dep.rs @@ -0,0 +1,8 @@ +//@ edition:2021 + +#![allow(incomplete_features)] + +pub trait Meow { + /// Who's a good dog? + async fn woof(); +} |
