Handle non-ascii character at boundary (#5089)
* Handle non-ascii character at boundary * Replace substraction underflow check with early termination
This commit is contained in:
parent
8b0b213cdd
commit
368a9b7cef
@ -278,6 +278,9 @@ fn break_string(max_width: usize, trim_end: bool, line_end: &str, input: &[&str]
|
|||||||
}
|
}
|
||||||
cur_index
|
cur_index
|
||||||
};
|
};
|
||||||
|
if max_width_index_in_input == 0 {
|
||||||
|
return SnippetState::EndOfInput(input.concat());
|
||||||
|
}
|
||||||
|
|
||||||
// Find the position in input for breaking the string
|
// Find the position in input for breaking the string
|
||||||
if line_end.is_empty()
|
if line_end.is_empty()
|
||||||
@ -301,7 +304,7 @@ fn break_string(max_width: usize, trim_end: bool, line_end: &str, input: &[&str]
|
|||||||
return if trim_end {
|
return if trim_end {
|
||||||
SnippetState::LineEnd(input[..=url_index_end].concat(), index_plus_ws + 1)
|
SnippetState::LineEnd(input[..=url_index_end].concat(), index_plus_ws + 1)
|
||||||
} else {
|
} else {
|
||||||
return SnippetState::LineEnd(input[..=index_plus_ws].concat(), index_plus_ws + 1);
|
SnippetState::LineEnd(input[..=index_plus_ws].concat(), index_plus_ws + 1)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
tests/source/issue-5023.rs
Normal file
22
tests/source/issue-5023.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// rustfmt-wrap_comments: true
|
||||||
|
|
||||||
|
/// A comment to test special unicode characters on boundaries
|
||||||
|
/// 是,是,是,是,是,是,是,是,是,是,是,是 it should break right here this goes to the next line
|
||||||
|
fn main() {
|
||||||
|
if xxx {
|
||||||
|
let xxx = xxx
|
||||||
|
.into_iter()
|
||||||
|
.filter(|(xxx, xxx)| {
|
||||||
|
if let Some(x) = Some(1) {
|
||||||
|
// xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
|
||||||
|
// xxxxxxxxxx. xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxx xxx xxxxxxx
|
||||||
|
// 是sdfadsdfxxxxxxxxx,sdfaxxxxxx_xxxxx_masdfaonxxx,
|
||||||
|
if false {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
}
|
23
tests/target/issue-5023.rs
Normal file
23
tests/target/issue-5023.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// rustfmt-wrap_comments: true
|
||||||
|
|
||||||
|
/// A comment to test special unicode characters on boundaries
|
||||||
|
/// 是,是,是,是,是,是,是,是,是,是,是,是 it should break right here
|
||||||
|
/// this goes to the next line
|
||||||
|
fn main() {
|
||||||
|
if xxx {
|
||||||
|
let xxx = xxx
|
||||||
|
.into_iter()
|
||||||
|
.filter(|(xxx, xxx)| {
|
||||||
|
if let Some(x) = Some(1) {
|
||||||
|
// xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
|
||||||
|
// xxxxxxxxxx. xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxx xxx xxxxxxx
|
||||||
|
// 是sdfadsdfxxxxxxxxx,sdfaxxxxxx_xxxxx_masdfaonxxx,
|
||||||
|
if false {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user