Skip to content

Commit 8bdf08f

Browse files
committed
Change pp indent to signed to allow negative indents
1 parent 0b7e1ba commit 8bdf08f

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

compiler/rustc_ast_pretty/src/pp.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ impl Printer {
392392
if size > self.space {
393393
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
394394
self.indent = match token.indent {
395-
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
395+
IndentStyle::Block { offset } => {
396+
usize::try_from(self.indent as isize + offset).unwrap()
397+
}
396398
IndentStyle::Visual => (MARGIN - self.space) as usize,
397399
};
398400
} else {

compiler/rustc_ast_pretty/src/pp/convenience.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ use std::borrow::Cow;
33

44
impl Printer {
55
/// "raw box"
6-
pub fn rbox(&mut self, indent: usize, breaks: Breaks) {
7-
self.scan_begin(BeginToken {
8-
indent: IndentStyle::Block { offset: indent as isize },
9-
breaks,
10-
})
6+
pub fn rbox(&mut self, indent: isize, breaks: Breaks) {
7+
self.scan_begin(BeginToken { indent: IndentStyle::Block { offset: indent }, breaks })
118
}
129

1310
/// Inconsistent breaking box
14-
pub fn ibox(&mut self, indent: usize) {
11+
pub fn ibox(&mut self, indent: isize) {
1512
self.rbox(indent, Breaks::Inconsistent)
1613
}
1714

1815
/// Consistent breaking box
19-
pub fn cbox(&mut self, indent: usize) {
16+
pub fn cbox(&mut self, indent: isize) {
2017
self.rbox(indent, Breaks::Consistent)
2118
}
2219

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub struct State<'a> {
9292
ann: &'a (dyn PpAnn + 'a),
9393
}
9494

95-
crate const INDENT_UNIT: usize = 4;
95+
crate const INDENT_UNIT: isize = 4;
9696

9797
/// Requires you to pass an input filename and reader so that
9898
/// it can scan the input text for comments to copy forward.

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a> PrintState<'a> for State<'a> {
139139
}
140140
}
141141

142-
pub const INDENT_UNIT: usize = 4;
142+
pub const INDENT_UNIT: isize = 4;
143143

144144
/// Requires you to pass an input filename and reader so that
145145
/// it can scan the input text for comments to copy forward.

0 commit comments

Comments
 (0)