Skip to content

Commit 0c86a68

Browse files
authored
Unrolled build for #148543
Rollup merge of #148543 - GuillaumeGomez:fix-import_trait_associated_functions, r=lolbinarycat Correctly link to associated trait items in reexports Fixes #148008. Issue was that we didn't add anchors in this case. r? ``````@lolbinarycat``````
2 parents 6d41834 + 044245c commit 0c86a68

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/librustdoc/html/format.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,23 @@ fn print_higher_ranked_params_with_space(
838838
pub(crate) fn print_anchor(did: DefId, text: Symbol, cx: &Context<'_>) -> impl Display {
839839
fmt::from_fn(move |f| {
840840
if let Ok(HrefInfo { url, kind, rust_path }) = href(did, cx) {
841+
let tcx = cx.tcx();
842+
let def_kind = tcx.def_kind(did);
843+
let anchor = if matches!(
844+
def_kind,
845+
DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant
846+
) {
847+
let parent_def_id = tcx.parent(did);
848+
let item_type =
849+
ItemType::from_def_kind(def_kind, Some(tcx.def_kind(parent_def_id)));
850+
format!("#{}.{}", item_type.as_str(), tcx.item_name(did))
851+
} else {
852+
String::new()
853+
};
854+
841855
write!(
842856
f,
843-
r#"<a class="{kind}" href="{url}" title="{kind} {path}">{text}</a>"#,
857+
r#"<a class="{kind}" href="{url}{anchor}" title="{kind} {path}">{text}</a>"#,
844858
path = join_path_syms(rust_path),
845859
text = EscapeBodyText(text.as_str()),
846860
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This test ensures that reexports of associated items links to the associated items.
2+
// Regression test for <https://github.com/rust-lang/rust/issues/148008>.
3+
4+
#![feature(import_trait_associated_functions)]
5+
6+
#![crate_name = "foo"]
7+
8+
//@ has 'foo/index.html'
9+
10+
pub trait Test {
11+
fn method();
12+
const CONST: u8;
13+
type Type;
14+
}
15+
16+
//@ has - '//*[@id="reexport.method"]//a[@href="trait.Test.html#tymethod.method"]' 'method'
17+
//@ has - '//*[@id="reexport.CONST"]//a[@href="trait.Test.html#associatedconstant.CONST"]' 'CONST'
18+
//@ has - '//*[@id="reexport.Type"]//a[@href="trait.Test.html#associatedtype.Type"]' 'Type'
19+
pub use self::Test::{method, CONST, Type};

0 commit comments

Comments
 (0)