Skip to content

Commit fc0cb5d

Browse files
Rollup merge of #82332 - GuillaumeGomez:no-src-link-on-dummy-spans, r=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`
2 parents 77b6f96 + 0c511c9 commit fc0cb5d

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Diff for: src/librustdoc/clean/types.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,10 @@ impl Span {
18521852
self.0
18531853
}
18541854

1855+
crate fn is_dummy(&self) -> bool {
1856+
self.0.is_dummy()
1857+
}
1858+
18551859
crate fn filename(&self, sess: &Session) -> FileName {
18561860
sess.source_map().span_to_filename(self.0)
18571861
}

Diff for: src/librustdoc/html/render/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,9 @@ impl Context<'_> {
16381638
/// may happen, for example, with externally inlined items where the source
16391639
/// of their crate documentation isn't known.
16401640
fn src_href(&self, item: &clean::Item) -> Option<String> {
1641+
if item.source.is_dummy() {
1642+
return None;
1643+
}
16411644
let mut root = self.root_path();
16421645
let mut path = String::new();
16431646
let cnum = item.source.cnum(self.sess());

Diff for: src/test/rustdoc/src-links-auto-impls.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![crate_name = "foo"]
2+
3+
// @has foo/struct.Unsized.html
4+
// @has - '//h3[@id="impl-Sized"]/code' 'impl !Sized for Unsized'
5+
// @!has - '//h3[@id="impl-Sized"]/a[@class="srclink"]' '[src]'
6+
// @has - '//h3[@id="impl-Sync"]/code' 'impl Sync for Unsized'
7+
// @!has - '//h3[@id="impl-Sync"]/a[@class="srclink"]' '[src]'
8+
// @has - '//h3[@id="impl-Any"]/code' 'impl<T> Any for T'
9+
// @has - '//h3[@id="impl-Any"]/a[@class="srclink"]' '[src]'
10+
pub struct Unsized {
11+
data: [u8],
12+
}

0 commit comments

Comments
 (0)