Skip to content

Commit cc4bb0d

Browse files
committed
Auto merge of #117928 - nnethercote:rustc_ast_pretty, r=fee1-dead
`rustc_ast_pretty` cleanups Some improvements I found while looking at this code. r? `@fee1-dead`
2 parents 739d556 + 6686221 commit cc4bb0d

File tree

27 files changed

+183
-240
lines changed

27 files changed

+183
-240
lines changed

Cargo.lock

+3-2
Original file line numberDiff line numberDiff line change
@@ -2060,9 +2060,9 @@ dependencies = [
20602060

20612061
[[package]]
20622062
name = "itertools"
2063-
version = "0.10.5"
2063+
version = "0.11.0"
20642064
source = "registry+https://github.com/rust-lang/crates.io-index"
2065-
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
2065+
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
20662066
dependencies = [
20672067
"either",
20682068
]
@@ -3471,6 +3471,7 @@ dependencies = [
34713471
name = "rustc_ast_pretty"
34723472
version = "0.0.0"
34733473
dependencies = [
3474+
"itertools",
34743475
"rustc_ast",
34753476
"rustc_span",
34763477
"thin-vec",

compiler/rustc_ast_passes/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
itertools = "0.10.1"
8+
itertools = "0.11"
99
rustc_ast = { path = "../rustc_ast" }
1010
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1111
rustc_attr = { path = "../rustc_attr" }

compiler/rustc_ast_pretty/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
itertools = "0.11"
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_span = { path = "../rustc_span" }
1011
thin-vec = "0.2.12"

compiler/rustc_ast_pretty/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#![doc(rust_logo)]
44
#![deny(rustc::untranslatable_diagnostic)]
55
#![deny(rustc::diagnostic_outside_of_impl)]
6-
#![feature(associated_type_bounds)]
76
#![feature(box_patterns)]
8-
#![feature(with_negative_coherence)]
97
#![recursion_limit = "256"]
108

119
mod helpers;

compiler/rustc_ast_pretty/src/pp.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,20 @@ enum IndentStyle {
165165
}
166166

167167
#[derive(Clone, Copy, Default, PartialEq)]
168-
pub struct BreakToken {
168+
pub(crate) struct BreakToken {
169169
offset: isize,
170170
blank_space: isize,
171171
pre_break: Option<char>,
172172
}
173173

174174
#[derive(Clone, Copy, PartialEq)]
175-
pub struct BeginToken {
175+
pub(crate) struct BeginToken {
176176
indent: IndentStyle,
177177
breaks: Breaks,
178178
}
179179

180-
#[derive(Clone, PartialEq)]
181-
pub enum Token {
180+
#[derive(PartialEq)]
181+
pub(crate) enum Token {
182182
// In practice a string token contains either a `&'static str` or a
183183
// `String`. `Cow` is overkill for this because we never modify the data,
184184
// but it's more convenient than rolling our own more specialized type.
@@ -229,7 +229,6 @@ pub struct Printer {
229229
last_printed: Option<Token>,
230230
}
231231

232-
#[derive(Clone)]
233232
struct BufEntry {
234233
token: Token,
235234
size: isize,
@@ -251,16 +250,16 @@ impl Printer {
251250
}
252251
}
253252

254-
pub fn last_token(&self) -> Option<&Token> {
253+
pub(crate) fn last_token(&self) -> Option<&Token> {
255254
self.last_token_still_buffered().or_else(|| self.last_printed.as_ref())
256255
}
257256

258-
pub fn last_token_still_buffered(&self) -> Option<&Token> {
257+
pub(crate) fn last_token_still_buffered(&self) -> Option<&Token> {
259258
self.buf.last().map(|last| &last.token)
260259
}
261260

262261
/// Be very careful with this!
263-
pub fn replace_last_token_still_buffered(&mut self, token: Token) {
262+
pub(crate) fn replace_last_token_still_buffered(&mut self, token: Token) {
264263
self.buf.last_mut().unwrap().token = token;
265264
}
266265

@@ -314,7 +313,7 @@ impl Printer {
314313
}
315314
}
316315

317-
pub fn offset(&mut self, offset: isize) {
316+
pub(crate) fn offset(&mut self, offset: isize) {
318317
if let Some(BufEntry { token: Token::Break(token), .. }) = &mut self.buf.last_mut() {
319318
token.offset += offset;
320319
}

compiler/rustc_ast_pretty/src/pp/convenience.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Printer {
6666
}
6767
}
6868

69-
pub fn hardbreak_tok_offset(off: isize) -> Token {
69+
pub(crate) fn hardbreak_tok_offset(off: isize) -> Token {
7070
Token::Break(BreakToken {
7171
offset: off,
7272
blank_space: SIZE_INFINITY,

0 commit comments

Comments
 (0)