Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 78ca460

Browse files
committedDec 20, 2023
Rid the AST & HIR pretty printers of syntactic cruft
1 parent bf9229a commit 78ca460

File tree

2 files changed

+4
-35
lines changed
  • compiler
    • rustc_ast_pretty/src/pprust/state
    • rustc_hir_pretty/src

2 files changed

+4
-35
lines changed
 

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

+2-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
55
use ast::StaticItem;
66
use itertools::{Itertools, Position};
77
use rustc_ast as ast;
8-
use rustc_ast::GenericBound;
98
use rustc_ast::ModKind;
109
use rustc_span::symbol::Ident;
1110

@@ -338,19 +337,9 @@ impl<'a> State<'a> {
338337
self.word_nbsp("trait");
339338
self.print_ident(item.ident);
340339
self.print_generic_params(&generics.params);
341-
let mut real_bounds = Vec::with_capacity(bounds.len());
342-
for b in bounds.iter() {
343-
if let GenericBound::Trait(ptr, ast::TraitBoundModifier::Maybe) = b {
344-
self.space();
345-
self.word_space("for ?");
346-
self.print_trait_ref(&ptr.trait_ref);
347-
} else {
348-
real_bounds.push(b.clone());
349-
}
350-
}
351-
if !real_bounds.is_empty() {
340+
if !bounds.is_empty() {
352341
self.word_nbsp(":");
353-
self.print_type_bounds(&real_bounds);
342+
self.print_type_bounds(bounds);
354343
}
355344
self.print_where_clause(&generics.where_clause);
356345
self.word(" ");

‎compiler/rustc_hir_pretty/src/lib.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -553,17 +553,7 @@ impl<'a> State<'a> {
553553
}
554554
hir::ItemKind::OpaqueTy(opaque_ty) => {
555555
self.print_item_type(item, opaque_ty.generics, |state| {
556-
let mut real_bounds = Vec::with_capacity(opaque_ty.bounds.len());
557-
for b in opaque_ty.bounds {
558-
if let GenericBound::Trait(ptr, hir::TraitBoundModifier::Maybe) = b {
559-
state.space();
560-
state.word_space("for ?");
561-
state.print_trait_ref(&ptr.trait_ref);
562-
} else {
563-
real_bounds.push(b);
564-
}
565-
}
566-
state.print_bounds("= impl", real_bounds);
556+
state.print_bounds("= impl", opaque_ty.bounds)
567557
});
568558
}
569559
hir::ItemKind::Enum(ref enum_definition, params) => {
@@ -625,17 +615,7 @@ impl<'a> State<'a> {
625615
self.word_nbsp("trait");
626616
self.print_ident(item.ident);
627617
self.print_generic_params(generics.params);
628-
let mut real_bounds = Vec::with_capacity(bounds.len());
629-
for b in bounds {
630-
if let GenericBound::Trait(ptr, hir::TraitBoundModifier::Maybe) = b {
631-
self.space();
632-
self.word_space("for ?");
633-
self.print_trait_ref(&ptr.trait_ref);
634-
} else {
635-
real_bounds.push(b);
636-
}
637-
}
638-
self.print_bounds(":", real_bounds);
618+
self.print_bounds(":", bounds);
639619
self.print_where_clause(generics);
640620
self.word(" ");
641621
self.bopen();

0 commit comments

Comments
 (0)
Please sign in to comment.