Skip to content

Commit de42a17

Browse files
Simplify test case for issue 5023
By replacing the code quoted from the issue with a single comment that more directly exposes the issue. This is to 1. Make the underlying issue easier to reason about 2. Make this test not behave upon the behaviour of indentation length when rewriting lines (my main motivation for this change, since it makes the followup patch simpler) This was tested by partially reverting 368a9b7 with the patch: ```patch diff --git i/src/string.rs w/src/string.rs index 3b97118..561e70ac 100644 --- i/src/string.rs +++ w/src/string.rs @@ -278,9 +278,6 @@ fn break_string(max_width: usize, trim_end: bool, line_end: &str, input: &[&str] } cur_index }; - if max_width_index_in_input == 0 { - return SnippetState::EndOfInput(input.concat()); - } // Find the position in input for breaking the string if line_end.is_empty() ``` The re-running tests, or executing `rustmft` directly on this test, triggered the panic from the original bug.
1 parent 461e7b1 commit de42a17

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

tests/source/issue-5023.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
// rustfmt-wrap_comments: true
22

3+
// below we try and force a split at a byte in the middle of a multi-byte
4+
// character. The two parts of the first line are constructed such that:
5+
// 1) the entire line is longer than `$comment_width`
6+
// 2) the length of the second part is such that:
7+
// `$comment_width - 3 + $length` is positive _and_ less than the number of
8+
// bytes in the multi-byte char
9+
10+
// xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
11+
// 是
12+
313
/// A comment to test special unicode characters on boundaries
414
/// 是,是,是,是,是,是,是,是,是,是,是,是 it should break right here this goes to the next line
5-
fn main() {
6-
if xxx {
7-
let xxx = xxx
8-
.into_iter()
9-
.filter(|(xxx, xxx)| {
10-
if let Some(x) = Some(1) {
11-
// xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
12-
// xxxxxxxxxx. xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxx xxx xxxxxxx
13-
// 是sdfadsdfxxxxxxxxx,sdfaxxxxxx_xxxxx_masdfaonxxx,
14-
if false {
15-
return true;
16-
}
17-
}
18-
false
19-
})
20-
.collect();
21-
}
22-
}
15+
fn main() {}

tests/target/issue-5023.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
// rustfmt-wrap_comments: true
22

3+
// below we try and force a split at a byte in the middle of a multi-byte
4+
// character. The two parts of the first line are constructed such that:
5+
// 1) the entire line is longer than `$comment_width`
6+
// 2) the length of the second part is such that:
7+
// `$comment_width - 3 + $length` is positive _and_ less than the number of
8+
// bytes in the multi-byte char
9+
10+
// xxxxxxxxxx
11+
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
12+
// 是
13+
314
/// A comment to test special unicode characters on boundaries
415
/// 是,是,是,是,是,是,是,是,是,是,是,是 it should break right here
516
/// this goes to the next line
6-
fn main() {
7-
if xxx {
8-
let xxx = xxx
9-
.into_iter()
10-
.filter(|(xxx, xxx)| {
11-
if let Some(x) = Some(1) {
12-
// xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
13-
// xxxxxxxxxx. xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxx xxx xxxxxxx
14-
// 是sdfadsdfxxxxxxxxx,sdfaxxxxxx_xxxxx_masdfaonxxx,
15-
if false {
16-
return true;
17-
}
18-
}
19-
false
20-
})
21-
.collect();
22-
}
23-
}
17+
fn main() {}

0 commit comments

Comments
 (0)