Skip to content

Commit 72e535e

Browse files
Rollup merge of #109919 - fmease:rustdoc-fix-issue-109488, r=notriddle
rustdoc: escape GAT args in more cases Fixes #109488. Previously we printed the *un*escaped form of GAT arguments not only when `f.alternate()` was true but *also* when we failed to compute the URL of the trait associated with the type projection, i.e. when `href(…)` returned an `Err(_)`. In this PR the argument printing logic is entirely separate from the link resolution code above as it should be. Further, we now only try to compute the URL if the HTML format was requested with `!f.alternate()`. Before, we would sometimes compute the `href` only to throw it away later.
2 parents a5c395e + 6567bc9 commit 72e535e

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

src/librustdoc/html/format.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -1142,22 +1142,21 @@ fn fmt_type<'cx>(
11421142
// the ugliness comes from inlining across crates where
11431143
// everything comes in as a fully resolved QPath (hard to
11441144
// look at).
1145-
match href(trait_.def_id(), cx) {
1146-
Ok((ref url, _, ref path)) if !f.alternate() => {
1147-
write!(
1148-
f,
1149-
"<a class=\"associatedtype\" href=\"{url}#{shortty}.{name}\" \
1150-
title=\"type {path}::{name}\">{name}</a>{args}",
1151-
url = url,
1152-
shortty = ItemType::AssocType,
1153-
name = assoc.name,
1154-
path = join_with_double_colon(path),
1155-
args = assoc.args.print(cx),
1156-
)?;
1157-
}
1158-
_ => write!(f, "{}{:#}", assoc.name, assoc.args.print(cx))?,
1159-
}
1160-
Ok(())
1145+
if !f.alternate() && let Ok((url, _, path)) = href(trait_.def_id(), cx) {
1146+
write!(
1147+
f,
1148+
"<a class=\"associatedtype\" href=\"{url}#{shortty}.{name}\" \
1149+
title=\"type {path}::{name}\">{name}</a>",
1150+
shortty = ItemType::AssocType,
1151+
name = assoc.name,
1152+
path = join_with_double_colon(&path),
1153+
)
1154+
} else {
1155+
write!(f, "{}", assoc.name)
1156+
}?;
1157+
1158+
// Carry `f.alternate()` into this display w/o branching manually.
1159+
fmt::Display::fmt(&assoc.args.print(cx), f)
11611160
}
11621161
}
11631162
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Make sure that we escape the arguments of the GAT projection even if we fail to compute
2+
// the href of the corresponding trait (in this case it is private).
3+
// Further, test that we also linkify the GAT arguments.
4+
5+
// @has 'issue_109488/type.A.html'
6+
// @has - '//pre[@class="rust item-decl"]' '<S as Tr>::P<Option<i32>>'
7+
// @has - '//pre[@class="rust item-decl"]//a[@class="enum"]/@href' '{{channel}}/core/option/enum.Option.html'
8+
pub type A = <S as Tr>::P<Option<i32>>;
9+
10+
/*private*/ trait Tr {
11+
type P<T>;
12+
}
13+
14+
pub struct S;
15+
16+
impl Tr for S {
17+
type P<T> = ();
18+
}

0 commit comments

Comments
 (0)