diff --git a/src/overflow.rs b/src/overflow.rs index e32213467a5..ac24181c780 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -77,6 +77,7 @@ pub(crate) enum OverflowableItem<'a> { FieldDef(&'a ast::FieldDef), TuplePatField(&'a TuplePatField<'a>), Ty(&'a ast::Ty), + Pat(&'a ast::Pat), } impl<'a> Rewrite for OverflowableItem<'a> { @@ -116,6 +117,7 @@ impl<'a> OverflowableItem<'a> { OverflowableItem::FieldDef(sf) => f(*sf), OverflowableItem::TuplePatField(pat) => f(*pat), OverflowableItem::Ty(ty) => f(*ty), + OverflowableItem::Pat(pat) => f(*pat), } } @@ -232,7 +234,7 @@ macro_rules! impl_into_overflowable_item_for_rustfmt_types { } } -impl_into_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, FieldDef, Ty); +impl_into_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, FieldDef, Ty, Pat); impl_into_overflowable_item_for_rustfmt_types!([MacroArg], [SegmentParam, TuplePatField]); pub(crate) fn into_overflowable_list<'a, T>( diff --git a/src/patterns.rs b/src/patterns.rs index 0c6a6f3e814..35d5210cd5a 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -232,17 +232,15 @@ impl Rewrite for Pat { } PatKind::Lit(ref expr) => expr.rewrite(context, shape), PatKind::Slice(ref slice_pat) => { - let rw: Vec = slice_pat - .iter() - .map(|p| { - if let Some(rw) = p.rewrite(context, shape) { - rw - } else { - context.snippet(p.span).to_string() - } - }) - .collect(); - Some(format!("[{}]", rw.join(", "))) + overflow::rewrite_with_square_brackets( + context, + "", + slice_pat.iter(), + shape, + self.span, + None, + None, + ) } PatKind::Struct(ref qself, ref path, ref fields, ellipsis) => { rewrite_struct_pat(qself, path, fields, ellipsis, self.span, context, shape) diff --git a/tests/source/issue-4530.rs b/tests/source/issue-4530.rs new file mode 100644 index 00000000000..3d39329daab --- /dev/null +++ b/tests/source/issue-4530.rs @@ -0,0 +1,3 @@ +fn main() { + let [aaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, ddddddddddddddddddddddddd] = panic!(); +} diff --git a/tests/target/issue-4530.rs b/tests/target/issue-4530.rs new file mode 100644 index 00000000000..3e4e2b6544e --- /dev/null +++ b/tests/target/issue-4530.rs @@ -0,0 +1,8 @@ +fn main() { + let [ + aaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccc, + ddddddddddddddddddddddddd, + ] = panic!(); +}