diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-12-22 19:01:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-22 19:01:26 +0100 |
| commit | 15dc9f5bee8ba12df5545e8cd05215fb24f845ba (patch) | |
| tree | 4258e44701ed9e6911eb8383ec3df5ca1bcd7c88 | |
| parent | 09684d2d31e93c99a21b8b037f5d75b6c687db56 (diff) | |
| parent | b09889b959c00d43803113aeda24c2ff400f2caf (diff) | |
| download | rust-15dc9f5bee8ba12df5545e8cd05215fb24f845ba.tar.gz rust-15dc9f5bee8ba12df5545e8cd05215fb24f845ba.zip | |
Rollup merge of #119169 - fmease:pretty-yeet-syntactic-cruft, r=compiler-errors
Rid the AST & HIR pretty printer of cruft
Found while working on #119163.
For `trait Trait: ?Sized {}` (semantically malformed), we currently output `trait Trait for ? Sized {}` (sic!) / `trait Trait for ? Sized { }` (sic!) if `-Zunpretty=expanded` / `-Zunpretty=hir` is passed.
`trait Tr for Sized? {}` (#15521) and later also `trait Tr for ?Sized {}` (I guess, #20194) is former Rust syntax. Hence I'm removing these outdated branches.
~~This will conflict with #119163, therefore marking this PR as blocked.~~ Rebased
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state/item.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_hir_pretty/src/lib.rs | 24 |
2 files changed, 4 insertions, 37 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index 247061c5ca7..43561a1c020 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -5,7 +5,6 @@ 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; use rustc_span::symbol::Ident; @@ -338,21 +337,9 @@ impl<'a> State<'a> { self.word_nbsp("trait"); self.print_ident(item.ident); self.print_generic_params(&generics.params); - let mut real_bounds = Vec::with_capacity(bounds.len()); - for bound in bounds.iter() { - if let GenericBound::Trait(ptr, modifiers) = bound - && let ast::BoundPolarity::Maybe(_) = modifiers.polarity - { - self.space(); - self.word_space("for ?"); - self.print_trait_ref(&ptr.trait_ref); - } else { - real_bounds.push(bound.clone()); - } - } - if !real_bounds.is_empty() { + if !bounds.is_empty() { self.word_nbsp(":"); - self.print_type_bounds(&real_bounds); + self.print_type_bounds(bounds); } self.print_where_clause(&generics.where_clause); self.word(" "); diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 6715d01c9e0..feaec5ac620 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -553,17 +553,7 @@ impl<'a> State<'a> { } hir::ItemKind::OpaqueTy(opaque_ty) => { self.print_item_type(item, opaque_ty.generics, |state| { - let mut real_bounds = Vec::with_capacity(opaque_ty.bounds.len()); - for b in opaque_ty.bounds { - if let GenericBound::Trait(ptr, hir::TraitBoundModifier::Maybe) = b { - state.space(); - state.word_space("for ?"); - state.print_trait_ref(&ptr.trait_ref); - } else { - real_bounds.push(b); - } - } - state.print_bounds("= impl", real_bounds); + state.print_bounds("= impl", opaque_ty.bounds) }); } hir::ItemKind::Enum(ref enum_definition, params) => { @@ -625,17 +615,7 @@ impl<'a> State<'a> { self.word_nbsp("trait"); self.print_ident(item.ident); self.print_generic_params(generics.params); - let mut real_bounds = Vec::with_capacity(bounds.len()); - for b in bounds { - if let GenericBound::Trait(ptr, hir::TraitBoundModifier::Maybe) = b { - self.space(); - self.word_space("for ?"); - self.print_trait_ref(&ptr.trait_ref); - } else { - real_bounds.push(b); - } - } - self.print_bounds(":", real_bounds); + self.print_bounds(":", bounds); self.print_where_clause(generics); self.word(" "); self.bopen(); |
