Skip to content

Commit

Permalink
Auto merge of #58972 - QuietMisdreavus:intra-doc-link-imports, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

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
  • Loading branch information
bors committed Apr 11, 2019
2 parents d21bebe + 49cde40 commit ee1474a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
_ => Err(())
}
} else {
debug!("attempting to resolve item without parent module: {}", path_str);
Err(())
}
}
Expand Down Expand Up @@ -404,6 +405,15 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
self.fold_item_recur(item)
}
}

// FIXME: if we can resolve intra-doc links from other crates, we can use the stock
// `fold_crate`, but until then we should avoid scanning `krate.external_traits` since those
// will never resolve properly
fn fold_crate(&mut self, mut c: Crate) -> Crate {
c.module = c.module.take().and_then(|module| self.fold_item(module));

c
}
}

/// Resolves a string as a macro.
Expand Down
6 changes: 6 additions & 0 deletions src/test/rustdoc/auxiliary/intra-links-external-traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub trait ThisTrait {
fn asdf(&self);

/// let's link to [`asdf`](ThisTrait::asdf)
fn qwop(&self);
}
12 changes: 12 additions & 0 deletions src/test/rustdoc/intra-links-external-traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// aux-build:intra-links-external-traits.rs
// ignore-cross-compile

#![crate_name = "outer"]
#![deny(intra_doc_link_resolution_failure)]

// using a trait that has intra-doc links on it from another crate (whether re-exporting or just
// implementing it) used to give spurious resolution failure warnings

extern crate intra_links_external_traits;

pub use intra_links_external_traits::ThisTrait;

0 comments on commit ee1474a

Please sign in to comment.