From a0b8e894564662a0eeee0d6230a83c82c1ef5da7 Mon Sep 17 00:00:00 2001 From: CoCo-Japan-pan <115922543+CoCo-Japan-pan@users.noreply.github.com> Date: Sun, 19 Apr 2026 00:01:43 +0900 Subject: [PATCH] Update AST pretty printing --- compiler/rustc_ast/src/ast.rs | 2 +- compiler/rustc_ast_lowering/src/item.rs | 2 +- compiler/rustc_ast_pretty/src/pprust/state/item.rs | 4 ++-- compiler/rustc_parse/src/parser/item.rs | 2 +- src/tools/clippy/clippy_utils/src/ast_utils/mod.rs | 8 ++++---- src/tools/rustfmt/src/items.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index b2c573c23f89..4eff1352d7e6 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3786,10 +3786,10 @@ pub struct TraitAlias { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Trait { + pub impl_restriction: ImplRestriction, pub constness: Const, pub safety: Safety, pub is_auto: IsAuto, - pub impl_restriction: ImplRestriction, pub ident: Ident, pub generics: Generics, #[visitable(extra = BoundKind::SuperTraits)] diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 239daecd3d1f..6d5d34268ea1 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -543,10 +543,10 @@ fn lower_item_kind( }) } ItemKind::Trait(box Trait { + impl_restriction, constness, is_auto, safety, - impl_restriction, ident, generics, bounds, diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index cb9bbf014e01..5154e5dc005c 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -371,10 +371,10 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) { self.bclose(item.span, empty, cb); } ast::ItemKind::Trait(box ast::Trait { + impl_restriction, constness, safety, is_auto, - impl_restriction, ident, generics, bounds, @@ -382,10 +382,10 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) { }) => { let (cb, ib) = self.head(""); self.print_visibility(&item.vis); + self.print_impl_restriction(impl_restriction); self.print_constness(*constness); self.print_safety(*safety); self.print_is_auto(*is_auto); - self.print_impl_restriction(impl_restriction); self.word_nbsp("trait"); self.print_ident(*ident); self.print_generic_params(&generics.params); diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 0be16e35b7b3..e72cf491004e 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1157,10 +1157,10 @@ fn parse_item_trait(&mut self, attrs: &mut AttrVec, lo: Span) -> PResult<'a, Ite generics.where_clause = self.parse_where_clause()?; let items = self.parse_item_list(attrs, |p| p.parse_trait_item(ForceCollect::No))?; Ok(ItemKind::Trait(Box::new(Trait { + impl_restriction, constness, is_auto, safety, - impl_restriction, ident, generics, bounds, diff --git a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index c96c0649753f..82142d55e21d 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -448,30 +448,30 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { }, ( Trait(box ast::Trait { + impl_restriction: liprt, constness: lc, is_auto: la, safety: lu, - impl_restriction: liprt, ident: li, generics: lg, bounds: lb, items: lis, }), Trait(box ast::Trait { + impl_restriction: riprt, constness: rc, is_auto: ra, safety: ru, - impl_restriction: riprt, ident: ri, generics: rg, bounds: rb, items: ris, }), ) => { - matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No) + eq_impl_restriction(liprt, riprt) + && matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No) && la == ra && matches!(lu, Safety::Default) == matches!(ru, Safety::Default) - && eq_impl_restriction(liprt, riprt) && eq_id(*li, *ri) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index baa1cd38237b..32f71703e019 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -1155,10 +1155,10 @@ pub(crate) fn format_trait( offset: Indent, ) -> RewriteResult { let ast::Trait { + ref impl_restriction, constness, is_auto, safety, - ref impl_restriction, ident, ref generics, ref bounds,