mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Delete duplicated helpers from HIR printer
This commit is contained in:
parent
772d51f887
commit
596e33ac32
@ -35,4 +35,14 @@ impl Printer {
|
||||
self.word(w);
|
||||
self.nbsp()
|
||||
}
|
||||
|
||||
// Synthesizes a comment that was not textually present in the original
|
||||
// source file.
|
||||
pub fn synth_comment(&mut self, text: impl Into<Cow<'static, str>>) {
|
||||
self.word("/*");
|
||||
self.space();
|
||||
self.word(text);
|
||||
self.space();
|
||||
self.word("*/")
|
||||
}
|
||||
}
|
||||
|
@ -349,6 +349,25 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
self.comments().as_mut().and_then(|c| c.next())
|
||||
}
|
||||
|
||||
fn maybe_print_trailing_comment(&mut self, span: rustc_span::Span, next_pos: Option<BytePos>) {
|
||||
if let Some(cmnts) = self.comments() {
|
||||
if let Some(cmnt) = cmnts.trailing_comment(span, next_pos) {
|
||||
self.print_comment(&cmnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_remaining_comments(&mut self) {
|
||||
// If there aren't any remaining comments, then we need to manually
|
||||
// make sure there is a line break at the end.
|
||||
if self.next_comment().is_none() {
|
||||
self.hardbreak();
|
||||
}
|
||||
while let Some(ref cmnt) = self.next_comment() {
|
||||
self.print_comment(cmnt)
|
||||
}
|
||||
}
|
||||
|
||||
fn print_literal(&mut self, lit: &ast::Lit) {
|
||||
self.maybe_print_comment(lit.span.lo());
|
||||
self.word(lit.token.to_string())
|
||||
@ -893,16 +912,6 @@ impl<'a> State<'a> {
|
||||
State { s: pp::mk_printer(), comments: None, ann: &NoAnn }
|
||||
}
|
||||
|
||||
// Synthesizes a comment that was not textually present in the original source
|
||||
// file.
|
||||
pub fn synth_comment(&mut self, text: String) {
|
||||
self.s.word("/*");
|
||||
self.s.space();
|
||||
self.s.word(text);
|
||||
self.s.space();
|
||||
self.s.word("*/")
|
||||
}
|
||||
|
||||
crate fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)
|
||||
where
|
||||
F: FnMut(&mut State<'_>, &T),
|
||||
@ -2920,29 +2929,6 @@ impl<'a> State<'a> {
|
||||
self.end();
|
||||
}
|
||||
|
||||
crate fn maybe_print_trailing_comment(
|
||||
&mut self,
|
||||
span: rustc_span::Span,
|
||||
next_pos: Option<BytePos>,
|
||||
) {
|
||||
if let Some(cmnts) = self.comments() {
|
||||
if let Some(cmnt) = cmnts.trailing_comment(span, next_pos) {
|
||||
self.print_comment(&cmnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate fn print_remaining_comments(&mut self) {
|
||||
// If there aren't any remaining comments, then we need to manually
|
||||
// make sure there is a line break at the end.
|
||||
if self.next_comment().is_none() {
|
||||
self.s.hardbreak();
|
||||
}
|
||||
while let Some(ref cmnt) = self.next_comment() {
|
||||
self.print_comment(cmnt);
|
||||
}
|
||||
}
|
||||
|
||||
crate fn print_fn_header_info(&mut self, header: ast::FnHeader) {
|
||||
self.print_constness(header.constness);
|
||||
self.print_asyncness(header.asyncness);
|
||||
|
@ -10,7 +10,7 @@ use rustc_hir::{GenericArg, GenericParam, GenericParamKind, Node};
|
||||
use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
|
||||
use rustc_span::source_map::{SourceMap, Spanned};
|
||||
use rustc_span::symbol::{kw, Ident, IdentPrinter, Symbol};
|
||||
use rustc_span::{self, BytePos, FileName};
|
||||
use rustc_span::{self, FileName};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
use std::borrow::Cow;
|
||||
@ -241,36 +241,6 @@ pub fn enum_def_to_string(
|
||||
}
|
||||
|
||||
impl<'a> State<'a> {
|
||||
pub fn cbox(&mut self, u: usize) {
|
||||
self.s.cbox(u);
|
||||
}
|
||||
|
||||
pub fn nbsp(&mut self) {
|
||||
self.s.word(" ")
|
||||
}
|
||||
|
||||
pub fn word_nbsp<S: Into<Cow<'static, str>>>(&mut self, w: S) {
|
||||
self.s.word(w);
|
||||
self.nbsp()
|
||||
}
|
||||
|
||||
pub fn head<S: Into<Cow<'static, str>>>(&mut self, w: S) {
|
||||
let w = w.into();
|
||||
// outer-box is consistent
|
||||
self.cbox(INDENT_UNIT);
|
||||
// head-box is inconsistent
|
||||
self.ibox(w.len() + 1);
|
||||
// keyword that starts the head
|
||||
if !w.is_empty() {
|
||||
self.word_nbsp(w);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bopen(&mut self) {
|
||||
self.s.word("{");
|
||||
self.end(); // close the head-box
|
||||
}
|
||||
|
||||
pub fn bclose_maybe_open(&mut self, span: rustc_span::Span, close_box: bool) {
|
||||
self.maybe_print_comment(span.hi());
|
||||
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
|
||||
@ -284,33 +254,6 @@ impl<'a> State<'a> {
|
||||
self.bclose_maybe_open(span, true)
|
||||
}
|
||||
|
||||
pub fn space_if_not_bol(&mut self) {
|
||||
if !self.s.is_beginning_of_line() {
|
||||
self.s.space();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
|
||||
if !self.s.is_beginning_of_line() {
|
||||
self.s.break_offset(n, off)
|
||||
} else if off != 0 && self.s.last_token().is_hardbreak_tok() {
|
||||
// We do something pretty sketchy here: tuck the nonzero
|
||||
// offset-adjustment we were going to deposit along with the
|
||||
// break into the previous hardbreak.
|
||||
self.s.replace_last_token(pp::Printer::hardbreak_tok_offset(off));
|
||||
}
|
||||
}
|
||||
|
||||
// Synthesizes a comment that was not textually present in the original source
|
||||
// file.
|
||||
pub fn synth_comment(&mut self, text: String) {
|
||||
self.s.word("/*");
|
||||
self.s.space();
|
||||
self.s.word(text);
|
||||
self.s.space();
|
||||
self.s.word("*/")
|
||||
}
|
||||
|
||||
pub fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)
|
||||
where
|
||||
F: FnMut(&mut State<'_>, &T),
|
||||
@ -2408,29 +2351,6 @@ impl<'a> State<'a> {
|
||||
self.end();
|
||||
}
|
||||
|
||||
pub fn maybe_print_trailing_comment(
|
||||
&mut self,
|
||||
span: rustc_span::Span,
|
||||
next_pos: Option<BytePos>,
|
||||
) {
|
||||
if let Some(cmnts) = self.comments() {
|
||||
if let Some(cmnt) = cmnts.trailing_comment(span, next_pos) {
|
||||
self.print_comment(&cmnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_remaining_comments(&mut self) {
|
||||
// If there aren't any remaining comments, then we need to manually
|
||||
// make sure there is a line break at the end.
|
||||
if self.next_comment().is_none() {
|
||||
self.s.hardbreak();
|
||||
}
|
||||
while let Some(ref cmnt) = self.next_comment() {
|
||||
self.print_comment(cmnt)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_fn_header_info(&mut self, header: hir::FnHeader, vis: &hir::Visibility<'_>) {
|
||||
self.s.word(visibility_qualified(vis, ""));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user