Skip to content

Commit

Permalink
Rollup merge of rust-lang#96447 - petrochenkov:docregr, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
rustdoc: Resolve doc links on fields during early resolution

Another subset of rust-lang#94857 which fixes rust-lang#96429.

This case regressed in rust-lang#96135 when `may_have_doc_links`-based filtering was introduced.
Before that filtering structs could collect traits in scope for their fields, but after the filtering structs won't collect anything if they don't have doc comments on them, so we have to visit fields too.
  • Loading branch information
JohnTitor authored May 3, 2022
2 parents e5e0925 + 6d590ba commit a4afb49
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 @@ -293,10 +293,22 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
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 a4afb49

Please sign in to comment.