Skip to content

Commit f915e3e

Browse files
committed
rustc_ast_pretty: Remove PrintState::insert_extra_parens
It's no longer necessary after #79472
1 parent c8915ee commit f915e3e

File tree

4 files changed

+3
-36
lines changed

4 files changed

+3
-36
lines changed

compiler/rustc_ast_pretty/src/pprust/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ use rustc_ast as ast;
88
use rustc_ast::token::{Nonterminal, Token, TokenKind};
99
use rustc_ast::tokenstream::{TokenStream, TokenTree};
1010

11-
pub fn nonterminal_to_string_no_extra_parens(nt: &Nonterminal) -> String {
12-
let state = State::without_insert_extra_parens();
13-
state.nonterminal_to_string(nt)
14-
}
15-
1611
pub fn nonterminal_to_string(nt: &Nonterminal) -> String {
1712
State::new().nonterminal_to_string(nt)
1813
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-26
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ pub struct State<'a> {
8888
comments: Option<Comments<'a>>,
8989
ann: &'a (dyn PpAnn + 'a),
9090
is_expanded: bool,
91-
// If `true`, additional parenthesis (separate from `ExprKind::Paren`)
92-
// are inserted to ensure that proper precedence is preserved
93-
// in the pretty-printed output.
94-
//
95-
// This is usually `true`, except when performing the pretty-print/reparse
96-
// check in `nt_to_tokenstream`
97-
insert_extra_parens: bool,
9891
}
9992

10093
crate const INDENT_UNIT: usize = 4;
@@ -115,7 +108,6 @@ pub fn print_crate<'a>(
115108
comments: Some(Comments::new(sm, filename, input)),
116109
ann,
117110
is_expanded,
118-
insert_extra_parens: true,
119111
};
120112

121113
if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
@@ -235,7 +227,6 @@ impl std::ops::DerefMut for State<'_> {
235227
}
236228

237229
pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::DerefMut {
238-
fn insert_extra_parens(&self) -> bool;
239230
fn comments(&mut self) -> &mut Option<Comments<'a>>;
240231
fn print_ident(&mut self, ident: Ident);
241232
fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool);
@@ -819,16 +810,12 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
819810

820811
fn to_string(&self, f: impl FnOnce(&mut State<'_>)) -> String {
821812
let mut printer = State::new();
822-
printer.insert_extra_parens = self.insert_extra_parens();
823813
f(&mut printer);
824814
printer.s.eof()
825815
}
826816
}
827817

828818
impl<'a> PrintState<'a> for State<'a> {
829-
fn insert_extra_parens(&self) -> bool {
830-
self.insert_extra_parens
831-
}
832819
fn comments(&mut self) -> &mut Option<Comments<'a>> {
833820
&mut self.comments
834821
}
@@ -865,17 +852,7 @@ impl<'a> PrintState<'a> for State<'a> {
865852

866853
impl<'a> State<'a> {
867854
pub fn new() -> State<'a> {
868-
State {
869-
s: pp::mk_printer(),
870-
comments: None,
871-
ann: &NoAnn,
872-
is_expanded: false,
873-
insert_extra_parens: true,
874-
}
875-
}
876-
877-
pub(super) fn without_insert_extra_parens() -> State<'a> {
878-
State { insert_extra_parens: false, ..State::new() }
855+
State { s: pp::mk_printer(), comments: None, ann: &NoAnn, is_expanded: false }
879856
}
880857

881858
// Synthesizes a comment that was not textually present in the original source
@@ -1680,8 +1657,7 @@ impl<'a> State<'a> {
16801657
}
16811658

16821659
/// Prints `expr` or `(expr)` when `needs_par` holds.
1683-
fn print_expr_cond_paren(&mut self, expr: &ast::Expr, mut needs_par: bool) {
1684-
needs_par &= self.insert_extra_parens;
1660+
fn print_expr_cond_paren(&mut self, expr: &ast::Expr, needs_par: bool) {
16851661
if needs_par {
16861662
self.popen();
16871663
}

compiler/rustc_hir_pretty/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ impl std::ops::DerefMut for State<'_> {
138138
}
139139

140140
impl<'a> PrintState<'a> for State<'a> {
141-
fn insert_extra_parens(&self) -> bool {
142-
true
143-
}
144141
fn comments(&mut self) -> &mut Option<Comments<'a>> {
145142
&mut self.comments
146143
}

compiler/rustc_parse/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ pub fn nt_to_tokenstream(
283283
} else if matches!(synthesize_tokens, CanSynthesizeMissingTokens::Yes) {
284284
return fake_token_stream(sess, nt);
285285
} else {
286-
let pretty = rustc_ast_pretty::pprust::nonterminal_to_string_no_extra_parens(&nt);
287-
panic!("Missing tokens for nt {:?}", pretty);
286+
panic!("Missing tokens for nt {:?}", pprust::nonterminal_to_string(nt));
288287
}
289288
}
290289

0 commit comments

Comments
 (0)