diff options
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust/state/expr.rs')
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state/expr.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index edbc3500373..ed9b68a1d5a 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -1,6 +1,6 @@ use crate::pp::Breaks::Inconsistent; -use crate::pprust::state::{AnnNode, IterDelimited, PrintState, State, INDENT_UNIT}; - +use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT}; +use itertools::{Itertools, Position}; use rustc_ast::ptr::P; use rustc_ast::token; use rustc_ast::util::literal::escape_byte_str_symbol; @@ -149,10 +149,12 @@ impl<'a> State<'a> { return; } self.cbox(0); - for field in fields.iter().delimited() { + for (pos, field) in fields.iter().with_position() { + let is_first = matches!(pos, Position::First | Position::Only); + let is_last = matches!(pos, Position::Last | Position::Only); self.maybe_print_comment(field.span.hi()); self.print_outer_attributes(&field.attrs); - if field.is_first { + if is_first { self.space_if_not_bol(); } if !field.is_shorthand { @@ -160,7 +162,7 @@ impl<'a> State<'a> { self.word_nbsp(":"); } self.print_expr(&field.expr); - if !field.is_last || has_rest { + if !is_last || has_rest { self.word_space(","); } else { self.trailing_comma_or_space(); @@ -279,7 +281,7 @@ impl<'a> State<'a> { self.print_expr_maybe_paren(expr, parser::PREC_PREFIX) } - pub fn print_expr(&mut self, expr: &ast::Expr) { + pub(super) fn print_expr(&mut self, expr: &ast::Expr) { self.print_expr_outer_attr_style(expr, true) } @@ -679,7 +681,7 @@ impl<'a> State<'a> { } } -pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> String { +fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> String { let mut template = "\"".to_string(); for piece in pieces { match piece { |
