.collect::<Option<Vec<_>>>());
let all_simple = pat_strs.iter().all(|p| pat_is_simple(&p));
- let items: Vec<_> = pat_strs.into_iter().map(|s| ListItem::from_str(s)).collect();
+ let items: Vec<_> = pat_strs.into_iter().map(ListItem::from_str).collect();
let fmt = ListFormatting {
tactic: if all_simple {
DefinitiveListTactic::Mixed
};
try_opt!(format_function_type(data.inputs.iter().map(|x| &**x),
&output,
+ false,
data.span,
context,
width,
fn format_function_type<'a, I>(inputs: I,
output: &FunctionRetTy,
+ variadic: bool,
span: Span,
context: &RewriteContext,
width: usize,
<I as Iterator>::Item: Deref,
<I::Item as Deref>::Target: Rewrite + Spanned + 'a
{
+ // Code for handling variadics is somewhat duplicated for items, but they
+ // are different enough to need some serious refactoring to share code.
+ enum ArgumentKind<T>
+ where T: Deref,
+ <T as Deref>::Target: Rewrite + Spanned
+ {
+ Regular(Box<T>),
+ Variadic(BytePos),
+ }
+
+ let variadic_arg = if variadic {
+ let variadic_start = context.codemap.span_before(span, "...");
+ Some(ArgumentKind::Variadic(variadic_start))
+ } else {
+ None
+ };
+
// 2 for ()
let budget = try_opt!(width.checked_sub(2));
// 1 for (
let offset = offset + 1;
let list_lo = context.codemap.span_after(span, "(");
let items = itemize_list(context.codemap,
- inputs,
+ // FIXME Would be nice to avoid this allocation,
+ // but I couldn't get the types to work out.
+ inputs.map(|i| ArgumentKind::Regular(Box::new(i)))
+ .chain(variadic_arg),
")",
- |ty| ty.span().lo,
- |ty| ty.span().hi,
- |ty| ty.rewrite(context, budget, offset),
+ |arg| {
+ match *arg {
+ ArgumentKind::Regular(ref ty) => ty.span().lo,
+ ArgumentKind::Variadic(start) => start,
+ }
+ },
+ |arg| {
+ match *arg {
+ ArgumentKind::Regular(ref ty) => ty.span().hi,
+ ArgumentKind::Variadic(start) => start + BytePos(3),
+ }
+ },
+ |arg| {
+ match *arg {
+ ArgumentKind::Regular(ref ty) => {
+ ty.rewrite(context, budget, offset)
+ }
+ ArgumentKind::Variadic(_) => Some("...".to_owned()),
+ }
+ },
list_lo,
span.hi);
let rewrite = try_opt!(format_function_type(bare_fn.decl.inputs.iter(),
&bare_fn.decl.output,
+ bare_fn.decl.variadic,
span,
context,
budget,
let z: (/*#digits*/ usize, /*exp*/ i16) = funk();
let z: ( usize /*#digits*/ , i16 /*exp*/ ) = funk();
}
+
+struct F {
+ f: extern "C" fn(x: u8, ... /* comment */),
+ g: extern "C" fn(x: u8,/* comment */ ...),
+ h: extern "C" fn(x: u8, ... ),
+ i: extern "C" fn(x: u8, /* comment 4*/ y: String, // comment 3
+ z: Foo, /* comment */ .../* comment 2*/ ),
+}
i16) = funk();
let z: (usize /* #digits */, i16 /* exp */) = funk();
}
+
+struct F {
+ f: extern "C" fn(x: u8, ... /* comment */),
+ g: extern "C" fn(x: u8,
+ // comment
+ ...),
+ h: extern "C" fn(x: u8, ...),
+ i: extern "C" fn(x: u8,
+ // comment 4
+ y: String, // comment 3
+ z: Foo,
+ // comment
+ ... /* comment 2 */),
+}