Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7c1ad96

Browse files
authored
Merge pull request rust-lang#2912 from topecongiro/fix-slice-pattern
Do not show wildcard pattern in slice pattern
2 parents af3c3c6 + 934cf28 commit 7c1ad96

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/patterns.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ impl Rewrite for Pat {
144144
let prefix = prefix.iter().map(|p| p.rewrite(context, shape));
145145
let slice_pat = slice_pat
146146
.as_ref()
147-
.map(|p| Some(format!("{}..", p.rewrite(context, shape)?)));
147+
.and_then(|p| p.rewrite(context, shape))
148+
.map(|rw| Some(format!("{}..", if rw == "_" { "" } else { &rw })));
148149
let suffix = suffix.iter().map(|p| p.rewrite(context, shape));
149150

150151
// Munge them together.

tests/source/pattern.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@ fn combine_patterns() {
6363
_ => return,
6464
};
6565
}
66+
67+
fn slice_patterns() {
68+
match b"123" {
69+
[0, ..] => {}
70+
[0, foo..] => {}
71+
_ => {}
72+
}
73+
}

tests/target/pattern.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,11 @@ fn combine_patterns() {
7575
_ => return,
7676
};
7777
}
78+
79+
fn slice_patterns() {
80+
match b"123" {
81+
[0, ..] => {}
82+
[0, foo..] => {}
83+
_ => {}
84+
}
85+
}

0 commit comments

Comments
 (0)