Skip to content

Commit fe993db

Browse files
committed
Merge pull request #947 from marcusklaas/match-pattern-limit
Fix off-by-one error in pattern formatting
2 parents 27c91ee + 63f0fc9 commit fe993db

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/patterns.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ impl Rewrite for Pat {
7676
if pat_vec.is_empty() {
7777
Some(path_str)
7878
} else {
79-
// 1 = (
80-
let width = try_opt!(width.checked_sub(path_str.len() + 1));
79+
// 2 = "()".len()
80+
let width = try_opt!(width.checked_sub(path_str.len() + 2));
81+
// 1 = "(".len()
8182
let offset = offset + path_str.len() + 1;
8283
let items = itemize_list(context.codemap,
8384
pat_vec.iter(),

tests/source/issue-913.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
mod client {
2+
impl Client {
3+
fn test(self) -> Result<()> {
4+
let next_state = match self.state {
5+
State::V5(v5::State::Command(v5::coand::State::WriteVersion(ref mut response))) => {
6+
let x = reformat . meeee() ;
7+
}
8+
};
9+
10+
let next_state = match self.state {
11+
State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
12+
// The pattern cannot be formatted in a way that the match stays
13+
// within the column limit. The rewrite should therefore be
14+
// skipped.
15+
let x = dont . reformat . meeee();
16+
}
17+
};
18+
}
19+
}
20+
}

tests/target/issue-913.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
mod client {
2+
impl Client {
3+
fn test(self) -> Result<()> {
4+
let next_state = match self.state {
5+
State::V5(v5::State::Command(v5::coand::State::WriteVersion(ref mut response))) => {
6+
let x = reformat.meeee();
7+
}
8+
};
9+
10+
let next_state = match self.state {
11+
State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
12+
// The pattern cannot be formatted in a way that the match stays
13+
// within the column limit. The rewrite should therefore be
14+
// skipped.
15+
let x = dont . reformat . meeee();
16+
}
17+
};
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)