Skip to content

Commit

Permalink
rustdoc: Resolve doc links on fields during early resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Apr 26, 2022
1 parent 3d237ab commit 6d590ba
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
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,
},
}
}

0 comments on commit 6d590ba

Please sign in to comment.