Skip to content

Commit 368a9b7

Browse files
authored
Handle non-ascii character at boundary (#5089)
* Handle non-ascii character at boundary * Replace substraction underflow check with early termination
1 parent 8b0b213 commit 368a9b7

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Diff for: src/string.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ fn break_string(max_width: usize, trim_end: bool, line_end: &str, input: &[&str]
278278
}
279279
cur_index
280280
};
281+
if max_width_index_in_input == 0 {
282+
return SnippetState::EndOfInput(input.concat());
283+
}
281284

282285
// Find the position in input for breaking the string
283286
if line_end.is_empty()
@@ -301,7 +304,7 @@ fn break_string(max_width: usize, trim_end: bool, line_end: &str, input: &[&str]
301304
return if trim_end {
302305
SnippetState::LineEnd(input[..=url_index_end].concat(), index_plus_ws + 1)
303306
} else {
304-
return SnippetState::LineEnd(input[..=index_plus_ws].concat(), index_plus_ws + 1);
307+
SnippetState::LineEnd(input[..=index_plus_ws].concat(), index_plus_ws + 1)
305308
};
306309
}
307310

Diff for: tests/source/issue-5023.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// rustfmt-wrap_comments: true
2+
3+
/// A comment to test special unicode characters on boundaries
4+
/// 是,是,是,是,是,是,是,是,是,是,是,是 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+
}

Diff for: tests/target/issue-5023.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// rustfmt-wrap_comments: true
2+
3+
/// A comment to test special unicode characters on boundaries
4+
/// 是,是,是,是,是,是,是,是,是,是,是,是 it should break right here
5+
/// 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+
}

0 commit comments

Comments
 (0)