Skip to content

Commit 86dbd8e

Browse files
Merge ad8a77a into 2958d89
2 parents 2958d89 + ad8a77a commit 86dbd8e

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5066,10 +5066,26 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
50665066
path = &path[..idx];
50675067
need_traits_in_scope = true;
50685068
for ns in [TypeNS, ValueNS, MacroNS] {
5069-
self.resolve_and_cache_rustdoc_path(path, ns);
5069+
if let Some(res) = self.resolve_and_cache_rustdoc_path(path, ns) {
5070+
// Rustdoc ignores tool attribute resolutions and attempts
5071+
// to resolve their prefixes for diagnostics.
5072+
any_resolved |=
5073+
!matches!(res, Res::NonMacroAttr(NonMacroAttrKind::Tool));
5074+
}
50705075
}
50715076
}
50725077
}
5078+
// Only link to current crate if nothing else matched.
5079+
if !any_resolved && &*path_str == self.r.tcx.crate_name(LOCAL_CRATE).as_str() {
5080+
self.r
5081+
.doc_link_resolutions
5082+
.entry(self.parent_scope.module.nearest_parent_mod().expect_local())
5083+
.or_default()
5084+
.insert(
5085+
(Symbol::intern(&path_str), ValueNS),
5086+
Some(Res::Def(DefKind::Mod, CRATE_DEF_ID.to_def_id())),
5087+
);
5088+
}
50735089
}
50745090

50755091
if need_traits_in_scope {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![deny(rustdoc::broken_intra_doc_links)]
2+
#![crate_name = "tarte"]
3+
4+
/// [tarte]
5+
pub struct Tarte;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test to ensure that we can link to the current crate by using its name.
2+
//@ aux-build:intra-link-current-crate.rs
3+
//@ build-aux-docs
4+
5+
#![deny(rustdoc::broken_intra_doc_links)]
6+
#![crate_name = "bar"]
7+
8+
//@ has 'bar/index.html'
9+
//@ has - '//*[@class="docblock"]//a[@href="index.html"]' 'bar'
10+
//! [`bar`]
11+
12+
extern crate tarte;
13+
14+
//@ has 'bar/struct.Tarte.html'
15+
//@ has - '//*[@class="docblock"]//a[@href="../tarte/index.html"]' 'tarte'
16+
#[doc(inline)]
17+
pub use tarte::Tarte;
18+
19+
pub mod foo {
20+
//@ has 'bar/foo/fn.tadam.html'
21+
//@ has - '//*[@class="docblock"]//a[@href="../index.html"]' 'bar'
22+
/// [`bar`]
23+
pub fn tadam() {}
24+
}

0 commit comments

Comments
 (0)