Skip to content

Commit a78da55

Browse files
committed
don't break on consecutive punctuations
1 parent c65ba14 commit a78da55

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/string.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,21 @@ fn is_valid_linebreak(input: &[&str], pos: usize) -> bool {
343343
return true;
344344
}
345345
let is_punctuation = is_punctuation(input[pos]);
346-
if is_punctuation && !is_part_of_type(input, pos) {
346+
if is_punctuation && !is_double_punctuation(input, pos) {
347347
return true;
348348
}
349349
false
350350
}
351351

352-
fn is_part_of_type(input: &[&str], pos: usize) -> bool {
353-
input.get(pos..=pos + 1) == Some(&[":", ":"])
354-
|| input.get(pos.saturating_sub(1)..=pos) == Some(&[":", ":"])
352+
fn is_double_punctuation(input: &[&str], pos: usize) -> bool {
353+
input
354+
.get(pos..=pos + 1)
355+
.map(|slice| slice.iter().all(|cha| is_punctuation(cha)))
356+
.unwrap_or(false)
357+
|| input
358+
.get(pos.saturating_sub(1)..=pos)
359+
.map(|slice| slice.iter().all(|cha| is_punctuation(cha)))
360+
.unwrap_or(false)
355361
}
356362

357363
fn is_new_line(grapheme: &str) -> bool {

tests/source/issue-5260.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ fn documented_with_verylongtype() {
1212
// on the type when `wrap_comments = true`
1313
}
1414

15+
/// So many stars ************************************************************************
16+
fn documented_with_many_stars() {
17+
// # don't break consecutive punctuations
18+
}

tests/target/issue-5260.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ fn documented_with_verylongtype() {
1111
// # We're using a long type link, rustfmt should not break line
1212
// on the type when `wrap_comments = true`
1313
}
14+
15+
/// So many stars
16+
/// ************************************************************************
17+
fn documented_with_many_stars() {
18+
// # don't break consecutive punctuations
19+
}

0 commit comments

Comments
 (0)