Skip to content

Commit 21d613b

Browse files
committed
Auto merge of #96447 - petrochenkov:docregr, r=GuillaumeGomez
rustdoc: Resolve doc links on fields during early resolution Another subset of #94857 which fixes #96429. This case regressed in #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.
2 parents 9add632 + 6d590ba commit 21d613b

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

src/librustdoc/passes/collect_intra_doc_links/early.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,22 @@ impl<'ra> EarlyDocLinkResolver<'_, 'ra> {
293293
if let Res::Def(DefKind::Mod, ..) = child.res {
294294
self.resolve_doc_links_extern_inner(def_id); // Inner attribute scope
295295
}
296-
// Traits are processed in `add_extern_traits_in_scope`.
296+
// `DefKind::Trait`s are processed in `process_extern_impls`.
297297
if let Res::Def(DefKind::Mod | DefKind::Enum, ..) = child.res {
298298
self.process_module_children_or_reexports(def_id);
299299
}
300+
if let Res::Def(DefKind::Struct | DefKind::Union | DefKind::Variant, _) =
301+
child.res
302+
{
303+
let field_def_ids = Vec::from_iter(
304+
self.resolver
305+
.cstore()
306+
.associated_item_def_ids_untracked(def_id, self.sess),
307+
);
308+
for field_def_id in field_def_ids {
309+
self.resolve_doc_links_extern_outer(field_def_id, scope_id);
310+
}
311+
}
300312
}
301313
}
302314
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Traits in scope are collected for doc links in field attributes.
2+
3+
// check-pass
4+
// aux-build: assoc-field-dep.rs
5+
6+
extern crate assoc_field_dep;
7+
pub use assoc_field_dep::*;
8+
9+
#[derive(Clone)]
10+
pub struct Struct;
11+
12+
pub mod mod1 {
13+
pub struct Fields {
14+
/// [crate::Struct::clone]
15+
pub field: u8,
16+
}
17+
}
18+
19+
pub mod mod2 {
20+
pub enum Fields {
21+
V {
22+
/// [crate::Struct::clone]
23+
field: u8,
24+
},
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#[derive(Clone)]
2+
pub struct Struct;
3+
4+
pub mod dep_mod1 {
5+
pub struct Fields {
6+
/// [crate::Struct::clone]
7+
pub field: u8,
8+
}
9+
}
10+
11+
pub mod dep_mod2 {
12+
pub enum Fields {
13+
V {
14+
/// [crate::Struct::clone]
15+
field: u8,
16+
},
17+
}
18+
}

0 commit comments

Comments
 (0)