Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Resolve doc links on fields during early resolution #96447

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/librustdoc/passes/collect_intra_doc_links/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,22 @@ impl EarlyDocLinkResolver<'_, '_> {
if let Res::Def(DefKind::Mod, ..) = child.res {
self.resolve_doc_links_extern_inner(def_id); // Inner attribute scope
}
// Traits are processed in `add_extern_traits_in_scope`.
// `DefKind::Trait`s are processed in `process_extern_impls`.
if let Res::Def(DefKind::Mod | DefKind::Enum, ..) = child.res {
self.process_module_children_or_reexports(def_id);
}
if let Res::Def(DefKind::Struct | DefKind::Union | DefKind::Variant, _) =
child.res
{
let field_def_ids = Vec::from_iter(
self.resolver
.cstore()
.associated_item_def_ids_untracked(def_id, self.sess),
);
for field_def_id in field_def_ids {
self.resolve_doc_links_extern_outer(field_def_id, scope_id);
}
}
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/rustdoc-ui/intra-doc/assoc-field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Traits in scope are collected for doc links in field attributes.

// check-pass
// aux-build: assoc-field-dep.rs

extern crate assoc_field_dep;
pub use assoc_field_dep::*;

#[derive(Clone)]
pub struct Struct;

pub mod mod1 {
pub struct Fields {
/// [crate::Struct::clone]
pub field: u8,
}
}

pub mod mod2 {
pub enum Fields {
V {
/// [crate::Struct::clone]
field: u8,
},
}
}
18 changes: 18 additions & 0 deletions src/test/rustdoc-ui/intra-doc/auxiliary/assoc-field-dep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[derive(Clone)]
pub struct Struct;

pub mod dep_mod1 {
pub struct Fields {
/// [crate::Struct::clone]
pub field: u8,
}
}

pub mod dep_mod2 {
pub enum Fields {
V {
/// [crate::Struct::clone]
field: u8,
},
}
}