Skip to content

Commit a31d633

Browse files
committed
Omit src-links for items from extern macros
If the span of a local item points into an external macro its source-file will be bogus.
1 parent c7640aa commit a31d633

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

src/librustdoc/html/render.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1501,11 +1501,17 @@ impl<'a> Item<'a> {
15011501
true, |component| {
15021502
path.push(component.to_string());
15031503
});
1504-
Some(format!("{root}src/{krate}/{path}.html#{href}",
1505-
root = self.cx.root_path,
1506-
krate = self.cx.layout.krate,
1507-
path = path.join("/"),
1508-
href = href))
1504+
// If the span points into an external macro the
1505+
// source-file will be bogus, i.e `<foo macros>`
1506+
if Path::new(&self.item.source.filename).is_file() {
1507+
Some(format!("{root}src/{krate}/{path}.html#{href}",
1508+
root = self.cx.root_path,
1509+
krate = self.cx.layout.krate,
1510+
path = path.join("/"),
1511+
href = href))
1512+
} else {
1513+
None
1514+
}
15091515

15101516
// If this item is not part of the local crate, then things get a little
15111517
// trickier. We don't actually know the span of the external item, but
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[macro_export]
12+
macro_rules! make_item (
13+
($name: ident) => (pub const $name: usize = 42;)
14+
);

src/test/rustdoc/issue-26606.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:issue-26606-macro.rs
12+
// ignore-cross-compile
13+
// build-aux-docs
14+
15+
// @has issue_26606_macro/macro.make_item!.html
16+
#[macro_use]
17+
extern crate issue_26606_macro;
18+
19+
// @has issue_26606/constant.FOO.html
20+
// @!has - '//a/@href' '../src/'
21+
make_item!(FOO);

0 commit comments

Comments
 (0)