Skip to content

Don't generate src link on dummy spans #82332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
}