Change pp indent to signed to allow negative indents
This commit is contained in:
parent
0b7e1baa58
commit
8bdf08fbed
@ -392,7 +392,9 @@ impl Printer {
|
||||
if size > self.space {
|
||||
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
|
||||
self.indent = match token.indent {
|
||||
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
|
||||
IndentStyle::Block { offset } => {
|
||||
usize::try_from(self.indent as isize + offset).unwrap()
|
||||
}
|
||||
IndentStyle::Visual => (MARGIN - self.space) as usize,
|
||||
};
|
||||
} else {
|
||||
|
@ -3,20 +3,17 @@ use std::borrow::Cow;
|
||||
|
||||
impl Printer {
|
||||
/// "raw box"
|
||||
pub fn rbox(&mut self, indent: usize, breaks: Breaks) {
|
||||
self.scan_begin(BeginToken {
|
||||
indent: IndentStyle::Block { offset: indent as isize },
|
||||
breaks,
|
||||
})
|
||||
pub fn rbox(&mut self, indent: isize, breaks: Breaks) {
|
||||
self.scan_begin(BeginToken { indent: IndentStyle::Block { offset: indent }, breaks })
|
||||
}
|
||||
|
||||
/// Inconsistent breaking box
|
||||
pub fn ibox(&mut self, indent: usize) {
|
||||
pub fn ibox(&mut self, indent: isize) {
|
||||
self.rbox(indent, Breaks::Inconsistent)
|
||||
}
|
||||
|
||||
/// Consistent breaking box
|
||||
pub fn cbox(&mut self, indent: usize) {
|
||||
pub fn cbox(&mut self, indent: isize) {
|
||||
self.rbox(indent, Breaks::Consistent)
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ pub struct State<'a> {
|
||||
ann: &'a (dyn PpAnn + 'a),
|
||||
}
|
||||
|
||||
crate const INDENT_UNIT: usize = 4;
|
||||
crate const INDENT_UNIT: isize = 4;
|
||||
|
||||
/// Requires you to pass an input filename and reader so that
|
||||
/// it can scan the input text for comments to copy forward.
|
||||
|
@ -139,7 +139,7 @@ impl<'a> PrintState<'a> for State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub const INDENT_UNIT: usize = 4;
|
||||
pub const INDENT_UNIT: isize = 4;
|
||||
|
||||
/// Requires you to pass an input filename and reader so that
|
||||
/// it can scan the input text for comments to copy forward.
|
||||
|
Loading…
x
Reference in New Issue
Block a user