Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rid the AST & HIR pretty printer of cruft #119169

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(" ");
Expand Down
24 changes: 2 additions & 22 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,17 +553,7 @@ impl<'a> State<'a> {
}
hir::ItemKind::OpaqueTy(opaque_ty) => {
Copy link
Member Author

@fmease fmease Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this branch reachable in practice? 🤔 type T = impl B; gets printed as type T = /*impl Trait*/; since the item gets to interpreted as a normal type alias in this specific case with a RHS of hir::TyKind::OpaqueDef. Doesn't matter anyway.

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) => {
Expand Down Expand Up @@ -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();
Expand Down
Loading