diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /compiler/rustc_ast_pretty/src/pprust/state/item.rs | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_ast_pretty/src/pprust/state/item.rs')
-rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state/item.rs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index 3393f034b..405ccc722 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -1,8 +1,9 @@ use crate::pp::Breaks::Inconsistent; -use crate::pprust::state::delimited::IterDelimited; +use crate::pprust::state::expr::FixupContext; use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT}; use ast::StaticItem; +use itertools::{Itertools, Position}; use rustc_ast as ast; use rustc_ast::GenericBound; use rustc_ast::ModKind; @@ -20,7 +21,7 @@ impl<'a> State<'a> { } } - pub(crate) fn print_foreign_item(&mut self, item: &ast::ForeignItem) { + fn print_foreign_item(&mut self, item: &ast::ForeignItem) { let ast::Item { id, span, ident, ref attrs, ref kind, ref vis, tokens: _ } = *item; self.ann.pre(self, AnnNode::SubItem(id)); self.hardbreak_if_not_bol(); @@ -97,7 +98,7 @@ impl<'a> State<'a> { self.end(); // end the head-ibox if let Some(body) = body { self.word_space("="); - self.print_expr(body); + self.print_expr(body, FixupContext::default()); } self.print_where_clause(&generics.where_clause); self.word(";"); @@ -368,7 +369,7 @@ impl<'a> State<'a> { self.nbsp(); if !bounds.is_empty() { self.word_nbsp("="); - self.print_type_bounds(&bounds); + self.print_type_bounds(bounds); } self.print_where_clause(&generics.where_clause); self.word(";"); @@ -499,7 +500,7 @@ impl<'a> State<'a> { self.end(); self.end(); // Close the outer-box. } - ast::VariantData::Struct(fields, ..) => { + ast::VariantData::Struct { fields, .. } => { self.print_where_clause(&generics.where_clause); self.print_record_struct_body(fields, span); } @@ -514,11 +515,11 @@ impl<'a> State<'a> { if let Some(d) = &v.disr_expr { self.space(); self.word_space("="); - self.print_expr(&d.value) + self.print_expr(&d.value, FixupContext::default()) } } - pub(crate) fn print_assoc_item(&mut self, item: &ast::AssocItem) { + fn print_assoc_item(&mut self, item: &ast::AssocItem) { let ast::Item { id, span, ident, ref attrs, ref kind, ref vis, tokens: _ } = *item; self.ann.pre(self, AnnNode::SubItem(id)); self.hardbreak_if_not_bol(); @@ -621,7 +622,7 @@ impl<'a> State<'a> { self.print_where_clause_parts(where_clause.has_where_token, &where_clause.predicates); } - pub(crate) fn print_where_clause_parts( + fn print_where_clause_parts( &mut self, has_where_token: bool, predicates: &[ast::WherePredicate], @@ -668,7 +669,7 @@ impl<'a> State<'a> { } } - pub fn print_where_bound_predicate( + pub(crate) fn print_where_bound_predicate( &mut self, where_bound_predicate: &ast::WhereBoundPredicate, ) { @@ -712,9 +713,10 @@ impl<'a> State<'a> { self.word("{"); self.zerobreak(); self.ibox(0); - for use_tree in items.iter().delimited() { + for (pos, use_tree) in items.iter().with_position() { + let is_last = matches!(pos, Position::Last | Position::Only); self.print_use_tree(&use_tree.0); - if !use_tree.is_last { + if !is_last { self.word(","); if let ast::UseTreeKind::Nested(_) = use_tree.0.kind { self.hardbreak(); |