use syntax::parse::lexer::comments;
use syntax::print::pp::{self, Breaks};
use syntax::print::pp::Breaks::{Consistent, Inconsistent};
-use syntax::print::pprust::{self, PrintState};
+use syntax::print::pprust::PrintState;
use syntax::symbol::kw;
use syntax::util::parser::{self, AssocOp, Fixity};
use syntax_pos::{self, BytePos, FileName};
fn print_literal(&mut self, lit: &hir::Lit) {
self.maybe_print_comment(lit.span.lo());
- self.writer().word(pprust::literal_to_string(lit.node.to_lit_token()))
+ self.writer().word(lit.node.to_lit_token().to_string())
}
pub fn print_expr(&mut self, expr: &hir::Expr) {
// Pack possible quotes and prefixes from the original literal into
// the error literal's symbol so they can be pretty-printed faithfully.
let suffixless_lit = token::Lit::new(lit.kind, lit.symbol, None);
- let symbol = Symbol::intern(&pprust::literal_to_string(suffixless_lit));
+ let symbol = Symbol::intern(&suffixless_lit.to_string());
let lit = token::Lit::new(token::Err, symbol, lit.suffix);
Lit::from_lit_token(lit, span).map_err(|_| unreachable!())
}
pub suffix: Option<Symbol>,
}
+impl fmt::Display for Lit {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let Lit { kind, symbol, suffix } = *self;
+ match kind {
+ Byte => write!(f, "b'{}'", symbol)?,
+ Char => write!(f, "'{}'", symbol)?,
+ Str => write!(f, "\"{}\"", symbol)?,
+ StrRaw(n) => write!(f, "r{delim}\"{string}\"{delim}",
+ delim="#".repeat(n as usize),
+ string=symbol)?,
+ ByteStr => write!(f, "b\"{}\"", symbol)?,
+ ByteStrRaw(n) => write!(f, "br{delim}\"{string}\"{delim}",
+ delim="#".repeat(n as usize),
+ string=symbol)?,
+ Integer |
+ Float |
+ Bool |
+ Err => write!(f, "{}", symbol)?,
+ }
+
+ if let Some(suffix) = suffix {
+ write!(f, "{}", suffix)?;
+ }
+
+ Ok(())
+ }
+}
+
impl LitKind {
/// An English article for the literal token kind.
crate fn article(self) -> &'static str {
to_string(|s| s.print_attribute(attr))
}
-pub fn lit_to_string(l: &ast::Lit) -> String {
- to_string(|s| s.print_literal(l))
-}
-
pub fn variant_to_string(var: &ast::Variant) -> String {
to_string(|s| s.print_variant(var))
}
fn print_literal(&mut self, lit: &ast::Lit) {
self.maybe_print_comment(lit.span.lo());
- self.writer().word(literal_to_string(lit.token))
+ self.writer().word(lit.token.to_string())
}
fn print_string(&mut self, st: &str,