Skip to content

Commit 9ebd809

Browse files
author
Lukas Markeffsky
committed
fix doc links on use items
1 parent a342617 commit 9ebd809

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

compiler/rustc_resolve/src/late.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ enum MaybeExported<'a> {
549549
Ok(NodeId),
550550
Impl(Option<DefId>),
551551
ImplItem(Result<DefId, &'a Visibility>),
552+
NestedUse(&'a Visibility),
552553
}
553554

554555
impl MaybeExported<'_> {
@@ -559,7 +560,9 @@ impl MaybeExported<'_> {
559560
trait_def_id.as_local()
560561
}
561562
MaybeExported::Impl(None) => return true,
562-
MaybeExported::ImplItem(Err(vis)) => return vis.kind.is_pub(),
563+
MaybeExported::ImplItem(Err(vis)) | MaybeExported::NestedUse(vis) => {
564+
return vis.kind.is_pub();
565+
}
563566
};
564567
def_id.map_or(true, |def_id| r.effective_visibilities.is_exported(def_id))
565568
}
@@ -2284,7 +2287,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
22842287
fn resolve_item(&mut self, item: &'ast Item) {
22852288
let mod_inner_docs =
22862289
matches!(item.kind, ItemKind::Mod(..)) && rustdoc::inner_docs(&item.attrs);
2287-
if !mod_inner_docs && !matches!(item.kind, ItemKind::Impl(..)) {
2290+
if !mod_inner_docs && !matches!(item.kind, ItemKind::Impl(..) | ItemKind::Use(..)) {
22882291
self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
22892292
}
22902293

@@ -2428,6 +2431,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
24282431
}
24292432

24302433
ItemKind::Use(ref use_tree) => {
2434+
let maybe_exported = match use_tree.kind {
2435+
UseTreeKind::Simple(_) | UseTreeKind::Glob => MaybeExported::Ok(item.id),
2436+
UseTreeKind::Nested(_) => MaybeExported::NestedUse(&item.vis),
2437+
};
2438+
self.resolve_doc_links(&item.attrs, maybe_exported);
2439+
24312440
self.future_proof_import(use_tree);
24322441
}
24332442

tests/rustdoc/intra-doc/nested-use.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Regression test for issue #113896: Intra-doc links on nested use items.
2+
3+
#![crate_name = "foo"]
4+
5+
// @has foo/struct.Foo.html
6+
// @has - '//a[@href="struct.Foo.html"]' 'Foo'
7+
// @has - '//a[@href="struct.Bar.html"]' 'Bar'
8+
9+
/// [`Foo`]
10+
pub use m::{Foo, Bar};
11+
12+
mod m {
13+
/// [`Bar`]
14+
pub struct Foo;
15+
pub struct Bar;
16+
}

0 commit comments

Comments
 (0)