about summary refs log tree commit diff
path: root/tests/rustdoc/extern
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-05-05 17:30:40 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-05-05 17:49:12 +0200
commite14e19a67dcdd7437b29bd37b4aa1fde3e5fecee (patch)
tree72413ee76e1e858195fc1f623c0bc4e6da36f5fe /tests/rustdoc/extern
parente245c3bc6bb7d278106649be9a03fc9b374e196b (diff)
Created `tests/rustdoc/extern` subfolder to limit number of files at the top level
Diffstat (limited to 'tests/rustdoc/extern')
-rw-r--r--tests/rustdoc/extern/auxiliary/empty.rs1
-rw-r--r--tests/rustdoc/extern/auxiliary/extern-links.rs1
-rw-r--r--tests/rustdoc/extern/auxiliary/external-cross-doc.md4
-rw-r--r--tests/rustdoc/extern/auxiliary/external-cross.rs3
-rw-r--r--tests/rustdoc/extern/auxiliary/external-doc.md3
-rw-r--r--tests/rustdoc/extern/auxiliary/html_root.rs2
-rw-r--r--tests/rustdoc/extern/auxiliary/issue-30109-1.rs1
-rw-r--r--tests/rustdoc/extern/auxiliary/no_html_root.rs1
-rw-r--r--tests/rustdoc/extern/auxiliary/panic-item.rs17
-rw-r--r--tests/rustdoc/extern/auxiliary/pub-extern-crate.rs2
-rw-r--r--tests/rustdoc/extern/auxiliary/rustdoc-extern-default-method.rs11
-rw-r--r--tests/rustdoc/extern/auxiliary/rustdoc-extern-method.rs7
-rw-r--r--tests/rustdoc/extern/auxiliary/variant-struct.rs5
-rw-r--r--tests/rustdoc/extern/extern-default-method.no_href_on_anchor.html1
-rw-r--r--tests/rustdoc/extern/extern-default-method.rs23
-rw-r--r--tests/rustdoc/extern/extern-fn-22038.rs22
-rw-r--r--tests/rustdoc/extern/extern-html-root-url-precedence.rs7
-rw-r--r--tests/rustdoc/extern/extern-html-root-url.rs18
-rw-r--r--tests/rustdoc/extern/extern-links.rs21
-rw-r--r--tests/rustdoc/extern/extern-method.rs19
-rw-r--r--tests/rustdoc/extern/external-cross.rs10
-rw-r--r--tests/rustdoc/extern/external-doc.rs14
-rw-r--r--tests/rustdoc/extern/hidden-extern-34025.rs13
-rw-r--r--tests/rustdoc/extern/link-extern-crate-33178.rs17
-rw-r--r--tests/rustdoc/extern/link-extern-crate-item-30109.rs17
-rw-r--r--tests/rustdoc/extern/link-extern-crate-title-33178.rs13
-rw-r--r--tests/rustdoc/extern/pub-extern-crate.rs9
-rw-r--r--tests/rustdoc/extern/unsafe-extern-blocks.rs29
-rw-r--r--tests/rustdoc/extern/unused-extern-crate.rs2
29 files changed, 293 insertions, 0 deletions
diff --git a/tests/rustdoc/extern/auxiliary/empty.rs b/tests/rustdoc/extern/auxiliary/empty.rs
new file mode 100644
index 00000000000..d11c69f812a
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/empty.rs
@@ -0,0 +1 @@
+// intentionally empty
diff --git a/tests/rustdoc/extern/auxiliary/extern-links.rs b/tests/rustdoc/extern/auxiliary/extern-links.rs
new file mode 100644
index 00000000000..4a835673a59
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/extern-links.rs
@@ -0,0 +1 @@
+pub struct Foo;
diff --git a/tests/rustdoc/extern/auxiliary/external-cross-doc.md b/tests/rustdoc/extern/auxiliary/external-cross-doc.md
new file mode 100644
index 00000000000..d3c85326559
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/external-cross-doc.md
@@ -0,0 +1,4 @@
+# Cross-crate imported docs
+
+This file is to make sure `#[doc = include_str!("file.md")]` works when you re-export an item with included
+docs.
diff --git a/tests/rustdoc/extern/auxiliary/external-cross.rs b/tests/rustdoc/extern/auxiliary/external-cross.rs
new file mode 100644
index 00000000000..5de63cdabc6
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/external-cross.rs
@@ -0,0 +1,3 @@
+#[deny(missing_docs)]
+#[doc = include_str!("external-cross-doc.md")]
+pub struct NeedMoreDocs;
diff --git a/tests/rustdoc/extern/auxiliary/external-doc.md b/tests/rustdoc/extern/auxiliary/external-doc.md
new file mode 100644
index 00000000000..babde0a05ad
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/external-doc.md
@@ -0,0 +1,3 @@
+# External Docs
+
+This file is here to test the `#[doc = include_str!("file")]` attribute.
diff --git a/tests/rustdoc/extern/auxiliary/html_root.rs b/tests/rustdoc/extern/auxiliary/html_root.rs
new file mode 100644
index 00000000000..4eb0b700f8f
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/html_root.rs
@@ -0,0 +1,2 @@
+#![doc(html_root_url="https://example.com/html_root")]
+pub fn foo() {}
diff --git a/tests/rustdoc/extern/auxiliary/issue-30109-1.rs b/tests/rustdoc/extern/auxiliary/issue-30109-1.rs
new file mode 100644
index 00000000000..ca05a6a9076
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/issue-30109-1.rs
@@ -0,0 +1 @@
+pub struct Bar;
diff --git a/tests/rustdoc/extern/auxiliary/no_html_root.rs b/tests/rustdoc/extern/auxiliary/no_html_root.rs
new file mode 100644
index 00000000000..c5c0bc606cd
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/no_html_root.rs
@@ -0,0 +1 @@
+pub fn bar() {}
diff --git a/tests/rustdoc/extern/auxiliary/panic-item.rs b/tests/rustdoc/extern/auxiliary/panic-item.rs
new file mode 100644
index 00000000000..ccf784f7284
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/panic-item.rs
@@ -0,0 +1,17 @@
+//@ no-prefer-dynamic
+#![crate_type = "lib"]
+#![no_std]
+#![feature(lang_items)]
+
+use core::panic::PanicInfo;
+use core::sync::atomic::{self, Ordering};
+
+#[panic_handler]
+fn panic(_info: &PanicInfo) -> ! {
+    loop {
+        atomic::compiler_fence(Ordering::SeqCst);
+    }
+}
+
+#[lang = "eh_personality"]
+fn foo() {}
diff --git a/tests/rustdoc/extern/auxiliary/pub-extern-crate.rs b/tests/rustdoc/extern/auxiliary/pub-extern-crate.rs
new file mode 100644
index 00000000000..8c89c8d6c76
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/pub-extern-crate.rs
@@ -0,0 +1,2 @@
+#![crate_name = "inner"]
+pub struct SomeStruct;
diff --git a/tests/rustdoc/extern/auxiliary/rustdoc-extern-default-method.rs b/tests/rustdoc/extern/auxiliary/rustdoc-extern-default-method.rs
new file mode 100644
index 00000000000..12934238a8e
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/rustdoc-extern-default-method.rs
@@ -0,0 +1,11 @@
+#![crate_type="lib"]
+
+pub trait Trait {
+    fn provided(&self) {}
+}
+
+pub struct Struct;
+
+impl Trait for Struct {
+    fn provided(&self) {}
+}
diff --git a/tests/rustdoc/extern/auxiliary/rustdoc-extern-method.rs b/tests/rustdoc/extern/auxiliary/rustdoc-extern-method.rs
new file mode 100644
index 00000000000..e493048d9da
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/rustdoc-extern-method.rs
@@ -0,0 +1,7 @@
+#![crate_type="lib"]
+#![feature(unboxed_closures)]
+
+pub trait Foo {
+    extern "rust-call" fn foo(&self, _: ()) -> i32;
+    extern "rust-call" fn foo_(&self, _: ()) -> i32 { 0 }
+}
diff --git a/tests/rustdoc/extern/auxiliary/variant-struct.rs b/tests/rustdoc/extern/auxiliary/variant-struct.rs
new file mode 100644
index 00000000000..0f3d2e5f1b7
--- /dev/null
+++ b/tests/rustdoc/extern/auxiliary/variant-struct.rs
@@ -0,0 +1,5 @@
+pub enum Foo {
+    Bar {
+        qux: (),
+    }
+}
diff --git a/tests/rustdoc/extern/extern-default-method.no_href_on_anchor.html b/tests/rustdoc/extern/extern-default-method.no_href_on_anchor.html
new file mode 100644
index 00000000000..ef14836ccb8
--- /dev/null
+++ b/tests/rustdoc/extern/extern-default-method.no_href_on_anchor.html
@@ -0,0 +1 @@
+<a class="fn">provided</a>(&amp;self)
\ No newline at end of file
diff --git a/tests/rustdoc/extern/extern-default-method.rs b/tests/rustdoc/extern/extern-default-method.rs
new file mode 100644
index 00000000000..1af9fab152e
--- /dev/null
+++ b/tests/rustdoc/extern/extern-default-method.rs
@@ -0,0 +1,23 @@
+//@ aux-build:rustdoc-extern-default-method.rs
+//@ ignore-cross-compile
+// ignore-tidy-linelength
+
+extern crate rustdoc_extern_default_method as ext;
+
+// For this test, the dependency is compiled but not documented.
+//
+// Still, the struct from the external crate and its impl should be documented since
+// the struct is re-exported from this crate.
+// However, the method in the trait impl should *not* have a link (an `href` attribute) to
+// its corresponding item in the trait declaration since it would otherwise be broken.
+//
+// In older versions of rustdoc, the impl item (`a[@class="fn"]`) used to link to
+// `#method.provided` – i.e. "to itself". Put in quotes since that was actually incorrect in
+// general: If the type `Struct` also had an inherent method called `provided`, the impl item
+// would link to that one even though those two methods are distinct items!
+
+//@ count extern_default_method/struct.Struct.html '//*[@id="method.provided"]' 1
+//@ count extern_default_method/struct.Struct.html '//*[@id="method.provided"]//a[@class="fn"]' 1
+//@ snapshot no_href_on_anchor - '//*[@id="method.provided"]//a[@class="fn"]'
+//@ has extern_default_method/struct.Struct.html '//*[@id="method.provided"]//a[@class="anchor"]/@href' #method.provided
+pub use ext::Struct;
diff --git a/tests/rustdoc/extern/extern-fn-22038.rs b/tests/rustdoc/extern/extern-fn-22038.rs
new file mode 100644
index 00000000000..206c6e181d1
--- /dev/null
+++ b/tests/rustdoc/extern/extern-fn-22038.rs
@@ -0,0 +1,22 @@
+// https://github.com/rust-lang/rust/issues/22038
+#![crate_name="issue_22038"]
+
+extern "C" {
+    //@ has issue_22038/fn.foo1.html \
+    //      '//pre[@class="rust item-decl"]' 'pub unsafe extern "C" fn foo1()'
+    pub fn foo1();
+}
+
+extern "system" {
+    //@ has issue_22038/fn.foo2.html \
+    //      '//pre[@class="rust item-decl"]' 'pub unsafe extern "system" fn foo2()'
+    pub fn foo2();
+}
+
+//@ has issue_22038/fn.bar.html \
+//      '//pre[@class="rust item-decl"]' 'pub extern "C" fn bar()'
+pub extern "C" fn bar() {}
+
+//@ has issue_22038/fn.baz.html \
+//      '//pre[@class="rust item-decl"]' 'pub extern "system" fn baz()'
+pub extern "system" fn baz() {}
diff --git a/tests/rustdoc/extern/extern-html-root-url-precedence.rs b/tests/rustdoc/extern/extern-html-root-url-precedence.rs
new file mode 100644
index 00000000000..93775087997
--- /dev/null
+++ b/tests/rustdoc/extern/extern-html-root-url-precedence.rs
@@ -0,0 +1,7 @@
+//@ compile-flags:-Z unstable-options --extern-html-root-url core=https://example.com/core/0.1.0 --extern-html-root-takes-precedence
+
+//@ has extern_html_root_url_precedence/index.html
+// --extern-html-root should take precedence if `--takes-precedence` is passed
+//@ has - '//a/@href' 'https://example.com/core/0.1.0/core/iter/index.html'
+#[doc(no_inline)]
+pub use std::iter;
diff --git a/tests/rustdoc/extern/extern-html-root-url.rs b/tests/rustdoc/extern/extern-html-root-url.rs
new file mode 100644
index 00000000000..a503e829de4
--- /dev/null
+++ b/tests/rustdoc/extern/extern-html-root-url.rs
@@ -0,0 +1,18 @@
+//@ compile-flags:-Z unstable-options --extern-html-root-url html_root=https://example.com/override --extern-html-root-url no_html_root=https://example.com/override
+//@ aux-build:html_root.rs
+//@ aux-build:no_html_root.rs
+// NOTE: intentionally does not build any auxiliary docs
+
+extern crate html_root;
+extern crate no_html_root;
+
+//@ has extern_html_root_url/index.html
+// `html_root_url` should override `--extern-html-root-url`
+//@ has - '//a/@href' 'https://example.com/html_root/html_root/fn.foo.html'
+#[doc(no_inline)]
+pub use html_root::foo;
+
+#[doc(no_inline)]
+// `--extern-html-root-url` should apply if no `html_root_url` is given
+//@ has - '//a/@href' 'https://example.com/override/no_html_root/fn.bar.html'
+pub use no_html_root::bar;
diff --git a/tests/rustdoc/extern/extern-links.rs b/tests/rustdoc/extern/extern-links.rs
new file mode 100644
index 00000000000..d1fee224755
--- /dev/null
+++ b/tests/rustdoc/extern/extern-links.rs
@@ -0,0 +1,21 @@
+//@ aux-build:extern-links.rs
+//@ ignore-cross-compile
+
+#![crate_name = "foo"]
+
+pub extern crate extern_links;
+
+//@ !has foo/index.html '//a' 'extern_links'
+#[doc(no_inline)]
+pub use extern_links as extern_links2;
+
+//@ !has foo/index.html '//a' 'Foo'
+#[doc(no_inline)]
+pub use extern_links::Foo;
+
+#[doc(hidden)]
+pub mod hidden {
+    //@ !has foo/hidden/extern_links/index.html
+    //@ !has foo/hidden/extern_links/struct.Foo.html
+    pub use extern_links;
+}
diff --git a/tests/rustdoc/extern/extern-method.rs b/tests/rustdoc/extern/extern-method.rs
new file mode 100644
index 00000000000..c3e042f2da8
--- /dev/null
+++ b/tests/rustdoc/extern/extern-method.rs
@@ -0,0 +1,19 @@
+//@ aux-build:rustdoc-extern-method.rs
+//@ ignore-cross-compile
+
+#![feature(unboxed_closures)]
+
+extern crate rustdoc_extern_method as foo;
+
+//@ has extern_method/trait.Foo.html //pre "pub trait Foo"
+//@ has - '//*[@id="tymethod.foo"]//h4[@class="code-header"]' 'extern "rust-call" fn foo'
+//@ has - '//*[@id="method.foo_"]//h4[@class="code-header"]' 'extern "rust-call" fn foo_'
+pub use foo::Foo;
+
+//@ has extern_method/trait.Bar.html //pre "pub trait Bar"
+pub trait Bar {
+    //@ has - '//*[@id="tymethod.bar"]//h4[@class="code-header"]' 'extern "rust-call" fn bar'
+    extern "rust-call" fn bar(&self, _: ());
+    //@ has - '//*[@id="method.bar_"]//h4[@class="code-header"]' 'extern "rust-call" fn bar_'
+    extern "rust-call" fn bar_(&self, _: ()) { }
+}
diff --git a/tests/rustdoc/extern/external-cross.rs b/tests/rustdoc/extern/external-cross.rs
new file mode 100644
index 00000000000..13646ec38cf
--- /dev/null
+++ b/tests/rustdoc/extern/external-cross.rs
@@ -0,0 +1,10 @@
+//@ aux-build:external-cross.rs
+//@ ignore-cross-compile
+
+#![crate_name="host"]
+
+extern crate external_cross;
+
+//@ has host/struct.NeedMoreDocs.html
+//@ has - '//h2' 'Cross-crate imported docs'
+pub use external_cross::NeedMoreDocs;
diff --git a/tests/rustdoc/extern/external-doc.rs b/tests/rustdoc/extern/external-doc.rs
new file mode 100644
index 00000000000..c81aa17ed5a
--- /dev/null
+++ b/tests/rustdoc/extern/external-doc.rs
@@ -0,0 +1,14 @@
+//@ has external_doc/struct.IncludeStrDocs.html
+//@ has - '//h2' 'External Docs'
+//@ has - '//h3' 'Inline Docs'
+#[doc = include_str!("auxiliary/external-doc.md")]
+/// ## Inline Docs
+pub struct IncludeStrDocs;
+
+macro_rules! dir { () => { "auxiliary" } }
+
+//@ has external_doc/struct.EagerExpansion.html
+//@ has - '//h2' 'External Docs'
+#[doc = include_str!(concat!(dir!(), "/external-doc.md"))]
+/// ## Inline Docs
+pub struct EagerExpansion;
diff --git a/tests/rustdoc/extern/hidden-extern-34025.rs b/tests/rustdoc/extern/hidden-extern-34025.rs
new file mode 100644
index 00000000000..2a7b21a874d
--- /dev/null
+++ b/tests/rustdoc/extern/hidden-extern-34025.rs
@@ -0,0 +1,13 @@
+// https://github.com/rust-lang/rust/issues/34025
+#![crate_name = "foo"]
+
+//@ !has 'foo/sys/index.html'
+//@ !has 'foo/sys/sidebar-items.js'
+#[doc(hidden)]
+pub mod sys {
+    extern "C" {
+        //@ !has 'foo/sys/fn.foo.html'
+        #[doc(hidden)]
+        pub fn foo();
+    }
+}
diff --git a/tests/rustdoc/extern/link-extern-crate-33178.rs b/tests/rustdoc/extern/link-extern-crate-33178.rs
new file mode 100644
index 00000000000..94822798af3
--- /dev/null
+++ b/tests/rustdoc/extern/link-extern-crate-33178.rs
@@ -0,0 +1,17 @@
+//@ aux-build:empty.rs
+//@ aux-build:variant-struct.rs
+//@ build-aux-docs
+//@ ignore-cross-compile
+
+// https://github.com/rust-lang/rust/issues/33178
+#![crate_name="issue_33178"]
+
+//@ has issue_33178/index.html
+//@ has - '//a[@title="mod empty"][@href="../empty/index.html"]' empty
+pub extern crate empty;
+
+//@ has - '//a[@title="mod variant_struct"][@href="../variant_struct/index.html"]' variant_struct
+pub extern crate variant_struct as foo;
+
+//@ has - '//a[@title="mod issue_33178"][@href="index.html"]' self
+pub extern crate self as bar;
diff --git a/tests/rustdoc/extern/link-extern-crate-item-30109.rs b/tests/rustdoc/extern/link-extern-crate-item-30109.rs
new file mode 100644
index 00000000000..544cfa14971
--- /dev/null
+++ b/tests/rustdoc/extern/link-extern-crate-item-30109.rs
@@ -0,0 +1,17 @@
+//@ build-aux-docs
+//@ aux-build:issue-30109-1.rs
+//@ ignore-cross-compile
+
+// https://github.com/rust-lang/rust/issues/30109
+#![crate_name="issue_30109"]
+
+pub mod quux {
+    extern crate issue_30109_1 as bar;
+    use self::bar::Bar;
+
+    pub trait Foo {}
+
+    //@ has issue_30109/quux/trait.Foo.html \
+    //          '//a/@href' '../issue_30109_1/struct.Bar.html'
+    impl Foo for Bar {}
+}
diff --git a/tests/rustdoc/extern/link-extern-crate-title-33178.rs b/tests/rustdoc/extern/link-extern-crate-title-33178.rs
new file mode 100644
index 00000000000..39c4fec1cd9
--- /dev/null
+++ b/tests/rustdoc/extern/link-extern-crate-title-33178.rs
@@ -0,0 +1,13 @@
+//@ aux-build:empty.rs
+//@ aux-build:variant-struct.rs
+//@ ignore-cross-compile
+
+// https://github.com/rust-lang/rust/issues/33178
+#![crate_name="issue_33178_1"]
+
+//@ has issue_33178_1/index.html
+//@ !has - //a/@title empty
+pub extern crate empty;
+
+//@ !has - //a/@title variant_struct
+pub extern crate variant_struct as foo;
diff --git a/tests/rustdoc/extern/pub-extern-crate.rs b/tests/rustdoc/extern/pub-extern-crate.rs
new file mode 100644
index 00000000000..05f70301e33
--- /dev/null
+++ b/tests/rustdoc/extern/pub-extern-crate.rs
@@ -0,0 +1,9 @@
+//@ aux-build:pub-extern-crate.rs
+
+//@ has pub_extern_crate/index.html
+//@ !has - '//code' 'pub extern crate inner'
+//@ has - '//a/@href' 'inner/index.html'
+//@ has pub_extern_crate/inner/index.html
+//@ has pub_extern_crate/inner/struct.SomeStruct.html
+#[doc(inline)]
+pub extern crate inner;
diff --git a/tests/rustdoc/extern/unsafe-extern-blocks.rs b/tests/rustdoc/extern/unsafe-extern-blocks.rs
new file mode 100644
index 00000000000..9a4e292dc83
--- /dev/null
+++ b/tests/rustdoc/extern/unsafe-extern-blocks.rs
@@ -0,0 +1,29 @@
+// Test to ensure the feature is working as expected.
+
+#![crate_name = "foo"]
+
+//@ has 'foo/index.html'
+
+// First we check that both the static and the function have a "sup" element
+// to tell they're unsafe.
+
+//@ count - '//dl[@class="item-table"]//sup[@title="unsafe static"]' 1
+//@ has - '//dl[@class="item-table"]//sup[@title="unsafe static"]' '⚠'
+//@ count - '//dl[@class="item-table"]//sup[@title="unsafe function"]' 1
+//@ has - '//dl[@class="item-table"]//sup[@title="unsafe function"]' '⚠'
+
+unsafe extern "C" {
+    //@ has 'foo/static.FOO.html'
+    //@ has - '//pre[@class="rust item-decl"]' 'pub static FOO: i32'
+    pub safe static FOO: i32;
+    //@ has 'foo/static.BAR.html'
+    //@ has - '//pre[@class="rust item-decl"]' 'pub unsafe static BAR: i32'
+    pub static BAR: i32;
+
+    //@ has 'foo/fn.foo.html'
+    //@ has - '//pre[@class="rust item-decl"]' 'pub extern "C" fn foo()'
+    pub safe fn foo();
+    //@ has 'foo/fn.bar.html'
+    //@ has - '//pre[@class="rust item-decl"]' 'pub unsafe extern "C" fn bar()'
+    pub fn bar();
+}
diff --git a/tests/rustdoc/extern/unused-extern-crate.rs b/tests/rustdoc/extern/unused-extern-crate.rs
new file mode 100644
index 00000000000..cdc00fd313a
--- /dev/null
+++ b/tests/rustdoc/extern/unused-extern-crate.rs
@@ -0,0 +1,2 @@
+//@ aux-crate:panic_item=panic-item.rs
+//@ has unused_extern_crate/index.html