diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2023-07-22 12:20:17 +0200 |
|---|---|---|
| committer | León Orell Valerian Liehr <me@fmease.dev> | 2023-07-22 12:20:17 +0200 |
| commit | 5924043b868e31623f50a86d6eb41d10ac8e5173 (patch) | |
| tree | a67126e4b32479d1e0952c205b352ebcb1adc219 /tests | |
| parent | c3c5a5c5f7a0cf9acdfe60440a1e1fa68a1c1278 (diff) | |
| download | rust-5924043b868e31623f50a86d6eb41d10ac8e5173.tar.gz rust-5924043b868e31623f50a86d6eb41d10ac8e5173.zip | |
rustdoc: handle cross-crate RPITITs correctly
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rustdoc/inline_cross/auxiliary/ret-pos-impl-trait-in-trait.rs | 35 | ||||
| -rw-r--r-- | tests/rustdoc/inline_cross/ret-pos-impl-trait-in-trait.rs | 35 |
2 files changed, 70 insertions, 0 deletions
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 00000000000..c72f011152d --- /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/ret-pos-impl-trait-in-trait.rs b/tests/rustdoc/inline_cross/ret-pos-impl-trait-in-trait.rs new file mode 100644 index 00000000000..8e9ef902015 --- /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; |
