From 755b4fb02b2a1fcc7d1e2163d1b4b370699788c9 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 16 Apr 2021 12:29:35 -0700 Subject: [PATCH] rustdoc: move the cx argument to the end of the list This should help make things consistent. --- src/librustdoc/html/format.rs | 26 +++++++++---------- src/librustdoc/html/render/mod.rs | 8 +++--- src/librustdoc/html/render/print_item.rs | 32 ++++++++++++------------ 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index c65ad738a9d..ca364b9f103 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -125,8 +125,8 @@ fn comma_sep(items: impl Iterator) -> impl fmt::Displ } crate fn print_generic_bounds<'a, 'tcx: 'a>( - cx: &'a Context<'tcx>, bounds: &'a [clean::GenericBound], + cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { display_fn(move |f| { let mut bounds_dup = FxHashSet::default(); @@ -155,9 +155,9 @@ impl clean::GenericParamDef { if !bounds.is_empty() { if f.alternate() { - write!(f, ": {:#}", print_generic_bounds(cx, bounds))?; + write!(f, ": {:#}", print_generic_bounds(bounds, cx))?; } else { - write!(f, ": {}", print_generic_bounds(cx, bounds))?; + write!(f, ": {}", print_generic_bounds(bounds, cx))?; } } @@ -239,13 +239,13 @@ crate fn print_where_clause<'a, 'tcx: 'a>( clause.push_str(&format!( "{:#}: {:#}", ty.print(cx), - print_generic_bounds(cx, bounds) + print_generic_bounds(bounds, cx) )); } else { clause.push_str(&format!( "{}: {}", 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) => { if f.alternate() { - write!(f, "impl {:#}", print_generic_bounds(cx, bounds)) + write!(f, "impl {:#}", print_generic_bounds(bounds, cx)) } 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_ } => { @@ -1013,21 +1013,21 @@ impl clean::FnDecl { /// * `asyncness`: Whether the function is async or not. crate fn full_print<'a, 'tcx: 'a>( &'a self, - cx: &'a Context<'tcx>, 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(cx, header_len, indent, asyncness, f)) + display_fn(move |f| self.inner_full_print(header_len, indent, asyncness, f, cx)) } fn inner_full_print( &self, - cx: &Context<'_>, header_len: usize, indent: usize, asyncness: hir::IsAsync, f: &mut fmt::Formatter<'_>, + cx: &Context<'_>, ) -> fmt::Result { let amp = if f.alternate() { "&" } else { "&" }; let mut args = String::new(); @@ -1134,8 +1134,8 @@ impl clean::FnDecl { impl clean::Visibility { crate fn print_with_space<'a, 'tcx: 'a>( self, - cx: &'a Context<'tcx>, item_did: DefId, + cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { let to_print = match self { clean::Public => "pub ".to_owned(), @@ -1320,9 +1320,9 @@ impl clean::TypeBinding { clean::TypeBindingKind::Constraint { ref bounds } => { if !bounds.is_empty() { if f.alternate() { - write!(f, ": {:#}", print_generic_bounds(cx, bounds))?; + write!(f, ": {:#}", print_generic_bounds(bounds, cx))?; } else { - write!(f, ": {}", print_generic_bounds(cx, bounds))?; + write!(f, ": {}", print_generic_bounds(bounds, cx))?; } } } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 9bd4f57051c..d10b612a737 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -815,7 +815,7 @@ fn assoc_const( w, "{}{}const {}: {}", 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), it.name.as_ref().unwrap(), ty.print(cx) @@ -839,7 +839,7 @@ fn assoc_type( it.name.as_ref().unwrap() ); if !bounds.is_empty() { - write!(w, ": {}", print_generic_bounds(cx, bounds)) + write!(w, ": {}", print_generic_bounds(bounds, cx)) } if let Some(default) = default { write!(w, " = {}", default.print(cx)) @@ -910,7 +910,7 @@ fn render_assoc_item( .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 asyncness = header.asyncness.print_with_space(); let unsafety = header.unsafety.print_with_space(); @@ -952,7 +952,7 @@ fn render_assoc_item( href = href, name = name, 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), where_clause = print_where_clause(g, cx, indent, end_newline), ) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 3b939a255a4..42b79503017 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -267,14 +267,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl Some(ref src) => write!( w, "{}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), myitem.name.as_ref().unwrap(), ), None => write!( w, "{}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), ), } @@ -285,7 +285,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl write!( w, "{}{}", - myitem.visibility.print_with_space(cx, myitem.def_id), + myitem.visibility.print_with_space(myitem.def_id, 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) { let header_len = format!( "{}{}{}{}{:#}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.asyncness.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, "{vis}{constness}{asyncness}{unsafety}{abi}fn \ {name}{generics}{decl}{notable_traits}{where_clause}", - 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(), asyncness = f.header.asyncness.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(), generics = f.generics.print(cx), 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), ); document(w, cx, it, None) @@ -429,7 +429,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra write!( w, "{}{}{}trait {}{}{}", - it.visibility.print_with_space(cx, it.def_id), + it.visibility.print_with_space(it.def_id, cx), t.unsafety.print_with_space(), if t.is_auto { "auto " } else { "" }, it.name.as_ref().unwrap(), @@ -848,7 +848,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum write!( w, "{}enum {}{}{}", - it.visibility.print_with_space(cx, it.def_id), + it.visibility.print_with_space(it.def_id, cx), it.name.as_ref().unwrap(), e.generics.print(cx), 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!( w, "{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(), typ = c.type_.print(cx), ); @@ -1116,7 +1116,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St write!( w, "{vis}static {mutability}{name}: {typ}", - 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(), name = it.name.as_ref().unwrap(), typ = s.type_.print(cx) @@ -1130,7 +1130,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { write!( w, " {}type {};\n}}", - it.visibility.print_with_space(cx, it.def_id), + it.visibility.print_with_space(it.def_id, cx), it.name.as_ref().unwrap(), ); @@ -1289,7 +1289,7 @@ fn render_union( write!( w, "{}{}{}", - it.visibility.print_with_space(cx, it.def_id), + it.visibility.print_with_space(it.def_id, cx), if structhead { "union " } else { "" }, it.name.as_ref().unwrap() ); @@ -1311,7 +1311,7 @@ fn render_union( write!( w, " {}{}: {},\n{}", - field.visibility.print_with_space(cx, field.def_id), + field.visibility.print_with_space(field.def_id, cx), field.name.as_ref().unwrap(), ty.print(cx), tab @@ -1341,7 +1341,7 @@ fn render_struct( write!( w, "{}{}{}", - it.visibility.print_with_space(cx, it.def_id), + it.visibility.print_with_space(it.def_id, cx), if structhead { "struct " } else { "" }, it.name.as_ref().unwrap() ); @@ -1367,7 +1367,7 @@ fn render_struct( w, "\n{} {}{}: {},", tab, - field.visibility.print_with_space(cx, field.def_id), + field.visibility.print_with_space(field.def_id, cx), field.name.as_ref().unwrap(), ty.print(cx), ); @@ -1401,7 +1401,7 @@ fn render_struct( write!( w, "{}{}", - field.visibility.print_with_space(cx, field.def_id), + field.visibility.print_with_space(field.def_id, cx), ty.print(cx), ) }