Skip to content

Commit

Permalink
Fix off-by-one error in pattern formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusklaas committed Apr 16, 2016
1 parent 41e037d commit 63f0fc9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/patterns.rs
Expand Up @@ -76,8 +76,9 @@ impl Rewrite for Pat {
if pat_vec.is_empty() {
Some(path_str)
} else {
// 1 = (
let width = try_opt!(width.checked_sub(path_str.len() + 1));
// 2 = "()".len()
let width = try_opt!(width.checked_sub(path_str.len() + 2));
// 1 = "(".len()
let offset = offset + path_str.len() + 1;
let items = itemize_list(context.codemap,
pat_vec.iter(),
Expand Down
20 changes: 20 additions & 0 deletions tests/source/issue-913.rs
@@ -0,0 +1,20 @@
mod client {
impl Client {
fn test(self) -> Result<()> {
let next_state = match self.state {
State::V5(v5::State::Command(v5::coand::State::WriteVersion(ref mut response))) => {
let x = reformat . meeee() ;
}
};

let next_state = match self.state {
State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
// The pattern cannot be formatted in a way that the match stays
// within the column limit. The rewrite should therefore be
// skipped.
let x = dont . reformat . meeee();
}
};
}
}
}
20 changes: 20 additions & 0 deletions tests/target/issue-913.rs
@@ -0,0 +1,20 @@
mod client {
impl Client {
fn test(self) -> Result<()> {
let next_state = match self.state {
State::V5(v5::State::Command(v5::coand::State::WriteVersion(ref mut response))) => {
let x = reformat.meeee();
}
};

let next_state = match self.state {
State::V5(v5::State::Command(v5::comand::State::WriteVersion(ref mut response))) => {
// The pattern cannot be formatted in a way that the match stays
// within the column limit. The rewrite should therefore be
// skipped.
let x = dont . reformat . meeee();
}
};
}
}
}

0 comments on commit 63f0fc9

Please sign in to comment.