1
Fork 0

rustdoc: move the cx argument to the end of the list

This should help make things consistent.
This commit is contained in:
Michael Howell 2021-04-16 12:29:35 -07:00
parent bb0204861b
commit 755b4fb02b
3 changed files with 33 additions and 33 deletions

View file

@ -125,8 +125,8 @@ fn comma_sep<T: fmt::Display>(items: impl Iterator<Item = T>) -> impl fmt::Displ
} }
crate fn print_generic_bounds<'a, 'tcx: 'a>( crate fn print_generic_bounds<'a, 'tcx: 'a>(
cx: &'a Context<'tcx>,
bounds: &'a [clean::GenericBound], bounds: &'a [clean::GenericBound],
cx: &'a Context<'tcx>,
) -> impl fmt::Display + 'a + Captures<'tcx> { ) -> impl fmt::Display + 'a + Captures<'tcx> {
display_fn(move |f| { display_fn(move |f| {
let mut bounds_dup = FxHashSet::default(); let mut bounds_dup = FxHashSet::default();
@ -155,9 +155,9 @@ impl clean::GenericParamDef {
if !bounds.is_empty() { if !bounds.is_empty() {
if f.alternate() { if f.alternate() {
write!(f, ": {:#}", print_generic_bounds(cx, bounds))?; write!(f, ": {:#}", print_generic_bounds(bounds, cx))?;
} else { } else {
write!(f, ":&nbsp;{}", print_generic_bounds(cx, bounds))?; write!(f, ":&nbsp;{}", print_generic_bounds(bounds, cx))?;
} }
} }
@ -239,13 +239,13 @@ crate fn print_where_clause<'a, 'tcx: 'a>(
clause.push_str(&format!( clause.push_str(&format!(
"{:#}: {:#}", "{:#}: {:#}",
ty.print(cx), ty.print(cx),
print_generic_bounds(cx, bounds) print_generic_bounds(bounds, cx)
)); ));
} else { } else {
clause.push_str(&format!( clause.push_str(&format!(
"{}: {}", "{}: {}",
ty.print(cx), ty.print(cx),
print_generic_bounds(cx, bounds) print_generic_bounds(bounds, cx)
)); ));
} }
} }
@ -819,9 +819,9 @@ fn fmt_type<'cx>(
} }
clean::ImplTrait(ref bounds) => { clean::ImplTrait(ref bounds) => {
if f.alternate() { if f.alternate() {
write!(f, "impl {:#}", print_generic_bounds(cx, bounds)) write!(f, "impl {:#}", print_generic_bounds(bounds, cx))
} else { } else {
write!(f, "impl {}", print_generic_bounds(cx, bounds)) write!(f, "impl {}", print_generic_bounds(bounds, cx))
} }
} }
clean::QPath { ref name, ref self_type, ref trait_ } => { clean::QPath { ref name, ref self_type, ref trait_ } => {
@ -1013,21 +1013,21 @@ impl clean::FnDecl {
/// * `asyncness`: Whether the function is async or not. /// * `asyncness`: Whether the function is async or not.
crate fn full_print<'a, 'tcx: 'a>( crate fn full_print<'a, 'tcx: 'a>(
&'a self, &'a self,
cx: &'a Context<'tcx>,
header_len: usize, header_len: usize,
indent: usize, indent: usize,
asyncness: hir::IsAsync, asyncness: hir::IsAsync,
cx: &'a Context<'tcx>,
) -> impl fmt::Display + 'a + Captures<'tcx> { ) -> impl fmt::Display + 'a + Captures<'tcx> {
display_fn(move |f| self.inner_full_print(cx, header_len, indent, asyncness, f)) display_fn(move |f| self.inner_full_print(header_len, indent, asyncness, f, cx))
} }
fn inner_full_print( fn inner_full_print(
&self, &self,
cx: &Context<'_>,
header_len: usize, header_len: usize,
indent: usize, indent: usize,
asyncness: hir::IsAsync, asyncness: hir::IsAsync,
f: &mut fmt::Formatter<'_>, f: &mut fmt::Formatter<'_>,
cx: &Context<'_>,
) -> fmt::Result { ) -> fmt::Result {
let amp = if f.alternate() { "&" } else { "&amp;" }; let amp = if f.alternate() { "&" } else { "&amp;" };
let mut args = String::new(); let mut args = String::new();
@ -1134,8 +1134,8 @@ impl clean::FnDecl {
impl clean::Visibility { impl clean::Visibility {
crate fn print_with_space<'a, 'tcx: 'a>( crate fn print_with_space<'a, 'tcx: 'a>(
self, self,
cx: &'a Context<'tcx>,
item_did: DefId, item_did: DefId,
cx: &'a Context<'tcx>,
) -> impl fmt::Display + 'a + Captures<'tcx> { ) -> impl fmt::Display + 'a + Captures<'tcx> {
let to_print = match self { let to_print = match self {
clean::Public => "pub ".to_owned(), clean::Public => "pub ".to_owned(),
@ -1320,9 +1320,9 @@ impl clean::TypeBinding {
clean::TypeBindingKind::Constraint { ref bounds } => { clean::TypeBindingKind::Constraint { ref bounds } => {
if !bounds.is_empty() { if !bounds.is_empty() {
if f.alternate() { if f.alternate() {
write!(f, ": {:#}", print_generic_bounds(cx, bounds))?; write!(f, ": {:#}", print_generic_bounds(bounds, cx))?;
} else { } else {
write!(f, ":&nbsp;{}", print_generic_bounds(cx, bounds))?; write!(f, ":&nbsp;{}", print_generic_bounds(bounds, cx))?;
} }
} }
} }

View file

@ -815,7 +815,7 @@ fn assoc_const(
w, w,
"{}{}const <a href=\"{}\" class=\"constant\"><b>{}</b></a>: {}", "{}{}const <a href=\"{}\" class=\"constant\"><b>{}</b></a>: {}",
extra, extra,
it.visibility.print_with_space(cx, it.def_id), it.visibility.print_with_space(it.def_id, cx),
naive_assoc_href(it, link, cx), naive_assoc_href(it, link, cx),
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
ty.print(cx) ty.print(cx)
@ -839,7 +839,7 @@ fn assoc_type(
it.name.as_ref().unwrap() it.name.as_ref().unwrap()
); );
if !bounds.is_empty() { if !bounds.is_empty() {
write!(w, ": {}", print_generic_bounds(cx, bounds)) write!(w, ": {}", print_generic_bounds(bounds, cx))
} }
if let Some(default) = default { if let Some(default) = default {
write!(w, " = {}", default.print(cx)) write!(w, " = {}", default.print(cx))
@ -910,7 +910,7 @@ fn render_assoc_item(
.unwrap_or_else(|| format!("#{}.{}", ty, name)) .unwrap_or_else(|| format!("#{}.{}", ty, name))
} }
}; };
let vis = meth.visibility.print_with_space(cx, meth.def_id).to_string(); let vis = meth.visibility.print_with_space(meth.def_id, cx).to_string();
let constness = header.constness.print_with_space(); let constness = header.constness.print_with_space();
let asyncness = header.asyncness.print_with_space(); let asyncness = header.asyncness.print_with_space();
let unsafety = header.unsafety.print_with_space(); let unsafety = header.unsafety.print_with_space();
@ -952,7 +952,7 @@ fn render_assoc_item(
href = href, href = href,
name = name, name = name,
generics = g.print(cx), generics = g.print(cx),
decl = d.full_print(cx, header_len, indent, header.asyncness), decl = d.full_print(header_len, indent, header.asyncness, cx),
notable_traits = notable_traits_decl(&d, cx), notable_traits = notable_traits_decl(&d, cx),
where_clause = print_where_clause(g, cx, indent, end_newline), where_clause = print_where_clause(g, cx, indent, end_newline),
) )

View file

@ -267,14 +267,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
Some(ref src) => write!( Some(ref src) => write!(
w, w,
"<tr><td><code>{}extern crate {} as {};", "<tr><td><code>{}extern crate {} as {};",
myitem.visibility.print_with_space(cx, myitem.def_id), myitem.visibility.print_with_space(myitem.def_id, cx),
anchor(myitem.def_id, &*src.as_str(), cx), anchor(myitem.def_id, &*src.as_str(), cx),
myitem.name.as_ref().unwrap(), myitem.name.as_ref().unwrap(),
), ),
None => write!( None => write!(
w, w,
"<tr><td><code>{}extern crate {};", "<tr><td><code>{}extern crate {};",
myitem.visibility.print_with_space(cx, myitem.def_id), myitem.visibility.print_with_space(myitem.def_id, cx),
anchor(myitem.def_id, &*myitem.name.as_ref().unwrap().as_str(), cx), anchor(myitem.def_id, &*myitem.name.as_ref().unwrap().as_str(), cx),
), ),
} }
@ -285,7 +285,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
write!( write!(
w, w,
"<tr><td><code>{}{}</code></td></tr>", "<tr><td><code>{}{}</code></td></tr>",
myitem.visibility.print_with_space(cx, myitem.def_id), myitem.visibility.print_with_space(myitem.def_id, cx),
import.print(cx), import.print(cx),
); );
} }
@ -386,7 +386,7 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) { fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) {
let header_len = format!( let header_len = format!(
"{}{}{}{}{:#}fn {}{:#}", "{}{}{}{}{:#}fn {}{:#}",
it.visibility.print_with_space(cx, it.def_id), it.visibility.print_with_space(it.def_id, cx),
f.header.constness.print_with_space(), f.header.constness.print_with_space(),
f.header.asyncness.print_with_space(), f.header.asyncness.print_with_space(),
f.header.unsafety.print_with_space(), f.header.unsafety.print_with_space(),
@ -401,7 +401,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
w, w,
"{vis}{constness}{asyncness}{unsafety}{abi}fn \ "{vis}{constness}{asyncness}{unsafety}{abi}fn \
{name}{generics}{decl}{notable_traits}{where_clause}</pre>", {name}{generics}{decl}{notable_traits}{where_clause}</pre>",
vis = it.visibility.print_with_space(cx, it.def_id), vis = it.visibility.print_with_space(it.def_id, cx),
constness = f.header.constness.print_with_space(), constness = f.header.constness.print_with_space(),
asyncness = f.header.asyncness.print_with_space(), asyncness = f.header.asyncness.print_with_space(),
unsafety = f.header.unsafety.print_with_space(), unsafety = f.header.unsafety.print_with_space(),
@ -409,7 +409,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::
name = it.name.as_ref().unwrap(), name = it.name.as_ref().unwrap(),
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, true),
decl = f.decl.full_print(cx, header_len, 0, f.header.asyncness), decl = f.decl.full_print(header_len, 0, f.header.asyncness, cx),
notable_traits = notable_traits_decl(&f.decl, cx), notable_traits = notable_traits_decl(&f.decl, cx),
); );
document(w, cx, it, None) document(w, cx, it, None)
@ -429,7 +429,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
write!( write!(
w, w,
"{}{}{}trait {}{}{}", "{}{}{}trait {}{}{}",
it.visibility.print_with_space(cx, it.def_id), it.visibility.print_with_space(it.def_id, cx),
t.unsafety.print_with_space(), t.unsafety.print_with_space(),
if t.is_auto { "auto " } else { "" }, if t.is_auto { "auto " } else { "" },
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
@ -848,7 +848,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
write!( write!(
w, w,
"{}enum {}{}{}", "{}enum {}{}{}",
it.visibility.print_with_space(cx, it.def_id), it.visibility.print_with_space(it.def_id, cx),
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
e.generics.print(cx), e.generics.print(cx),
print_where_clause(&e.generics, cx, 0, true), print_where_clause(&e.generics, cx, 0, true),
@ -1029,7 +1029,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
write!( write!(
w, w,
"{vis}const {name}: {typ}", "{vis}const {name}: {typ}",
vis = it.visibility.print_with_space(cx, it.def_id), vis = it.visibility.print_with_space(it.def_id, cx),
name = it.name.as_ref().unwrap(), name = it.name.as_ref().unwrap(),
typ = c.type_.print(cx), typ = c.type_.print(cx),
); );
@ -1116,7 +1116,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
write!( write!(
w, w,
"{vis}static {mutability}{name}: {typ}</pre>", "{vis}static {mutability}{name}: {typ}</pre>",
vis = it.visibility.print_with_space(cx, it.def_id), vis = it.visibility.print_with_space(it.def_id, cx),
mutability = s.mutability.print_with_space(), mutability = s.mutability.print_with_space(),
name = it.name.as_ref().unwrap(), name = it.name.as_ref().unwrap(),
typ = s.type_.print(cx) typ = s.type_.print(cx)
@ -1130,7 +1130,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
write!( write!(
w, w,
" {}type {};\n}}</pre>", " {}type {};\n}}</pre>",
it.visibility.print_with_space(cx, it.def_id), it.visibility.print_with_space(it.def_id, cx),
it.name.as_ref().unwrap(), it.name.as_ref().unwrap(),
); );
@ -1289,7 +1289,7 @@ fn render_union(
write!( write!(
w, w,
"{}{}{}", "{}{}{}",
it.visibility.print_with_space(cx, it.def_id), it.visibility.print_with_space(it.def_id, cx),
if structhead { "union " } else { "" }, if structhead { "union " } else { "" },
it.name.as_ref().unwrap() it.name.as_ref().unwrap()
); );
@ -1311,7 +1311,7 @@ fn render_union(
write!( write!(
w, w,
" {}{}: {},\n{}", " {}{}: {},\n{}",
field.visibility.print_with_space(cx, field.def_id), field.visibility.print_with_space(field.def_id, cx),
field.name.as_ref().unwrap(), field.name.as_ref().unwrap(),
ty.print(cx), ty.print(cx),
tab tab
@ -1341,7 +1341,7 @@ fn render_struct(
write!( write!(
w, w,
"{}{}{}", "{}{}{}",
it.visibility.print_with_space(cx, it.def_id), it.visibility.print_with_space(it.def_id, cx),
if structhead { "struct " } else { "" }, if structhead { "struct " } else { "" },
it.name.as_ref().unwrap() it.name.as_ref().unwrap()
); );
@ -1367,7 +1367,7 @@ fn render_struct(
w, w,
"\n{} {}{}: {},", "\n{} {}{}: {},",
tab, tab,
field.visibility.print_with_space(cx, field.def_id), field.visibility.print_with_space(field.def_id, cx),
field.name.as_ref().unwrap(), field.name.as_ref().unwrap(),
ty.print(cx), ty.print(cx),
); );
@ -1401,7 +1401,7 @@ fn render_struct(
write!( write!(
w, w,
"{}{}", "{}{}",
field.visibility.print_with_space(cx, field.def_id), field.visibility.print_with_space(field.def_id, cx),
ty.print(cx), ty.print(cx),
) )
} }