Skip to content
Closed
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
18 changes: 17 additions & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4951,10 +4951,26 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
path = &path[..idx];
need_traits_in_scope = true;
for ns in [TypeNS, ValueNS, MacroNS] {
self.resolve_and_cache_rustdoc_path(path, ns);
if let Some(res) = self.resolve_and_cache_rustdoc_path(path, ns) {
// Rustdoc ignores tool attribute resolutions and attempts
// to resolve their prefixes for diagnostics.
any_resolved |=
!matches!(res, Res::NonMacroAttr(NonMacroAttrKind::Tool));
}
}
}
}
// Only link to current crate if nothing else matched.
if !any_resolved && &*path_str == self.r.tcx.crate_name(LOCAL_CRATE).as_str() {
self.r
.doc_link_resolutions
.entry(self.parent_scope.module.nearest_parent_mod().expect_local())
.or_default()
.insert(
(Symbol::intern(&path_str), ValueNS),
Some(Res::Def(DefKind::Mod, CRATE_DEF_ID.to_def_id())),
);
}
}

if need_traits_in_scope {
Expand Down
5 changes: 5 additions & 0 deletions tests/rustdoc/intra-doc/auxiliary/intra-link-current-crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![crate_name = "tarte"]

/// [tarte]
pub struct Tarte;
24 changes: 24 additions & 0 deletions tests/rustdoc/intra-doc/link-to-current-crate.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, an integration test for cross-crate inlining?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Test to ensure that we can link to the current crate by using its name.
//@ aux-build:intra-link-current-crate.rs
//@ build-aux-docs

#![deny(rustdoc::broken_intra_doc_links)]
#![crate_name = "bar"]

//@ has 'bar/index.html'
//@ has - '//*[@class="docblock"]//a[@href="index.html"]' 'bar'
//! [`bar`]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case for [crate@bar]?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no crate disambiguator. Can be added in a follow-up.


extern crate tarte;

//@ has 'bar/struct.Tarte.html'
//@ has - '//*[@class="docblock"]//a[@href="../tarte/index.html"]' 'tarte'
#[doc(inline)]
pub use tarte::Tarte;

pub mod foo {
//@ has 'bar/foo/fn.tadam.html'
//@ has - '//*[@class="docblock"]//a[@href="../index.html"]' 'bar'
/// [`bar`]
pub fn tadam() {}
}
Loading