Skip to content

Commit f27349a

Browse files
committed
Wrap long array and slice patterns.
Closes rust-lang#4530.
1 parent 7aa69e5 commit f27349a

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

src/overflow.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub(crate) enum OverflowableItem<'a> {
7777
FieldDef(&'a ast::FieldDef),
7878
TuplePatField(&'a TuplePatField<'a>),
7979
Ty(&'a ast::Ty),
80+
Pat(&'a ast::Pat),
8081
}
8182

8283
impl<'a> Rewrite for OverflowableItem<'a> {
@@ -116,6 +117,7 @@ impl<'a> OverflowableItem<'a> {
116117
OverflowableItem::FieldDef(sf) => f(*sf),
117118
OverflowableItem::TuplePatField(pat) => f(*pat),
118119
OverflowableItem::Ty(ty) => f(*ty),
120+
OverflowableItem::Pat(pat) => f(*pat),
119121
}
120122
}
121123

@@ -232,7 +234,7 @@ macro_rules! impl_into_overflowable_item_for_rustfmt_types {
232234
}
233235
}
234236

235-
impl_into_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, FieldDef, Ty);
237+
impl_into_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, FieldDef, Ty, Pat);
236238
impl_into_overflowable_item_for_rustfmt_types!([MacroArg], [SegmentParam, TuplePatField]);
237239

238240
pub(crate) fn into_overflowable_list<'a, T>(

src/patterns.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ impl Rewrite for Pat {
232232
}
233233
PatKind::Lit(ref expr) => expr.rewrite(context, shape),
234234
PatKind::Slice(ref slice_pat) => {
235+
/*
235236
let rw: Vec<String> = slice_pat
236237
.iter()
237238
.map(|p| {
@@ -242,7 +243,16 @@ impl Rewrite for Pat {
242243
}
243244
})
244245
.collect();
245-
Some(format!("[{}]", rw.join(", ")))
246+
*/
247+
overflow::rewrite_with_square_brackets(
248+
context,
249+
"",
250+
slice_pat.iter(),
251+
shape,
252+
self.span,
253+
None,
254+
None,
255+
)
246256
}
247257
PatKind::Struct(ref qself, ref path, ref fields, ellipsis) => {
248258
rewrite_struct_pat(qself, path, fields, ellipsis, self.span, context, shape)

tests/source/issue-4530.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let [aaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, ddddddddddddddddddddddddd] = panic!();
3+
}

tests/target/issue-4530.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let [
3+
aaaaaaaaaaaaaaaaaaaaaaaaaa,
4+
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
5+
cccccccccccccccccccccccccc,
6+
ddddddddddddddddddddddddd,
7+
] = panic!();
8+
}

0 commit comments

Comments
 (0)