Skip to content

Commit

Permalink
Rollup merge of #82332 - GuillaumeGomez:no-src-link-on-dummy-spans, r…
Browse files Browse the repository at this point in the history
…=jyn514

Don't generate src link on dummy spans

Just realized that the "auto trait impls" had `[src]` links were leading to the crate root because they were dummy spans. This PR fixes this issue.

cc `@jyn514`
r? `@camelid`
  • Loading branch information
GuillaumeGomez committed Feb 20, 2021
2 parents 77b6f96 + 0c511c9 commit fc0cb5d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,10 @@ impl Span {
self.0
}

crate fn is_dummy(&self) -> bool {
self.0.is_dummy()
}

crate fn filename(&self, sess: &Session) -> FileName {
sess.source_map().span_to_filename(self.0)
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,9 @@ impl Context<'_> {
/// may happen, for example, with externally inlined items where the source
/// of their crate documentation isn't known.
fn src_href(&self, item: &clean::Item) -> Option<String> {
if item.source.is_dummy() {
return None;
}
let mut root = self.root_path();
let mut path = String::new();
let cnum = item.source.cnum(self.sess());
Expand Down
12 changes: 12 additions & 0 deletions src/test/rustdoc/src-links-auto-impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![crate_name = "foo"]

// @has foo/struct.Unsized.html
// @has - '//h3[@id="impl-Sized"]/code' 'impl !Sized for Unsized'
// @!has - '//h3[@id="impl-Sized"]/a[@class="srclink"]' '[src]'
// @has - '//h3[@id="impl-Sync"]/code' 'impl Sync for Unsized'
// @!has - '//h3[@id="impl-Sync"]/a[@class="srclink"]' '[src]'
// @has - '//h3[@id="impl-Any"]/code' 'impl<T> Any for T'
// @has - '//h3[@id="impl-Any"]/a[@class="srclink"]' '[src]'
pub struct Unsized {
data: [u8],
}

0 comments on commit fc0cb5d

Please sign in to comment.