Rollup merge of #99017 - GuillaumeGomez:rustdoc-ending-enum, r=notriddle
Replace boolean argument for print_where_clause with an enum to make code more clear As you suggested ``@notriddle.`` Just not sure if the naming seems good to you? r? ``@notriddle``
This commit is contained in:
commit
ec0c1560be
3 changed files with 23 additions and 17 deletions
|
@ -268,6 +268,12 @@ impl clean::Generics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub(crate) enum Ending {
|
||||||
|
Newline,
|
||||||
|
NoNewline,
|
||||||
|
}
|
||||||
|
|
||||||
/// * The Generics from which to emit a where-clause.
|
/// * The Generics from which to emit a where-clause.
|
||||||
/// * The number of spaces to indent each line with.
|
/// * The number of spaces to indent each line with.
|
||||||
/// * Whether the where-clause needs to add a comma and newline after the last bound.
|
/// * Whether the where-clause needs to add a comma and newline after the last bound.
|
||||||
|
@ -275,7 +281,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||||
gens: &'a clean::Generics,
|
gens: &'a clean::Generics,
|
||||||
cx: &'a Context<'tcx>,
|
cx: &'a Context<'tcx>,
|
||||||
indent: usize,
|
indent: usize,
|
||||||
end_newline: bool,
|
ending: Ending,
|
||||||
) -> impl fmt::Display + 'a + Captures<'tcx> {
|
) -> impl fmt::Display + 'a + Captures<'tcx> {
|
||||||
use fmt::Write;
|
use fmt::Write;
|
||||||
|
|
||||||
|
@ -342,7 +348,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||||
|
|
||||||
let where_preds = comma_sep(where_predicates, false);
|
let where_preds = comma_sep(where_predicates, false);
|
||||||
let clause = if f.alternate() {
|
let clause = if f.alternate() {
|
||||||
if end_newline {
|
if ending == Ending::Newline {
|
||||||
// add a space so stripping <br> tags and breaking spaces still renders properly
|
// add a space so stripping <br> tags and breaking spaces still renders properly
|
||||||
format!(" where{where_preds}, ")
|
format!(" where{where_preds}, ")
|
||||||
} else {
|
} else {
|
||||||
|
@ -356,7 +362,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
|
||||||
}
|
}
|
||||||
let where_preds = where_preds.to_string().replace("<br>", &br_with_padding);
|
let where_preds = where_preds.to_string().replace("<br>", &br_with_padding);
|
||||||
|
|
||||||
if end_newline {
|
if ending == Ending::Newline {
|
||||||
let mut clause = " ".repeat(indent.saturating_sub(1));
|
let mut clause = " ".repeat(indent.saturating_sub(1));
|
||||||
// add a space so stripping <br> tags and breaking spaces still renders properly
|
// add a space so stripping <br> tags and breaking spaces still renders properly
|
||||||
write!(
|
write!(
|
||||||
|
@ -1167,7 +1173,7 @@ impl clean::Impl {
|
||||||
fmt_type(&self.for_, f, use_absolute, cx)?;
|
fmt_type(&self.for_, f, use_absolute, cx)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt::Display::fmt(&print_where_clause(&self.generics, cx, 0, true), f)?;
|
fmt::Display::fmt(&print_where_clause(&self.generics, cx, 0, Ending::Newline), f)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ use crate::formats::{AssocItemRender, Impl, RenderMode};
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::format::{
|
use crate::html::format::{
|
||||||
href, join_with_double_colon, print_abi_with_space, print_constness_with_space,
|
href, join_with_double_colon, print_abi_with_space, print_constness_with_space,
|
||||||
print_default_space, print_generic_bounds, print_where_clause, Buffer, HrefError,
|
print_default_space, print_generic_bounds, print_where_clause, Buffer, Ending, HrefError,
|
||||||
PrintWithSpace,
|
PrintWithSpace,
|
||||||
};
|
};
|
||||||
use crate::html::highlight;
|
use crate::html::highlight;
|
||||||
|
@ -747,7 +747,7 @@ fn assoc_type(
|
||||||
if !bounds.is_empty() {
|
if !bounds.is_empty() {
|
||||||
write!(w, ": {}", print_generic_bounds(bounds, cx))
|
write!(w, ": {}", print_generic_bounds(bounds, cx))
|
||||||
}
|
}
|
||||||
write!(w, "{}", print_where_clause(generics, cx, indent, false));
|
write!(w, "{}", print_where_clause(generics, cx, indent, Ending::NoNewline));
|
||||||
if let Some(default) = default {
|
if let Some(default) = default {
|
||||||
write!(w, " = {}", default.print(cx))
|
write!(w, " = {}", default.print(cx))
|
||||||
}
|
}
|
||||||
|
@ -796,10 +796,10 @@ fn assoc_method(
|
||||||
header_len += 4;
|
header_len += 4;
|
||||||
let indent_str = " ";
|
let indent_str = " ";
|
||||||
render_attributes_in_pre(w, meth, indent_str);
|
render_attributes_in_pre(w, meth, indent_str);
|
||||||
(4, indent_str, false)
|
(4, indent_str, Ending::NoNewline)
|
||||||
} else {
|
} else {
|
||||||
render_attributes_in_code(w, meth);
|
render_attributes_in_code(w, meth);
|
||||||
(0, "", true)
|
(0, "", Ending::Newline)
|
||||||
};
|
};
|
||||||
w.reserve(header_len + "<a href=\"\" class=\"fnname\">{".len() + "</a>".len());
|
w.reserve(header_len + "<a href=\"\" class=\"fnname\">{".len() + "</a>".len());
|
||||||
write!(
|
write!(
|
||||||
|
|
|
@ -29,7 +29,7 @@ use crate::formats::{AssocItemRender, Impl, RenderMode};
|
||||||
use crate::html::escape::Escape;
|
use crate::html::escape::Escape;
|
||||||
use crate::html::format::{
|
use crate::html::format::{
|
||||||
join_with_double_colon, print_abi_with_space, print_constness_with_space, print_where_clause,
|
join_with_double_colon, print_abi_with_space, print_constness_with_space, print_where_clause,
|
||||||
Buffer, PrintWithSpace,
|
Buffer, Ending, PrintWithSpace,
|
||||||
};
|
};
|
||||||
use crate::html::highlight;
|
use crate::html::highlight;
|
||||||
use crate::html::layout::Page;
|
use crate::html::layout::Page;
|
||||||
|
@ -69,7 +69,7 @@ fn print_where_clause_and_check<'a, 'tcx: 'a>(
|
||||||
cx: &'a Context<'tcx>,
|
cx: &'a Context<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let len_before = buffer.len();
|
let len_before = buffer.len();
|
||||||
write!(buffer, "{}", print_where_clause(gens, cx, 0, true));
|
write!(buffer, "{}", print_where_clause(gens, cx, 0, Ending::Newline));
|
||||||
len_before != buffer.len()
|
len_before != buffer.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &cle
|
||||||
abi = abi,
|
abi = abi,
|
||||||
name = name,
|
name = name,
|
||||||
generics = f.generics.print(cx),
|
generics = f.generics.print(cx),
|
||||||
where_clause = print_where_clause(&f.generics, cx, 0, true),
|
where_clause = print_where_clause(&f.generics, cx, 0, Ending::Newline),
|
||||||
decl = f.decl.full_print(header_len, 0, header.asyncness, cx),
|
decl = f.decl.full_print(header_len, 0, header.asyncness, cx),
|
||||||
notable_traits = notable_traits_decl(&f.decl, cx),
|
notable_traits = notable_traits_decl(&f.decl, cx),
|
||||||
);
|
);
|
||||||
|
@ -556,7 +556,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
|
||||||
);
|
);
|
||||||
|
|
||||||
if !t.generics.where_predicates.is_empty() {
|
if !t.generics.where_predicates.is_empty() {
|
||||||
write!(w, "{}", print_where_clause(&t.generics, cx, 0, true));
|
write!(w, "{}", print_where_clause(&t.generics, cx, 0, Ending::Newline));
|
||||||
} else {
|
} else {
|
||||||
w.write_str(" ");
|
w.write_str(" ");
|
||||||
}
|
}
|
||||||
|
@ -1025,7 +1025,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &
|
||||||
"trait {}{}{} = {};",
|
"trait {}{}{} = {};",
|
||||||
it.name.unwrap(),
|
it.name.unwrap(),
|
||||||
t.generics.print(cx),
|
t.generics.print(cx),
|
||||||
print_where_clause(&t.generics, cx, 0, true),
|
print_where_clause(&t.generics, cx, 0, Ending::Newline),
|
||||||
bounds(&t.bounds, true, cx)
|
bounds(&t.bounds, true, cx)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1049,7 +1049,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &cl
|
||||||
"type {}{}{where_clause} = impl {bounds};",
|
"type {}{}{where_clause} = impl {bounds};",
|
||||||
it.name.unwrap(),
|
it.name.unwrap(),
|
||||||
t.generics.print(cx),
|
t.generics.print(cx),
|
||||||
where_clause = print_where_clause(&t.generics, cx, 0, true),
|
where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline),
|
||||||
bounds = bounds(&t.bounds, false, cx),
|
bounds = bounds(&t.bounds, false, cx),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1074,7 +1074,7 @@ fn item_typedef(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clea
|
||||||
"type {}{}{where_clause} = {type_};",
|
"type {}{}{where_clause} = {type_};",
|
||||||
it.name.unwrap(),
|
it.name.unwrap(),
|
||||||
t.generics.print(cx),
|
t.generics.print(cx),
|
||||||
where_clause = print_where_clause(&t.generics, cx, 0, true),
|
where_clause = print_where_clause(&t.generics, cx, 0, Ending::Newline),
|
||||||
type_ = t.type_.print(cx),
|
type_ = t.type_.print(cx),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1784,7 +1784,7 @@ fn render_struct(
|
||||||
}
|
}
|
||||||
w.write_str(")");
|
w.write_str(")");
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(w, "{}", print_where_clause(g, cx, 0, false));
|
write!(w, "{}", print_where_clause(g, cx, 0, Ending::NoNewline));
|
||||||
}
|
}
|
||||||
// We only want a ";" when we are displaying a tuple struct, not a variant tuple struct.
|
// We only want a ";" when we are displaying a tuple struct, not a variant tuple struct.
|
||||||
if structhead {
|
if structhead {
|
||||||
|
@ -1794,7 +1794,7 @@ fn render_struct(
|
||||||
CtorKind::Const => {
|
CtorKind::Const => {
|
||||||
// Needed for PhantomData.
|
// Needed for PhantomData.
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(w, "{}", print_where_clause(g, cx, 0, false));
|
write!(w, "{}", print_where_clause(g, cx, 0, Ending::NoNewline));
|
||||||
}
|
}
|
||||||
w.write_str(";");
|
w.write_str(";");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue