]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_ast_pretty/src/helpers.rs
Rollup merge of #107339 - aliemjay:covariant, r=lcnr
[rust.git] / compiler / rustc_ast_pretty / src / helpers.rs
1 use crate::pp::Printer;
2 use std::borrow::Cow;
3
4 impl Printer {
5     pub fn word_space<W: Into<Cow<'static, str>>>(&mut self, w: W) {
6         self.word(w);
7         self.space();
8     }
9
10     pub fn popen(&mut self) {
11         self.word("(");
12     }
13
14     pub fn pclose(&mut self) {
15         self.word(")");
16     }
17
18     pub fn hardbreak_if_not_bol(&mut self) {
19         if !self.is_beginning_of_line() {
20             self.hardbreak()
21         }
22     }
23
24     pub fn space_if_not_bol(&mut self) {
25         if !self.is_beginning_of_line() {
26             self.space();
27         }
28     }
29
30     pub fn nbsp(&mut self) {
31         self.word(" ")
32     }
33
34     pub fn word_nbsp<S: Into<Cow<'static, str>>>(&mut self, w: S) {
35         self.word(w);
36         self.nbsp()
37     }
38
39     /// Synthesizes a comment that was not textually present in the original
40     /// source file.
41     pub fn synth_comment(&mut self, text: impl Into<Cow<'static, str>>) {
42         self.word("/*");
43         self.space();
44         self.word(text);
45         self.space();
46         self.word("*/")
47     }
48 }