Merge pull request #2195 from topecongiro/issue-2193

Take into account a trailing comma on variant
This commit is contained in:
Nick Cameron 2017-11-28 08:57:31 +13:00 committed by GitHub
commit 458eade4a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 14 deletions

View file

@ -533,8 +533,8 @@ impl<'a> FmtVisitor<'a> {
}
let context = self.get_context();
let indent = self.block_indent;
let shape = self.shape();
// 1 = ','
let shape = self.shape().sub_width(1)?;
let attrs_str = field.node.attrs.rewrite(&context, shape)?;
let lo = field
.node
@ -544,19 +544,15 @@ impl<'a> FmtVisitor<'a> {
let span = mk_sp(lo, field.span.lo());
let variant_body = match field.node.data {
ast::VariantData::Tuple(..) | ast::VariantData::Struct(..) => {
// FIXME: Should limit the width, as we have a trailing comma
format_struct(
&context,
&StructParts::from_variant(field),
indent,
Some(one_line_width),
)?
}
ast::VariantData::Tuple(..) | ast::VariantData::Struct(..) => format_struct(
&context,
&StructParts::from_variant(field),
self.block_indent,
Some(one_line_width),
)?,
ast::VariantData::Unit(..) => if let Some(ref expr) = field.node.disr_expr {
let lhs = format!("{} =", field.node.name);
// 1 = ','
rewrite_assign_rhs(&context, lhs, &**expr, shape.sub_width(1)?)?
rewrite_assign_rhs(&context, lhs, &**expr, shape)?
} else {
field.node.name.to_string()
},
@ -1312,7 +1308,7 @@ fn format_tuple_struct(
}
result.push(')');
} else {
let shape = Shape::indented(offset, context.config);
let shape = Shape::indented(offset, context.config).sub_width(1)?;
let fields = &fields.iter().map(|field| field).collect::<Vec<_>>()[..];
let one_line_width = context.config.width_heuristics().fn_call_width;
result = rewrite_call_inner(context, &result, fields, span, shape, one_line_width, false)?;

View file

@ -172,3 +172,11 @@ enum AnError {
#[fail(display = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")]
UnexpectedSingleToken { token: syn::Token },
}
// #2193
enum WidthOf101 {
#[fail(display = ".....................................................")] Io(::std::io::Error),
#[fail(display = ".....................................................")] Ioo(::std::io::Error),
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(::std::io::Error),
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(::std::io::Error),
}

View file

@ -222,3 +222,14 @@ enum AnError {
#[fail(display = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")]
UnexpectedSingleToken { token: syn::Token },
}
// #2193
enum WidthOf101 {
#[fail(display = ".....................................................")] Io(::std::io::Error),
#[fail(display = ".....................................................")]
Ioo(::std::io::Error),
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(::std::io::Error),
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
::std::io::Error,
),
}