diff --git a/src/test/rustdoc-ui/intra-links-anchors.rs b/src/test/rustdoc-ui/intra-links-anchors.rs new file mode 100644 index 000000000000..8603f65dde1f --- /dev/null +++ b/src/test/rustdoc-ui/intra-links-anchors.rs @@ -0,0 +1,45 @@ +#![deny(intra_doc_link_resolution_failure)] + +// A few tests on anchors. + +/// Hello people. +/// +/// You can anchors? Here's one! +/// +/// # hola +/// +/// Isn't it amazing? +pub struct Foo { + pub f: u8, +} + +pub enum Enum { + A, + B, +} + +/// Have you heard about stuff? +/// +/// Like [Foo#hola]. +/// +/// Or maybe [Foo::f#hola]. +//~^ ERROR `[Foo::f#hola]` has an anchor issue... +pub fn foo() {} + +/// Empty. +/// +/// Another anchor error: [hello#people#!]. +//~^ ERROR `[hello#people#!]` has an anchor issue... +pub fn bar() {} + +/// Empty? +/// +/// Damn enum's variants: [Enum::A#whatever]. +//~^ ERROR `[Enum::A#whatever]` has an anchor issue... +pub fn enum_link() {} + +/// Primitives? +/// +/// [u32#hello] +//~^ ERROR `[u32#hello]` has an anchor issue... +pub fn x() {} diff --git a/src/test/rustdoc-ui/intra-links-anchors.stderr b/src/test/rustdoc-ui/intra-links-anchors.stderr new file mode 100644 index 000000000000..39e83b5659be --- /dev/null +++ b/src/test/rustdoc-ui/intra-links-anchors.stderr @@ -0,0 +1,32 @@ +error: `[Foo::f#hola]` has an anchor issue... + --> $DIR/intra-links-anchors.rs:25:15 + | +LL | /// Or maybe [Foo::f#hola]. + | ^^^^^^^^^^^ struct fields cannot be followed by anchors + | +note: lint level defined here + --> $DIR/intra-links-anchors.rs:1:9 + | +LL | #![deny(intra_doc_link_resolution_failure)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: `[hello#people#!]` has an anchor issue... + --> $DIR/intra-links-anchors.rs:31:28 + | +LL | /// Another anchor error: [hello#people#!]. + | ^^^^^^^^^^^^^^ only one `#` is allowed in a link + +error: `[Enum::A#whatever]` has an anchor issue... + --> $DIR/intra-links-anchors.rs:37:28 + | +LL | /// Damn enum's variants: [Enum::A#whatever]. + | ^^^^^^^^^^^^^^^^ variants cannot be followed by anchors + +error: `[u32#hello]` has an anchor issue... + --> $DIR/intra-links-anchors.rs:43:6 + | +LL | /// [u32#hello] + | ^^^^^^^^^ primitive types cannot be followed by anchors + +error: aborting due to 4 previous errors + diff --git a/src/test/rustdoc/intra-links-anchors.rs b/src/test/rustdoc/intra-links-anchors.rs new file mode 100644 index 000000000000..f554e16b4f47 --- /dev/null +++ b/src/test/rustdoc/intra-links-anchors.rs @@ -0,0 +1,12 @@ +/// I want... +/// +/// # Anchor! +pub struct Something; + +// @has intra_links_anchors/struct.SomeOtherType.html +// @has - '//a/@href' '../intra_links_anchors/struct.Something.html#Anchor!' + +/// I want... +/// +/// To link to [Something#Anchor!] +pub struct SomeOtherType;