Skip to content

Commit e07a632

Browse files
committed
Remove IterDelimited.
itertools has `with_position` which does the same thing.
1 parent 826c39e commit e07a632

File tree

6 files changed

+13
-52
lines changed

6 files changed

+13
-52
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,6 +3545,7 @@ dependencies = [
35453545
name = "rustc_ast_pretty"
35463546
version = "0.0.0"
35473547
dependencies = [
3548+
"itertools",
35483549
"rustc_ast",
35493550
"rustc_span",
35503551
"thin-vec",

compiler/rustc_ast_pretty/Cargo.toml

Lines changed: 1 addition & 0 deletions
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/pprust/state.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod delimited;
21
mod expr;
32
mod item;
43

@@ -23,8 +22,6 @@ use rustc_span::{BytePos, FileName, Span, DUMMY_SP};
2322
use std::borrow::Cow;
2423
use thin_vec::ThinVec;
2524

26-
pub use self::delimited::IterDelimited;
27-
2825
pub enum MacHeader<'a> {
2926
Path(&'a ast::Path),
3027
Keyword(&'static str),

compiler/rustc_ast_pretty/src/pprust/state/delimited.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::pp::Breaks::Inconsistent;
2-
use crate::pprust::state::{AnnNode, IterDelimited, PrintState, State, INDENT_UNIT};
3-
2+
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
3+
use itertools::{Itertools, Position};
44
use rustc_ast::ptr::P;
55
use rustc_ast::token;
66
use rustc_ast::util::literal::escape_byte_str_symbol;
@@ -149,18 +149,20 @@ impl<'a> State<'a> {
149149
return;
150150
}
151151
self.cbox(0);
152-
for field in fields.iter().delimited() {
152+
for (pos, field) in fields.iter().with_position() {
153+
let is_first = matches!(pos, Position::First | Position::Only);
154+
let is_last = matches!(pos, Position::Last | Position::Only);
153155
self.maybe_print_comment(field.span.hi());
154156
self.print_outer_attributes(&field.attrs);
155-
if field.is_first {
157+
if is_first {
156158
self.space_if_not_bol();
157159
}
158160
if !field.is_shorthand {
159161
self.print_ident(field.ident);
160162
self.word_nbsp(":");
161163
}
162164
self.print_expr(&field.expr);
163-
if !field.is_last || has_rest {
165+
if !is_last || has_rest {
164166
self.word_space(",");
165167
} else {
166168
self.trailing_comma_or_space();

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::pp::Breaks::Inconsistent;
2-
use crate::pprust::state::delimited::IterDelimited;
32
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
43

54
use ast::StaticItem;
5+
use itertools::{Itertools, Position};
66
use rustc_ast as ast;
77
use rustc_ast::GenericBound;
88
use rustc_ast::ModKind;
@@ -712,9 +712,10 @@ impl<'a> State<'a> {
712712
self.word("{");
713713
self.zerobreak();
714714
self.ibox(0);
715-
for use_tree in items.iter().delimited() {
715+
for (pos, use_tree) in items.iter().with_position() {
716+
let is_last = matches!(pos, Position::Last | Position::Only);
716717
self.print_use_tree(&use_tree.0);
717-
if !use_tree.is_last {
718+
if !is_last {
718719
self.word(",");
719720
if let ast::UseTreeKind::Nested(_) = use_tree.0.kind {
720721
self.hardbreak();

0 commit comments

Comments
 (0)