rustdoc: escape GAT args in more cases

This commit is contained in:
León Orell Valerian Liehr 2023-04-04 02:09:23 +02:00
parent 480068c235
commit 6567bc9a47
No known key found for this signature in database
GPG Key ID: D17A07215F68E713
2 changed files with 33 additions and 16 deletions

View File

@ -1142,22 +1142,21 @@ fn fmt_type<'cx>(
// the ugliness comes from inlining across crates where // the ugliness comes from inlining across crates where
// everything comes in as a fully resolved QPath (hard to // everything comes in as a fully resolved QPath (hard to
// look at). // look at).
match href(trait_.def_id(), cx) { if !f.alternate() && let Ok((url, _, path)) = href(trait_.def_id(), cx) {
Ok((ref url, _, ref path)) if !f.alternate() => {
write!( write!(
f, f,
"<a class=\"associatedtype\" href=\"{url}#{shortty}.{name}\" \ "<a class=\"associatedtype\" href=\"{url}#{shortty}.{name}\" \
title=\"type {path}::{name}\">{name}</a>{args}", title=\"type {path}::{name}\">{name}</a>",
url = url,
shortty = ItemType::AssocType, shortty = ItemType::AssocType,
name = assoc.name, name = assoc.name,
path = join_with_double_colon(path), path = join_with_double_colon(&path),
args = assoc.args.print(cx), )
)?; } else {
} write!(f, "{}", assoc.name)
_ => write!(f, "{}{:#}", assoc.name, assoc.args.print(cx))?, }?;
}
Ok(()) // Carry `f.alternate()` into this display w/o branching manually.
fmt::Display::fmt(&assoc.args.print(cx), f)
} }
} }
} }

View File

@ -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> = ();
}