Skip to content

Commit 6567bc9

Browse files
committed
rustdoc: escape GAT args in more cases
1 parent 480068c commit 6567bc9

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)