Allow any line to have at least 60 chars

This commit is contained in:
David Tolnay 2022-01-31 10:56:57 -08:00
parent 67259e74a4
commit 6db97b35d8
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -136,6 +136,7 @@ mod ring;
use ring::RingBuffer; use ring::RingBuffer;
use std::borrow::Cow; use std::borrow::Cow;
use std::cmp;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::iter; use std::iter;
@ -201,6 +202,8 @@ const SIZE_INFINITY: isize = 0xffff;
/// Target line width. /// Target line width.
const MARGIN: isize = 78; const MARGIN: isize = 78;
/// Every line is allowed at least this much space, even if highly indented.
const MIN_SPACE: isize = 60;
pub struct Printer { pub struct Printer {
out: String, out: String,
@ -420,7 +423,7 @@ impl Printer {
self.out.push('\n'); self.out.push('\n');
let indent = self.indent as isize + token.offset; let indent = self.indent as isize + token.offset;
self.pending_indentation = indent; self.pending_indentation = indent;
self.space = MARGIN - indent; self.space = cmp::max(MARGIN - indent, MIN_SPACE);
} }
} }