Skip to content

Commit

Permalink
Change pp indent to signed to allow negative indents
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Feb 3, 2022
1 parent 0b7e1ba commit 8bdf08f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_ast_pretty/src/pp.rs
Expand Up @@ -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 {
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_ast_pretty/src/pp/convenience.rs
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Expand Up @@ -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.
Expand Down

0 comments on commit 8bdf08f

Please sign in to comment.