diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-05-05 15:50:06 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-05-05 17:47:18 +0200 |
| commit | b374996ab8d3d8a10fdf1ffcf2b1c3de3fdbbf64 (patch) | |
| tree | 7f243a4077047a4c33b3e7d1877746eade25c3b4 /tests/rustdoc/anchors | |
| parent | 099f730dcf95404e3f272cb2690a25077b9f2a4b (diff) | |
| download | rust-b374996ab8d3d8a10fdf1ffcf2b1c3de3fdbbf64.tar.gz rust-b374996ab8d3d8a10fdf1ffcf2b1c3de3fdbbf64.zip | |
Created `tests/rustdoc/anchors` subfolder to limit number of files at the top level
Diffstat (limited to 'tests/rustdoc/anchors')
17 files changed, 279 insertions, 0 deletions
diff --git a/tests/rustdoc/anchors/anchor-id-duplicate-method-name-25001.rs b/tests/rustdoc/anchors/anchor-id-duplicate-method-name-25001.rs new file mode 100644 index 00000000000..d7f4e587d5e --- /dev/null +++ b/tests/rustdoc/anchors/anchor-id-duplicate-method-name-25001.rs @@ -0,0 +1,46 @@ +// https://github.com/rust-lang/rust/issues/25001 +#![crate_name="issue_25001"] + +//@ has issue_25001/struct.Foo.html +pub struct Foo<T>(T); + +pub trait Bar { + type Item; + + fn quux(self); +} + +impl Foo<u8> { + //@ has - '//*[@id="method.pass"]//h4[@class="code-header"]' 'fn pass()' + pub fn pass() {} +} +impl Foo<u16> { + //@ has - '//*[@id="method.pass-1"]//h4[@class="code-header"]' 'fn pass() -> usize' + pub fn pass() -> usize { 42 } +} +impl Foo<u32> { + //@ has - '//*[@id="method.pass-2"]//h4[@class="code-header"]' 'fn pass() -> isize' + pub fn pass() -> isize { 42 } +} + +impl<T> Bar for Foo<T> { + //@ has - '//*[@id="associatedtype.Item"]//h4[@class="code-header"]' 'type Item = T' + type Item=T; + + //@ has - '//*[@id="method.quux"]//h4[@class="code-header"]' 'fn quux(self)' + fn quux(self) {} +} +impl<'a, T> Bar for &'a Foo<T> { + //@ has - '//*[@id="associatedtype.Item-1"]//h4[@class="code-header"]' "type Item = &'a T" + type Item=&'a T; + + //@ has - '//*[@id="method.quux-1"]//h4[@class="code-header"]' 'fn quux(self)' + fn quux(self) {} +} +impl<'a, T> Bar for &'a mut Foo<T> { + //@ has - '//*[@id="associatedtype.Item-2"]//h4[@class="code-header"]' "type Item = &'a mut T" + type Item=&'a mut T; + + //@ has - '//*[@id="method.quux-2"]//h4[@class="code-header"]' 'fn quux(self)' + fn quux(self) {} +} diff --git a/tests/rustdoc/anchors/anchor-id-trait-method-15169.rs b/tests/rustdoc/anchors/anchor-id-trait-method-15169.rs new file mode 100644 index 00000000000..19eeeaee9d1 --- /dev/null +++ b/tests/rustdoc/anchors/anchor-id-trait-method-15169.rs @@ -0,0 +1,7 @@ +//@ has issue_15169/struct.Foo.html '//*[@id="method.eq"]' 'fn eq' + +// https://github.com/rust-lang/rust/issues/15169 +#![crate_name="issue_15169"] + +#[derive(PartialEq)] +pub struct Foo; diff --git a/tests/rustdoc/anchors/anchor-id-trait-tymethod-28478.rs b/tests/rustdoc/anchors/anchor-id-trait-tymethod-28478.rs new file mode 100644 index 00000000000..e7adba7d06e --- /dev/null +++ b/tests/rustdoc/anchors/anchor-id-trait-tymethod-28478.rs @@ -0,0 +1,34 @@ +// https://github.com/rust-lang/rust/issues/28478 +#![crate_name="issue_28478"] + +#![feature(associated_type_defaults)] + +//@ has issue_28478/trait.Bar.html +pub trait Bar { + //@ has - '//*[@id="associatedtype.Bar"]' 'type Bar = ()' + //@ has - '//*[@href="#associatedtype.Bar"]' 'Bar' + type Bar = (); + //@ has - '//*[@id="associatedconstant.Baz"]' 'const Baz: usize' + //@ has - '//*[@href="#associatedconstant.Baz"]' 'Baz' + const Baz: usize = 7; + //@ has - '//*[@id="tymethod.bar"]' 'fn bar' + fn bar(); + //@ has - '//*[@id="method.baz"]' 'fn baz' + fn baz() { } +} + +//@ has issue_28478/struct.Foo.html +pub struct Foo; + +impl Foo { + //@ has - '//*[@href="#method.foo"]' 'foo' + pub fn foo() {} +} + +impl Bar for Foo { + //@ has - '//*[@href="trait.Bar.html#associatedtype.Bar"]' 'Bar' + //@ has - '//*[@href="trait.Bar.html#associatedconstant.Baz"]' 'Baz' + //@ has - '//*[@href="trait.Bar.html#tymethod.bar"]' 'bar' + fn bar() {} + //@ has - '//*[@href="trait.Bar.html#method.baz"]' 'baz' +} diff --git a/tests/rustdoc/anchors/anchors.no_const_anchor.html b/tests/rustdoc/anchors/anchors.no_const_anchor.html new file mode 100644 index 00000000000..07a7507fa2e --- /dev/null +++ b/tests/rustdoc/anchors/anchors.no_const_anchor.html @@ -0,0 +1 @@ +<section id="associatedconstant.YOLO" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#16">Source</a><h4 class="code-header">const <a href="#associatedconstant.YOLO" class="constant">YOLO</a>: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section> \ No newline at end of file diff --git a/tests/rustdoc/anchors/anchors.no_const_anchor2.html b/tests/rustdoc/anchors/anchors.no_const_anchor2.html new file mode 100644 index 00000000000..091dac3e4b2 --- /dev/null +++ b/tests/rustdoc/anchors/anchors.no_const_anchor2.html @@ -0,0 +1 @@ +<section id="associatedconstant.X" class="associatedconstant"><a class="src rightside" href="../src/foo/anchors.rs.html#42">Source</a><h4 class="code-header">pub const <a href="#associatedconstant.X" class="constant">X</a>: <a class="primitive" href="{{channel}}/std/primitive.i32.html">i32</a> = 0i32</h4></section> \ No newline at end of file diff --git a/tests/rustdoc/anchors/anchors.no_method_anchor.html b/tests/rustdoc/anchors/anchors.no_method_anchor.html new file mode 100644 index 00000000000..89f9898624c --- /dev/null +++ b/tests/rustdoc/anchors/anchors.no_method_anchor.html @@ -0,0 +1 @@ +<section id="method.new" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#48">Source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -> Self</h4></section> \ No newline at end of file diff --git a/tests/rustdoc/anchors/anchors.no_trait_method_anchor.html b/tests/rustdoc/anchors/anchors.no_trait_method_anchor.html new file mode 100644 index 00000000000..51656a3e58f --- /dev/null +++ b/tests/rustdoc/anchors/anchors.no_trait_method_anchor.html @@ -0,0 +1 @@ +<section id="method.bar" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#23">Source</a><h4 class="code-header">fn <a href="#method.bar" class="fn">bar</a>()</h4></section> \ No newline at end of file diff --git a/tests/rustdoc/anchors/anchors.no_tymethod_anchor.html b/tests/rustdoc/anchors/anchors.no_tymethod_anchor.html new file mode 100644 index 00000000000..49ee624bdbc --- /dev/null +++ b/tests/rustdoc/anchors/anchors.no_tymethod_anchor.html @@ -0,0 +1 @@ +<section id="tymethod.foo" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#20">Source</a><h4 class="code-header">fn <a href="#tymethod.foo" class="fn">foo</a>()</h4></section> \ No newline at end of file diff --git a/tests/rustdoc/anchors/anchors.no_type_anchor.html b/tests/rustdoc/anchors/anchors.no_type_anchor.html new file mode 100644 index 00000000000..c5ac3c93818 --- /dev/null +++ b/tests/rustdoc/anchors/anchors.no_type_anchor.html @@ -0,0 +1 @@ +<section id="associatedtype.T" class="method"><a class="src rightside" href="../src/foo/anchors.rs.html#13">Source</a><h4 class="code-header">type <a href="#associatedtype.T" class="associatedtype">T</a></h4></section> \ No newline at end of file diff --git a/tests/rustdoc/anchors/anchors.no_type_anchor2.html b/tests/rustdoc/anchors/anchors.no_type_anchor2.html new file mode 100644 index 00000000000..14dd31d87b6 --- /dev/null +++ b/tests/rustdoc/anchors/anchors.no_type_anchor2.html @@ -0,0 +1 @@ +<section id="associatedtype.Y" class="associatedtype"><a class="src rightside" href="../src/foo/anchors.rs.html#45">Source</a><h4 class="code-header">pub type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section> \ No newline at end of file diff --git a/tests/rustdoc/anchors/anchors.rs b/tests/rustdoc/anchors/anchors.rs new file mode 100644 index 00000000000..255ef87351c --- /dev/null +++ b/tests/rustdoc/anchors/anchors.rs @@ -0,0 +1,49 @@ +// This test ensures that anchors are generated in the right places. + +#![feature(inherent_associated_types)] +#![allow(incomplete_features)] +#![crate_name = "foo"] + +pub struct Foo; + +//@ has 'foo/trait.Bar.html' +pub trait Bar { + // There should be no anchors here. + //@ snapshot no_type_anchor - '//*[@id="associatedtype.T"]' + type T; + // There should be no anchors here. + //@ snapshot no_const_anchor - '//*[@id="associatedconstant.YOLO"]' + const YOLO: u32; + + // There should be no anchors here. + //@ snapshot no_tymethod_anchor - '//*[@id="tymethod.foo"]' + fn foo(); + // There should be no anchors here. + //@ snapshot no_trait_method_anchor - '//*[@id="method.bar"]' + fn bar() {} +} + +//@ has 'foo/struct.Foo.html' +impl Bar for Foo { + //@ has - '//*[@id="associatedtype.T"]/a[@class="anchor"]' '' + type T = u32; + //@ has - '//*[@id="associatedconstant.YOLO"]/a[@class="anchor"]' '' + const YOLO: u32 = 0; + + //@ has - '//*[@id="method.foo"]/a[@class="anchor"]' '' + fn foo() {} + // Same check for provided "bar" method. + //@ has - '//*[@id="method.bar"]/a[@class="anchor"]' '' +} + +impl Foo { + //@ snapshot no_const_anchor2 - '//*[@id="associatedconstant.X"]' + // There should be no anchors here. + pub const X: i32 = 0; + //@ snapshot no_type_anchor2 - '//*[@id="associatedtype.Y"]' + // There should be no anchors here. + pub type Y = u32; + //@ snapshot no_method_anchor - '//*[@id="method.new"]' + // There should be no anchors here. + pub fn new() -> Self { Self } +} diff --git a/tests/rustdoc/anchors/auxiliary/issue-86620-1.rs b/tests/rustdoc/anchors/auxiliary/issue-86620-1.rs new file mode 100644 index 00000000000..f6debf6fb4e --- /dev/null +++ b/tests/rustdoc/anchors/auxiliary/issue-86620-1.rs @@ -0,0 +1,11 @@ +#![crate_name = "issue_86620_1"] + +pub trait VZip { + fn vzip() -> usize; +} + +impl<T> VZip for T { + fn vzip() -> usize { + 0 + } +} diff --git a/tests/rustdoc/anchors/disambiguate-anchors-32890.rs b/tests/rustdoc/anchors/disambiguate-anchors-32890.rs new file mode 100644 index 00000000000..0b726d5fba4 --- /dev/null +++ b/tests/rustdoc/anchors/disambiguate-anchors-32890.rs @@ -0,0 +1,20 @@ +// https://github.com/rust-lang/rust/issues/32890 +#![crate_name="issue_32890"] + +//@ has issue_32890/struct.Foo.html +pub struct Foo<T>(T); + +impl Foo<u8> { + //@ has - '//a[@href="#method.pass"]' 'pass' + pub fn pass() {} +} + +impl Foo<u16> { + //@ has - '//a[@href="#method.pass-1"]' 'pass' + pub fn pass() {} +} + +impl Foo<u32> { + //@ has - '//a[@href="#method.pass-2"]' 'pass' + pub fn pass() {} +} diff --git a/tests/rustdoc/anchors/disambiguate-anchors-header-29449.rs b/tests/rustdoc/anchors/disambiguate-anchors-header-29449.rs new file mode 100644 index 00000000000..feb0632775e --- /dev/null +++ b/tests/rustdoc/anchors/disambiguate-anchors-header-29449.rs @@ -0,0 +1,28 @@ +// https://github.com/rust-lang/rust/issues/29449 +#![crate_name="issue_29449"] + +//@ has issue_29449/struct.Foo.html +pub struct Foo; + +impl Foo { + //@ has - '//*[@id="examples"]' 'Examples' + //@ has - '//*[@id="examples"]/a[@href="#examples"]' '§' + //@ has - '//*[@id="panics"]' 'Panics' + //@ has - '//*[@id="panics"]/a[@href="#panics"]' '§' + /// # Examples + /// # Panics + pub fn bar() {} + + //@ has - '//*[@id="examples-1"]' 'Examples' + //@ has - '//*[@id="examples-1"]/a[@href="#examples-1"]' '§' + /// # Examples + pub fn bar_1() {} + + //@ has - '//*[@id="examples-2"]' 'Examples' + //@ has - '//*[@id="examples-2"]/a[@href="#examples-2"]' '§' + //@ has - '//*[@id="panics-1"]' 'Panics' + //@ has - '//*[@id="panics-1"]/a[@href="#panics-1"]' '§' + /// # Examples + /// # Panics + pub fn bar_2() {} +} diff --git a/tests/rustdoc/anchors/extern-default-method.no_href_on_anchor.html b/tests/rustdoc/anchors/extern-default-method.no_href_on_anchor.html new file mode 100644 index 00000000000..ef14836ccb8 --- /dev/null +++ b/tests/rustdoc/anchors/extern-default-method.no_href_on_anchor.html @@ -0,0 +1 @@ +<a class="fn">provided</a>(&self) \ No newline at end of file diff --git a/tests/rustdoc/anchors/method-anchor-in-blanket-impl-86620.rs b/tests/rustdoc/anchors/method-anchor-in-blanket-impl-86620.rs new file mode 100644 index 00000000000..89e8712169a --- /dev/null +++ b/tests/rustdoc/anchors/method-anchor-in-blanket-impl-86620.rs @@ -0,0 +1,11 @@ +//@ aux-build:issue-86620-1.rs +#![crate_name = "foo"] +// https://github.com/rust-lang/rust/issues/86620 + +extern crate issue_86620_1; + +use issue_86620_1::*; + +//@ !has foo/struct.S.html '//*[@id="method.vzip"]//a[@class="fnname"]/@href' #tymethod.vzip +//@ has foo/struct.S.html '//*[@id="method.vzip"]//a[@class="anchor"]/@href' #method.vzip +pub struct S; diff --git a/tests/rustdoc/anchors/trait-impl-items-links-and-anchors.rs b/tests/rustdoc/anchors/trait-impl-items-links-and-anchors.rs new file mode 100644 index 00000000000..c1845a33b9d --- /dev/null +++ b/tests/rustdoc/anchors/trait-impl-items-links-and-anchors.rs @@ -0,0 +1,65 @@ +pub trait MyTrait { + type Assoc; + const VALUE: u32 = 12; + fn trait_function(&self); + fn defaulted(&self) {} + fn defaulted_override(&self) {} +} + +impl MyTrait for String { + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedtype.Assoc-1"]//a[@class="associatedtype"]/@href' #associatedtype.Assoc + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedtype.Assoc-1"]//a[@class="anchor"]/@href' #associatedtype.Assoc-1 + type Assoc = (); + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedconstant.VALUE-1"]//a[@class="constant"]/@href' #associatedconstant.VALUE + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedconstant.VALUE-1"]//a[@class="anchor"]/@href' #associatedconstant.VALUE-1 + const VALUE: u32 = 5; + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="method.trait_function"]//a[@class="fn"]/@href' #tymethod.trait_function + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="method.trait_function"]//a[@class="anchor"]/@href' #method.trait_function + fn trait_function(&self) {} + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="method.defaulted_override-1"]//a[@class="fn"]/@href' #method.defaulted_override + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="method.defaulted_override-1"]//a[@class="anchor"]/@href' #method.defaulted_override-1 + fn defaulted_override(&self) {} +} + +impl MyTrait for Vec<u8> { + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedtype.Assoc-2"]//a[@class="associatedtype"]/@href' #associatedtype.Assoc + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedtype.Assoc-2"]//a[@class="anchor"]/@href' #associatedtype.Assoc-2 + type Assoc = (); + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedconstant.VALUE-2"]//a[@class="constant"]/@href' #associatedconstant.VALUE + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedconstant.VALUE-2"]//a[@class="anchor"]/@href' #associatedconstant.VALUE-2 + const VALUE: u32 = 5; + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="method.trait_function"]//a[@class="fn"]/@href' #tymethod.trait_function + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="method.trait_function-1"]//a[@class="anchor"]/@href' #method.trait_function-1 + fn trait_function(&self) {} + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="method.defaulted_override-2"]//a[@class="fn"]/@href' #method.defaulted_override + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="method.defaulted_override-2"]//a[@class="anchor"]/@href' #method.defaulted_override-2 + fn defaulted_override(&self) {} +} + +impl MyTrait for MyStruct { + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedtype.Assoc-3"]//a[@class="anchor"]/@href' #associatedtype.Assoc-3 + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="associatedtype.Assoc"]//a[@class="associatedtype"]/@href' trait.MyTrait.html#associatedtype.Assoc + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="associatedtype.Assoc"]//a[@class="anchor"]/@href' #associatedtype.Assoc + type Assoc = bool; + //@ has trait_impl_items_links_and_anchors/trait.MyTrait.html '//*[@id="associatedconstant.VALUE-3"]//a[@class="anchor"]/@href' #associatedconstant.VALUE-3 + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="associatedconstant.VALUE"]//a[@class="constant"]/@href' trait.MyTrait.html#associatedconstant.VALUE + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="associatedconstant.VALUE"]//a[@class="anchor"]/@href' #associatedconstant.VALUE + const VALUE: u32 = 20; + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="method.trait_function"]//a[@class="fn"]/@href' trait.MyTrait.html#tymethod.trait_function + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="method.trait_function"]//a[@class="anchor"]/@href' #method.trait_function + fn trait_function(&self) {} + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="method.defaulted_override"]//a[@class="fn"]/@href' trait.MyTrait.html#method.defaulted_override + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="method.defaulted_override"]//a[@class="anchor"]/@href' #method.defaulted_override + fn defaulted_override(&self) {} + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="method.defaulted"]//a[@class="fn"]/@href' trait.MyTrait.html#method.defaulted + //@ has trait_impl_items_links_and_anchors/struct.MyStruct.html '//*[@id="method.defaulted"]//a[@class="anchor"]/@href' #method.defaulted +} + +pub struct MyStruct; + +// We check that associated items with default values aren't generated in the implementors list. +impl MyTrait for (u8, u8) { + //@ !has trait_impl_items_links_and_anchors/trait.MyTrait.html '//div[@id="associatedconstant.VALUE-4"]' '' + type Assoc = bool; + fn trait_function(&self) {} +} |
