summaryrefslogtreecommitdiffstats
path: root/tests/rustdoc/inline_cross
diff options
context:
space:
mode:
Diffstat (limited to 'tests/rustdoc/inline_cross')
-rw-r--r--tests/rustdoc/inline_cross/auxiliary/generic-const-items.rs22
-rw-r--r--tests/rustdoc/inline_cross/auxiliary/impl-sized.rs21
-rw-r--r--tests/rustdoc/inline_cross/auxiliary/ret-pos-impl-trait-in-trait.rs35
-rw-r--r--tests/rustdoc/inline_cross/generic-const-items.rs26
-rw-r--r--tests/rustdoc/inline_cross/impl-sized.rs27
-rw-r--r--tests/rustdoc/inline_cross/ret-pos-impl-trait-in-trait.rs35
6 files changed, 166 insertions, 0 deletions
diff --git a/tests/rustdoc/inline_cross/auxiliary/generic-const-items.rs b/tests/rustdoc/inline_cross/auxiliary/generic-const-items.rs
new file mode 100644
index 000000000..0fc7a7aae
--- /dev/null
+++ b/tests/rustdoc/inline_cross/auxiliary/generic-const-items.rs
@@ -0,0 +1,22 @@
+#![feature(generic_const_items)]
+#![allow(incomplete_features)]
+
+pub const K<'a, T: 'a + Copy, const N: usize>: Option<[T; N]> = None
+where
+ String: From<T>;
+
+pub trait Trait<T: ?Sized> {
+ const C<'a>: &'a T
+ where
+ T: 'a + Eq;
+}
+
+pub struct Implementor;
+
+impl Trait<str> for Implementor {
+ const C<'a>: &'a str = "C"
+ // In real code we could've left off this bound but adding it explicitly allows us to test if
+ // we render where-clauses on associated consts inside impl blocks correctly.
+ where
+ str: 'a;
+}
diff --git a/tests/rustdoc/inline_cross/auxiliary/impl-sized.rs b/tests/rustdoc/inline_cross/auxiliary/impl-sized.rs
new file mode 100644
index 000000000..65f72a3b9
--- /dev/null
+++ b/tests/rustdoc/inline_cross/auxiliary/impl-sized.rs
@@ -0,0 +1,21 @@
+use std::fmt::Debug;
+
+pub fn sized(x: impl Sized) -> impl Sized {
+ x
+}
+
+pub fn sized_outlives<'a>(x: impl Sized + 'a) -> impl Sized + 'a {
+ x
+}
+
+pub fn maybe_sized(x: &impl ?Sized) -> &impl ?Sized {
+ x
+}
+
+pub fn debug_maybe_sized(x: &(impl Debug + ?Sized)) -> &(impl Debug + ?Sized) {
+ x
+}
+
+pub fn maybe_sized_outlives<'t>(x: &(impl ?Sized + 't)) -> &(impl ?Sized + 't) {
+ x
+}
diff --git a/tests/rustdoc/inline_cross/auxiliary/ret-pos-impl-trait-in-trait.rs b/tests/rustdoc/inline_cross/auxiliary/ret-pos-impl-trait-in-trait.rs
new file mode 100644
index 000000000..c72f01115
--- /dev/null
+++ b/tests/rustdoc/inline_cross/auxiliary/ret-pos-impl-trait-in-trait.rs
@@ -0,0 +1,35 @@
+#![feature(return_position_impl_trait_in_trait)]
+
+pub trait Trait {
+ fn create() -> impl Iterator<Item = u64> {
+ std::iter::empty()
+ }
+}
+
+pub struct Basic;
+pub struct Intermediate;
+pub struct Advanced;
+
+impl Trait for Basic {
+ // method provided by the trait
+}
+
+impl Trait for Intermediate {
+ fn create() -> std::ops::Range<u64> { // concrete return type
+ 0..1
+ }
+}
+
+impl Trait for Advanced {
+ fn create() -> impl Iterator<Item = u64> { // opaque return type
+ std::iter::repeat(0)
+ }
+}
+
+// Regression test for issue #113929:
+
+pub trait Def {
+ fn def<T>() -> impl Default {}
+}
+
+impl Def for () {}
diff --git a/tests/rustdoc/inline_cross/generic-const-items.rs b/tests/rustdoc/inline_cross/generic-const-items.rs
new file mode 100644
index 000000000..70cf7af88
--- /dev/null
+++ b/tests/rustdoc/inline_cross/generic-const-items.rs
@@ -0,0 +1,26 @@
+#![crate_name = "user"]
+
+// aux-crate:generic_const_items=generic-const-items.rs
+// edition:2021
+
+// @has 'user/constant.K.html'
+// @has - '//*[@class="rust item-decl"]//code' \
+// "pub const K<'a, T: 'a + Copy, const N: usize>: Option<[T; N]> \
+// where \
+// String: From<T>;"
+pub use generic_const_items::K;
+
+// @has user/trait.Trait.html
+// @has - '//*[@id="associatedconstant.C"]' \
+// "const C<'a>: &'a T \
+// where \
+// T: 'a + Eq"
+pub use generic_const_items::Trait;
+
+// @has user/struct.Implementor.html
+// @has - '//h3[@class="code-header"]' 'impl Trait<str> for Implementor'
+// @has - '//*[@id="associatedconstant.C"]' \
+// "const C<'a>: &'a str = \"C\" \
+// where \
+// str: 'a"
+pub use generic_const_items::Implementor;
diff --git a/tests/rustdoc/inline_cross/impl-sized.rs b/tests/rustdoc/inline_cross/impl-sized.rs
new file mode 100644
index 000000000..82bdce474
--- /dev/null
+++ b/tests/rustdoc/inline_cross/impl-sized.rs
@@ -0,0 +1,27 @@
+#![crate_name = "user"]
+
+// aux-crate:impl_sized=impl-sized.rs
+// edition:2021
+
+// @has user/fn.sized.html
+// @has - '//pre[@class="rust item-decl"]' "sized(x: impl Sized) -> impl Sized"
+pub use impl_sized::sized;
+
+// @has user/fn.sized_outlives.html
+// @has - '//pre[@class="rust item-decl"]' \
+// "sized_outlives<'a>(x: impl Sized + 'a) -> impl Sized + 'a"
+pub use impl_sized::sized_outlives;
+
+// @has user/fn.maybe_sized.html
+// @has - '//pre[@class="rust item-decl"]' "maybe_sized(x: &impl ?Sized) -> &impl ?Sized"
+pub use impl_sized::maybe_sized;
+
+// @has user/fn.debug_maybe_sized.html
+// @has - '//pre[@class="rust item-decl"]' \
+// "debug_maybe_sized(x: &(impl Debug + ?Sized)) -> &(impl Debug + ?Sized)"
+pub use impl_sized::debug_maybe_sized;
+
+// @has user/fn.maybe_sized_outlives.html
+// @has - '//pre[@class="rust item-decl"]' \
+// "maybe_sized_outlives<'t>(x: &(impl ?Sized + 't)) -> &(impl ?Sized + 't)"
+pub use impl_sized::maybe_sized_outlives;
diff --git a/tests/rustdoc/inline_cross/ret-pos-impl-trait-in-trait.rs b/tests/rustdoc/inline_cross/ret-pos-impl-trait-in-trait.rs
new file mode 100644
index 000000000..8e9ef9020
--- /dev/null
+++ b/tests/rustdoc/inline_cross/ret-pos-impl-trait-in-trait.rs
@@ -0,0 +1,35 @@
+#![crate_name = "user"]
+// aux-crate:rpitit=ret-pos-impl-trait-in-trait.rs
+// edition:2021
+
+// Test that we can correctly render cross-crate RPITITs.
+// In particular, check that we don't render the internal associated type generated by
+// their desugaring. We count the number of associated items and ensure that it is exactly one.
+// This is more robust than checking for the absence of the associated type.
+
+// @has user/trait.Trait.html
+// @has - '//*[@id="method.create"]' 'fn create() -> impl Iterator<Item = u64>'
+// The class "method" is used for all three kinds of associated items at the time of writing.
+// @count - '//*[@id="main-content"]//section[@class="method"]' 1
+pub use rpitit::Trait;
+
+// @has user/struct.Basic.html
+// @has - '//*[@id="method.create"]' 'fn create() -> impl Iterator<Item = u64>'
+// @count - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]' 1
+pub use rpitit::Basic;
+
+// @has user/struct.Intermediate.html
+// @has - '//*[@id="method.create"]' 'fn create() -> Range<u64>'
+// @count - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]' 1
+pub use rpitit::Intermediate;
+
+// @has user/struct.Advanced.html
+// @has - '//*[@id="method.create"]' 'fn create() -> impl Iterator<Item = u64>'
+// @count - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]' 1
+pub use rpitit::Advanced;
+
+// Regression test for issue #113929:
+
+// @has user/trait.Def.html
+// @has - '//*[@id="method.def"]' 'fn def<T>() -> impl Default'
+pub use rpitit::Def;