Skip to content

rustdoc: escape GAT args in more cases #109919

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 1 commit into from
Apr 4, 2023
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
31 changes: 15 additions & 16 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,22 +1142,21 @@ fn fmt_type<'cx>(
// the ugliness comes from inlining across crates where
// everything comes in as a fully resolved QPath (hard to
// look at).
match href(trait_.def_id(), cx) {
Ok((ref url, _, ref path)) if !f.alternate() => {
write!(
f,
"<a class=\"associatedtype\" href=\"{url}#{shortty}.{name}\" \
title=\"type {path}::{name}\">{name}</a>{args}",
url = url,
shortty = ItemType::AssocType,
name = assoc.name,
path = join_with_double_colon(path),
args = assoc.args.print(cx),
)?;
}
_ => write!(f, "{}{:#}", assoc.name, assoc.args.print(cx))?,
}
Ok(())
if !f.alternate() && let Ok((url, _, path)) = href(trait_.def_id(), cx) {
write!(
f,
"<a class=\"associatedtype\" href=\"{url}#{shortty}.{name}\" \
title=\"type {path}::{name}\">{name}</a>",
shortty = ItemType::AssocType,
name = assoc.name,
path = join_with_double_colon(&path),
)
} else {
write!(f, "{}", assoc.name)
}?;

// Carry `f.alternate()` into this display w/o branching manually.
fmt::Display::fmt(&assoc.args.print(cx), f)
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/rustdoc/generic-associated-types/issue-109488.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Make sure that we escape the arguments of the GAT projection even if we fail to compute
// the href of the corresponding trait (in this case it is private).
// Further, test that we also linkify the GAT arguments.

// @has 'issue_109488/type.A.html'
// @has - '//pre[@class="rust item-decl"]' '<S as Tr>::P<Option<i32>>'
// @has - '//pre[@class="rust item-decl"]//a[@class="enum"]/@href' '{{channel}}/core/option/enum.Option.html'
pub type A = <S as Tr>::P<Option<i32>>;

/*private*/ trait Tr {
type P<T>;
}

pub struct S;

impl Tr for S {
type P<T> = ();
}