about summary refs log tree commit diff
path: root/tests/rustdoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-25 01:35:53 +0000
committerbors <bors@rust-lang.org>2023-07-25 01:35:53 +0000
commitbeef07fe8fb98aca9f2b59c6a1b3e4f3ea4c0e15 (patch)
treeb72f5884ddfaaf089b8e01ca754424161eec815b /tests/rustdoc
parent1821920cc8e7dc44b0035da890170bf3eadc2ae9 (diff)
parent637ea3f746236611fc5451cfc97c976650c20218 (diff)
downloadrust-beef07fe8fb98aca9f2b59c6a1b3e4f3ea4c0e15.tar.gz
rust-beef07fe8fb98aca9f2b59c6a1b3e4f3ea4c0e15.zip
Auto merge of #113958 - lukas-code:doc-links, r=GuillaumeGomez,petrochenkov
fix intra-doc links on nested `use` and `extern crate` items

This PR fixes two rustdoc ICEs that happen if there are any intra-doc links on nested `use` or `extern crate` items, for example:
```rust
/// Re-export [`fmt`] and [`io`].
pub use std::{fmt, io}; // "nested" use = use with braces

/// Re-export [`std`].
pub extern crate std;
```

Nested use items were incorrectly considered private and therefore didn't have their intra-doc links resolved. I fixed this by always resolving intra-doc links for nested `use` items that are declared `pub`.

<details>

During AST->HIR lowering, nested `use` items are desugared like this:
```rust
pub use std::{}; // "list stem"
pub use std::fmt;
pub use std::io;
```
Each of these HIR nodes has it's own effective visibility and the list stem is always considered private.
To check the effective visibility of an AST node, the AST node is mapped to a HIR node with `Resolver::local_def_id`, which returns the (private) list stem for nested use items.

</details>

For `extern crate`, there was a hack in rustdoc that stored the `DefId` of the crate itself in the cleaned item, instead of the `DefId` of the `extern crate` item. This made rustdoc look at the resolved links of the extern crate's crate root instead of the `extern crate` item. I've removed this hack and instead translate the `DefId` in the appropriate places.

As as side effect of fixing `extern crate`, i've turned
```rust
#[doc(masked)]
extern crate self as _;
```
into a no-op instead of hiding all trait impls. Proper verification for `doc(masked)` is included as a bonus.

fixes https://github.com/rust-lang/rust/issues/113896
Diffstat (limited to 'tests/rustdoc')
-rw-r--r--tests/rustdoc/intra-doc/nested-use.rs16
-rw-r--r--tests/rustdoc/issue-33178.rs9
2 files changed, 21 insertions, 4 deletions
diff --git a/tests/rustdoc/intra-doc/nested-use.rs b/tests/rustdoc/intra-doc/nested-use.rs
new file mode 100644
index 00000000000..19ebfff1bce
--- /dev/null
+++ b/tests/rustdoc/intra-doc/nested-use.rs
@@ -0,0 +1,16 @@
+// Regression test for issue #113896: Intra-doc links on nested use items.
+
+#![crate_name = "foo"]
+
+// @has foo/struct.Foo.html
+// @has - '//a[@href="struct.Foo.html"]' 'Foo'
+// @has - '//a[@href="struct.Bar.html"]' 'Bar'
+
+/// [`Foo`]
+pub use m::{Foo, Bar};
+
+mod m {
+    /// [`Bar`]
+    pub struct Foo;
+    pub struct Bar;
+}
diff --git a/tests/rustdoc/issue-33178.rs b/tests/rustdoc/issue-33178.rs
index 1f45fe72391..ed643f5ae11 100644
--- a/tests/rustdoc/issue-33178.rs
+++ b/tests/rustdoc/issue-33178.rs
@@ -4,10 +4,11 @@
 // ignore-cross-compile
 
 // @has issue_33178/index.html
-// @has - //a/@title empty
-// @has - //a/@href ../empty/index.html
+// @has - '//a[@title="mod empty"][@href="../empty/index.html"]' empty
 pub extern crate empty;
 
-// @has - //a/@title variant_struct
-// @has - //a/@href ../variant_struct/index.html
+// @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;