Skip to content

Commit cdafe99

Browse files
committed
Add more missing methods to IntraLinkCrateLoader
This helps with (but does not fix) #84738. I tested on jyn514/objr@edcee7b and still hit ICEs.
1 parent 489ec31 commit cdafe99

File tree

6 files changed

+57
-4
lines changed

6 files changed

+57
-4
lines changed

src/librustdoc/passes/collect_intra_doc_links/early.rs

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use ast::visit;
12
use rustc_ast as ast;
23
use rustc_hir::def::Namespace::TypeNS;
34
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
@@ -16,7 +17,7 @@ crate fn load_intra_link_crates(resolver: Resolver, krate: &ast::Crate) -> Resol
1617
let mut loader = IntraLinkCrateLoader { current_mod: CRATE_DEF_ID, resolver };
1718
// `walk_crate` doesn't visit the crate itself for some reason.
1819
loader.load_links_in_attrs(&krate.attrs, krate.span);
19-
ast::visit::walk_crate(&mut loader, krate);
20+
visit::walk_crate(&mut loader, krate);
2021
loader.resolver
2122
}
2223

@@ -54,7 +55,12 @@ impl IntraLinkCrateLoader {
5455
}
5556
}
5657

57-
impl ast::visit::Visitor<'_> for IntraLinkCrateLoader {
58+
impl visit::Visitor<'_> for IntraLinkCrateLoader {
59+
fn visit_foreign_item(&mut self, item: &ast::ForeignItem) {
60+
self.load_links_in_attrs(&item.attrs, item.span);
61+
visit::walk_foreign_item(self, item)
62+
}
63+
5864
fn visit_item(&mut self, item: &ast::Item) {
5965
use rustc_ast_lowering::ResolverAstLowering;
6066

@@ -64,12 +70,29 @@ impl ast::visit::Visitor<'_> for IntraLinkCrateLoader {
6470
let old_mod = mem::replace(&mut self.current_mod, new_mod);
6571

6672
self.load_links_in_attrs(&item.attrs, item.span);
67-
ast::visit::walk_item(self, item);
73+
visit::walk_item(self, item);
6874

6975
self.current_mod = old_mod;
7076
} else {
7177
self.load_links_in_attrs(&item.attrs, item.span);
72-
ast::visit::walk_item(self, item);
78+
visit::walk_item(self, item);
7379
}
7480
}
81+
82+
// NOTE: if doc-comments are ever allowed on function parameters, this will have to implement `visit_param` too.
83+
84+
fn visit_assoc_item(&mut self, item: &ast::AssocItem, ctxt: visit::AssocCtxt) {
85+
self.load_links_in_attrs(&item.attrs, item.span);
86+
visit::walk_assoc_item(self, item, ctxt)
87+
}
88+
89+
fn visit_field_def(&mut self, field: &ast::FieldDef) {
90+
self.load_links_in_attrs(&field.attrs, field.span);
91+
visit::walk_field_def(self, field)
92+
}
93+
94+
fn visit_variant(&mut self, v: &ast::Variant) {
95+
self.load_links_in_attrs(&v.attrs, v.span);
96+
visit::walk_variant(self, v)
97+
}
7598
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// intentionally empty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// intentionally empty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// intentionally empty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// intentionally empty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// check-pass
2+
// aux-crate:dep1=dep1.rs
3+
// aux-crate:dep2=dep2.rs
4+
// aux-crate:dep3=dep3.rs
5+
// aux-crate:dep4=dep4.rs
6+
#![deny(rustdoc::broken_intra_doc_links)]
7+
8+
pub trait Trait {
9+
/// [dep1]
10+
type Item;
11+
}
12+
13+
pub struct S {
14+
/// [dep2]
15+
pub x: usize,
16+
}
17+
18+
extern "C" {
19+
/// [dep3]
20+
pub fn printf();
21+
}
22+
23+
pub enum E {
24+
/// [dep4]
25+
A
26+
}

0 commit comments

Comments
 (0)