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`
This commit is contained in:
Guillaume Gomez 2021-02-20 20:37:04 +01:00 committed by GitHub
commit fc0cb5d5eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

@ -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)
}

View File

@ -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());

View File

@ -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],
}