mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-12 20:16:49 +00:00
Fix integer underflow in extra_offset
This commit is contained in:
parent
931e71eb43
commit
88fdf9a6e3
@ -23,11 +23,10 @@ use rewrite::{Rewrite, RewriteContext};
|
||||
use SKIP_ANNOTATION;
|
||||
|
||||
// Computes the length of a string's last line, minus offset.
|
||||
#[inline]
|
||||
pub fn extra_offset(text: &str, offset: Indent) -> usize {
|
||||
match text.rfind('\n') {
|
||||
// 1 for newline character
|
||||
Some(idx) => text.len() - idx - 1 - offset.width(),
|
||||
Some(idx) => text.len().checked_sub(idx + 1 + offset.width()).unwrap_or(0),
|
||||
None => text.len(),
|
||||
}
|
||||
}
|
||||
|
4
tests/target/issue-1055.rs
Normal file
4
tests/target/issue-1055.rs
Normal file
@ -0,0 +1,4 @@
|
||||
fn issue_1055() {
|
||||
let foo = (|| {
|
||||
})();
|
||||
}
|
Loading…
Reference in New Issue
Block a user