summaryrefslogtreecommitdiffstats
path: root/src/librustdoc/html/format.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/librustdoc/html/format.rs78
1 files changed, 40 insertions, 38 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 36a47b05c..92e7f2739 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -152,7 +152,7 @@ impl Buffer {
}
}
-fn comma_sep<T: fmt::Display>(
+pub(crate) fn comma_sep<T: fmt::Display>(
items: impl Iterator<Item = T>,
space_after_comma: bool,
) -> impl fmt::Display {
@@ -331,7 +331,8 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
bounds_display.truncate(bounds_display.len() - " + ".len());
write!(f, "{}: {bounds_display}", lifetime.print())
}
- clean::WherePredicate::EqPredicate { lhs, rhs } => {
+ // FIXME(fmease): Render bound params.
+ clean::WherePredicate::EqPredicate { lhs, rhs, bound_params: _ } => {
if f.alternate() {
write!(f, "{:#} == {:#}", lhs.print(cx), rhs.print(cx))
} else {
@@ -349,8 +350,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
let where_preds = comma_sep(where_predicates, false);
let clause = if f.alternate() {
if ending == Ending::Newline {
- // add a space so stripping <br> tags and breaking spaces still renders properly
- format!(" where{where_preds}, ")
+ format!(" where{where_preds},")
} else {
format!(" where{where_preds}")
}
@@ -364,20 +364,16 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
if ending == Ending::Newline {
let mut clause = "&nbsp;".repeat(indent.saturating_sub(1));
- // add a space so stripping <br> tags and breaking spaces still renders properly
- write!(
- clause,
- " <span class=\"where fmt-newline\">where{where_preds},&nbsp;</span>"
- )?;
+ write!(clause, "<span class=\"where fmt-newline\">where{where_preds},</span>")?;
clause
} else {
// insert a <br> tag after a single space but before multiple spaces at the start
if indent == 0 {
- format!(" <br><span class=\"where\">where{where_preds}</span>")
+ format!("<br><span class=\"where\">where{where_preds}</span>")
} else {
let mut clause = br_with_padding;
- clause.truncate(clause.len() - 5 * "&nbsp;".len());
- write!(clause, " <span class=\"where\">where{where_preds}</span>")?;
+ clause.truncate(clause.len() - 4 * "&nbsp;".len());
+ write!(clause, "<span class=\"where\">where{where_preds}</span>")?;
clause
}
}
@@ -592,7 +588,7 @@ fn generate_macro_def_id_path(
}
})
.collect();
- let relative = fqp.iter().map(|elem| elem.to_string());
+ let mut relative = fqp.iter().map(|elem| elem.to_string());
let cstore = CStore::from_tcx(tcx);
// We need this to prevent a `panic` when this function is used from intra doc links...
if !cstore.has_crate_data(def_id.krate) {
@@ -612,11 +608,11 @@ fn generate_macro_def_id_path(
let mut path = if is_macro_2 {
once(crate_name.clone()).chain(relative).collect()
} else {
- vec![crate_name.clone(), relative.last().unwrap()]
+ vec![crate_name.clone(), relative.next_back().unwrap()]
};
if path.len() < 2 {
// The minimum we can have is the crate name followed by the macro name. If shorter, then
- // it means that that `relative` was empty, which is an error.
+ // it means that `relative` was empty, which is an error.
debug!("macro path cannot be empty!");
return Err(HrefError::NotInExternalCache);
}
@@ -663,7 +659,7 @@ pub(crate) fn href_with_root_path(
}
if !did.is_local()
- && !cache.access_levels.is_public(did)
+ && !cache.effective_visibilities.is_directly_public(did)
&& !cache.document_private
&& !cache.primitive_locations.values().any(|&id| id == did)
{
@@ -1015,15 +1011,25 @@ fn fmt_type<'cx>(
write!(f, "]")
}
},
- clean::Array(ref t, ref n) => {
- primitive_link(f, PrimitiveType::Array, "[", cx)?;
- fmt::Display::fmt(&t.print(cx), f)?;
- if f.alternate() {
- primitive_link(f, PrimitiveType::Array, &format!("; {}]", n), cx)
- } else {
- primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n)), cx)
+ clean::Array(ref t, ref n) => match **t {
+ clean::Generic(name) if !f.alternate() => primitive_link(
+ f,
+ PrimitiveType::Array,
+ &format!("[{name}; {n}]", n = Escape(n)),
+ cx,
+ ),
+ _ => {
+ write!(f, "[")?;
+ fmt::Display::fmt(&t.print(cx), f)?;
+ if f.alternate() {
+ write!(f, "; {n}")?;
+ } else {
+ write!(f, "; ")?;
+ primitive_link(f, PrimitiveType::Array, &format!("{n}", n = Escape(n)), cx)?;
+ }
+ write!(f, "]")
}
- }
+ },
clean::RawPointer(m, ref t) => {
let m = match m {
hir::Mutability::Mut => "mut",
@@ -1079,7 +1085,12 @@ fn fmt_type<'cx>(
write!(f, "impl {}", print_generic_bounds(bounds, cx))
}
}
- clean::QPath { ref assoc, ref self_type, ref trait_, should_show_cast } => {
+ clean::QPath(box clean::QPathData {
+ ref assoc,
+ ref self_type,
+ ref trait_,
+ should_show_cast,
+ }) => {
if f.alternate() {
if should_show_cast {
write!(f, "<{:#} as {:#}>::", self_type.print(cx), trait_.print(cx))?
@@ -1305,22 +1316,19 @@ impl clean::FnDecl {
/// <br>Used to determine line-wrapping.
/// * `indent`: The number of spaces to indent each successive line with, if line-wrapping is
/// necessary.
- /// * `asyncness`: Whether the function is async or not.
pub(crate) fn full_print<'a, 'tcx: 'a>(
&'a self,
header_len: usize,
indent: usize,
- asyncness: hir::IsAsync,
cx: &'a Context<'tcx>,
) -> impl fmt::Display + 'a + Captures<'tcx> {
- display_fn(move |f| self.inner_full_print(header_len, indent, asyncness, f, cx))
+ display_fn(move |f| self.inner_full_print(header_len, indent, f, cx))
}
fn inner_full_print(
&self,
header_len: usize,
indent: usize,
- asyncness: hir::IsAsync,
f: &mut fmt::Formatter<'_>,
cx: &Context<'_>,
) -> fmt::Result {
@@ -1385,15 +1393,9 @@ impl clean::FnDecl {
args_plain.push_str(", ...");
}
- let arrow_plain;
- let arrow = if let hir::IsAsync::Async = asyncness {
- let output = self.sugared_async_return_type();
- arrow_plain = format!("{:#}", output.print(cx));
- if f.alternate() { arrow_plain.clone() } else { format!("{}", output.print(cx)) }
- } else {
- arrow_plain = format!("{:#}", self.output.print(cx));
- if f.alternate() { arrow_plain.clone() } else { format!("{}", self.output.print(cx)) }
- };
+ let arrow_plain = format!("{:#}", self.output.print(cx));
+ let arrow =
+ if f.alternate() { arrow_plain.clone() } else { format!("{}", self.output.print(cx)) };
let declaration_len = header_len + args_plain.len() + arrow_plain.len();
let output = if declaration_len > 80 {