Skip to content

Commit 096cb41

Browse files
Remove writer function from PrintState
1 parent 73c1752 commit 096cb41

File tree

2 files changed

+33
-42
lines changed

2 files changed

+33
-42
lines changed

src/librustc/hir/print.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ impl std::ops::DerefMut for State<'_> {
8787
}
8888

8989
impl<'a> PrintState<'a> for State<'a> {
90-
fn writer(&mut self) -> &mut pp::Printer {
91-
&mut self.s
92-
}
93-
9490
fn comments(&mut self) -> &mut Option<Comments<'a>> {
9591
&mut self.comments
9692
}
@@ -1182,7 +1178,7 @@ impl<'a> State<'a> {
11821178

11831179
fn print_literal(&mut self, lit: &hir::Lit) {
11841180
self.maybe_print_comment(lit.span.lo());
1185-
self.writer().word(lit.node.to_lit_token().to_string())
1181+
self.word(lit.node.to_lit_token().to_string())
11861182
}
11871183

11881184
pub fn print_expr(&mut self, expr: &hir::Expr) {

src/libsyntax/print/pprust.rs

+32-37
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ impl std::ops::DerefMut for State<'_> {
446446
}
447447

448448
pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefMut {
449-
fn writer(&mut self) -> &mut pp::Printer;
450449
fn comments(&mut self) -> &mut Option<Comments<'a>>;
451450

452451
fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], mut op: F)
@@ -476,51 +475,51 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
476475
match cmnt.style {
477476
comments::Mixed => {
478477
assert_eq!(cmnt.lines.len(), 1);
479-
self.writer().zerobreak();
480-
self.writer().word(cmnt.lines[0].clone());
481-
self.writer().zerobreak()
478+
self.zerobreak();
479+
self.word(cmnt.lines[0].clone());
480+
self.zerobreak()
482481
}
483482
comments::Isolated => {
484483
self.hardbreak_if_not_bol();
485484
for line in &cmnt.lines {
486485
// Don't print empty lines because they will end up as trailing
487486
// whitespace
488487
if !line.is_empty() {
489-
self.writer().word(line.clone());
488+
self.word(line.clone());
490489
}
491-
self.writer().hardbreak();
490+
self.hardbreak();
492491
}
493492
}
494493
comments::Trailing => {
495-
if !self.writer().is_beginning_of_line() {
496-
self.writer().word(" ");
494+
if !self.is_beginning_of_line() {
495+
self.word(" ");
497496
}
498497
if cmnt.lines.len() == 1 {
499-
self.writer().word(cmnt.lines[0].clone());
500-
self.writer().hardbreak()
498+
self.word(cmnt.lines[0].clone());
499+
self.hardbreak()
501500
} else {
502501
self.ibox(0);
503502
for line in &cmnt.lines {
504503
if !line.is_empty() {
505-
self.writer().word(line.clone());
504+
self.word(line.clone());
506505
}
507-
self.writer().hardbreak();
506+
self.hardbreak();
508507
}
509508
self.end();
510509
}
511510
}
512511
comments::BlankLine => {
513512
// We need to do at least one, possibly two hardbreaks.
514-
let twice = match self.writer().last_token() {
513+
let twice = match self.last_token() {
515514
pp::Token::String(s) => ";" == s,
516515
pp::Token::Begin(_) => true,
517516
pp::Token::End => true,
518517
_ => false
519518
};
520519
if twice {
521-
self.writer().hardbreak();
520+
self.hardbreak();
522521
}
523-
self.writer().hardbreak();
522+
self.hardbreak();
524523
}
525524
}
526525
if let Some(cm) = self.comments() {
@@ -534,7 +533,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
534533

535534
fn print_literal(&mut self, lit: &ast::Lit) {
536535
self.maybe_print_comment(lit.span.lo());
537-
self.writer().word(lit.token.to_string())
536+
self.word(lit.token.to_string())
538537
}
539538

540539
fn print_string(&mut self, st: &str,
@@ -549,7 +548,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
549548
string=st))
550549
}
551550
};
552-
self.writer().word(st)
551+
self.word(st)
553552
}
554553

555554
fn print_inner_attributes(&mut self,
@@ -601,10 +600,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
601600
fn print_attribute_path(&mut self, path: &ast::Path) {
602601
for (i, segment) in path.segments.iter().enumerate() {
603602
if i > 0 {
604-
self.writer().word("::");
603+
self.word("::");
605604
}
606605
if segment.ident.name != kw::PathRoot {
607-
self.writer().word(ident_to_string(segment.ident, segment.ident.is_raw_guess()));
606+
self.word(ident_to_string(segment.ident, segment.ident.is_raw_guess()));
608607
}
609608
}
610609
}
@@ -620,21 +619,21 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
620619
}
621620
self.maybe_print_comment(attr.span.lo());
622621
if attr.is_sugared_doc {
623-
self.writer().word(attr.value_str().unwrap().as_str().to_string());
624-
self.writer().hardbreak()
622+
self.word(attr.value_str().unwrap().as_str().to_string());
623+
self.hardbreak()
625624
} else {
626625
match attr.style {
627-
ast::AttrStyle::Inner => self.writer().word("#!["),
628-
ast::AttrStyle::Outer => self.writer().word("#["),
626+
ast::AttrStyle::Inner => self.word("#!["),
627+
ast::AttrStyle::Outer => self.word("#["),
629628
}
630629
if let Some(mi) = attr.meta() {
631630
self.print_meta_item(&mi);
632631
} else {
633632
self.print_attribute_path(&attr.path);
634-
self.writer().space();
633+
self.space();
635634
self.print_tts(attr.tokens.clone());
636635
}
637-
self.writer().word("]");
636+
self.word("]");
638637
}
639638
}
640639

@@ -655,7 +654,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
655654
ast::MetaItemKind::Word => self.print_attribute_path(&item.path),
656655
ast::MetaItemKind::NameValue(ref value) => {
657656
self.print_attribute_path(&item.path);
658-
self.writer().space();
657+
self.space();
659658
self.word_space("=");
660659
self.print_literal(value);
661660
}
@@ -681,20 +680,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
681680
fn print_tt(&mut self, tt: tokenstream::TokenTree, convert_dollar_crate: bool) {
682681
match tt {
683682
TokenTree::Token(ref token) => {
684-
self.writer().word(token_to_string_ext(&token, convert_dollar_crate));
683+
self.word(token_to_string_ext(&token, convert_dollar_crate));
685684
match token.kind {
686685
token::DocComment(..) => {
687-
self.writer().hardbreak()
686+
self.hardbreak()
688687
}
689688
_ => {}
690689
}
691690
}
692691
TokenTree::Delimited(_, delim, tts) => {
693-
self.writer().word(token_kind_to_string(&token::OpenDelim(delim)));
694-
self.writer().space();
692+
self.word(token_kind_to_string(&token::OpenDelim(delim)));
693+
self.space();
695694
self.print_tts(tts);
696-
self.writer().space();
697-
self.writer().word(token_kind_to_string(&token::CloseDelim(delim)))
695+
self.space();
696+
self.word(token_kind_to_string(&token::CloseDelim(delim)))
698697
},
699698
}
700699
}
@@ -707,7 +706,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
707706
self.ibox(0);
708707
for (i, tt) in tts.into_trees().enumerate() {
709708
if i != 0 {
710-
self.writer().space();
709+
self.space();
711710
}
712711
self.print_tt(tt, convert_dollar_crate);
713712
}
@@ -716,10 +715,6 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
716715
}
717716

718717
impl<'a> PrintState<'a> for State<'a> {
719-
fn writer(&mut self) -> &mut pp::Printer {
720-
&mut self.s
721-
}
722-
723718
fn comments(&mut self) -> &mut Option<Comments<'a>> {
724719
&mut self.comments
725720
}

0 commit comments

Comments
 (0)