Skip to content

Commit ef9be56

Browse files
committed
Auto merge of #58972 - QuietMisdreavus:intra-doc-link-imports, r=GuillaumeGomez
rustdoc: don't process `Crate::external_traits` when collecting intra-doc links Part of #58745, closes #58917 The `collect-intra-doc-links` pass keeps track of the modules it recurses through as it processes items. This is used to know what module to give the resolver when looking up links. When looking through the regular items of the crate, this works fine, but the `DocFolder` trait as written doesn't just process the main crate hierarchy - it also processes the trait items in the `external_traits` map. This is useful for other passes (so they can strip out `#[doc(hidden)]` items, for example), but here it creates a situation where we're processing items "outside" the regular module hierarchy. Since everything in `external_traits` is defined outside the current crate, we can't fall back to finding its module scope like we do with local items. Skipping this collection saves us from emitting some spurious warnings. We don't even lose anything by skipping it, either - the docs loaded from here are only ever rendered through `html::render::document_short` which strips any links out, so the fact that the links haven't been loaded doesn't matter. Hopefully this removes most of the remaining spurious resolution warnings from intra-doc links. r? @GuillaumeGomez
2 parents 3750348 + 49cde40 commit ef9be56

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+10
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
196196
_ => Err(())
197197
}
198198
} else {
199+
debug!("attempting to resolve item without parent module: {}", path_str);
199200
Err(())
200201
}
201202
}
@@ -404,6 +405,15 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
404405
self.fold_item_recur(item)
405406
}
406407
}
408+
409+
// FIXME: if we can resolve intra-doc links from other crates, we can use the stock
410+
// `fold_crate`, but until then we should avoid scanning `krate.external_traits` since those
411+
// will never resolve properly
412+
fn fold_crate(&mut self, mut c: Crate) -> Crate {
413+
c.module = c.module.take().and_then(|module| self.fold_item(module));
414+
415+
c
416+
}
407417
}
408418

409419
/// Resolves a string as a macro.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub trait ThisTrait {
2+
fn asdf(&self);
3+
4+
/// let's link to [`asdf`](ThisTrait::asdf)
5+
fn qwop(&self);
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// aux-build:intra-links-external-traits.rs
2+
// ignore-cross-compile
3+
4+
#![crate_name = "outer"]
5+
#![deny(intra_doc_link_resolution_failure)]
6+
7+
// using a trait that has intra-doc links on it from another crate (whether re-exporting or just
8+
// implementing it) used to give spurious resolution failure warnings
9+
10+
extern crate intra_links_external_traits;
11+
12+
pub use intra_links_external_traits::ThisTrait;

0 commit comments

Comments
 (0)