summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/html/format.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /src/librustdoc/html/format.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librustdoc/html/format.rs')
-rw-r--r--src/librustdoc/html/format.rs49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 1b445b898..d963d6092 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -167,7 +167,7 @@ pub(crate) fn print_generic_bounds<'a, 'tcx: 'a>(
display_fn(move |f| {
let mut bounds_dup = FxHashSet::default();
- for (i, bound) in bounds.iter().filter(|b| bounds_dup.insert(b.clone())).enumerate() {
+ for (i, bound) in bounds.iter().filter(|b| bounds_dup.insert(*b)).enumerate() {
if i > 0 {
f.write_str(" + ")?;
}
@@ -439,6 +439,7 @@ impl clean::GenericBound {
let modifier_str = match modifier {
hir::TraitBoundModifier::None => "",
hir::TraitBoundModifier::Maybe => "?",
+ hir::TraitBoundModifier::Negative => "!",
// ~const is experimental; do not display those bounds in rustdoc
hir::TraitBoundModifier::MaybeConst => "",
};
@@ -1115,14 +1116,17 @@ fn fmt_type<'cx>(
ref trait_,
should_show_cast,
}) => {
+ // FIXME(inherent_associated_types): Once we support non-ADT self-types (#106719),
+ // we need to surround them with angle brackets in some cases (e.g. `<dyn …>::P`).
+
if f.alternate() {
- if should_show_cast {
+ if let Some(trait_) = trait_ && should_show_cast {
write!(f, "<{:#} as {:#}>::", self_type.print(cx), trait_.print(cx))?
} else {
write!(f, "{:#}::", self_type.print(cx))?
}
} else {
- if should_show_cast {
+ if let Some(trait_) = trait_ && should_show_cast {
write!(f, "&lt;{} as {}&gt;::", self_type.print(cx), trait_.print(cx))?
} else {
write!(f, "{}::", self_type.print(cx))?
@@ -1138,15 +1142,36 @@ fn fmt_type<'cx>(
// the ugliness comes from inlining across crates where
// everything comes in as a fully resolved QPath (hard to
// look at).
- 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),
- )
+ if !f.alternate() {
+ // FIXME(inherent_associated_types): We always link to the very first associated
+ // type (in respect to source order) that bears the given name (`assoc.name`) and that is
+ // affiliated with the computed `DefId`. This is obviously incorrect when we have
+ // multiple impl blocks. Ideally, we would thread the `DefId` of the assoc ty itself
+ // through here and map it to the corresponding HTML ID that was generated by
+ // `render::Context::derive_id` when the impl blocks were rendered.
+ // There is no such mapping unfortunately.
+ // As a hack, we could badly imitate `derive_id` here by keeping *count* when looking
+ // for the assoc ty `DefId` in `tcx.associated_items(self_ty_did).in_definition_order()`
+ // considering privacy, `doc(hidden)`, etc.
+ // I don't feel like that right now :cold_sweat:.
+
+ let parent_href = match trait_ {
+ Some(trait_) => href(trait_.def_id(), cx).ok(),
+ None => self_type.def_id(cx.cache()).and_then(|did| href(did, cx).ok()),
+ };
+
+ if let Some((url, _, path)) = parent_href {
+ 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)
+ }
} else {
write!(f, "{}", assoc.name)
}?;