about summary refs log tree commit diff
path: root/src/libsyntax/print
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-01-20 08:26:12 +0000
committerbors <bors@rust-lang.org>2019-01-20 08:26:12 +0000
commit2ab5d8ac447f1f3f865dbae5bafbdeacacdea6d9 (patch)
tree277e74cb41d08c97b79f8b372ed0b35cb719581d /src/libsyntax/print
parent588f94b37d020aefe54b0c00ced2fdd7ccc61dfb (diff)
parent4005d3a8cb082f84f6bfb8c2168387a747aabf1e (diff)
downloadrust-2ab5d8ac447f1f3f865dbae5bafbdeacacdea6d9.tar.gz
rust-2ab5d8ac447f1f3f865dbae5bafbdeacacdea6d9.zip
Auto merge of #57651 - JohnTitor:give-char-type, r=estebank
Implement new literal type `Err`

Fixes #57384

I removed `return Ok`, otherwise, two errors occur. Any solutions?

r? @estebank
Diffstat (limited to 'src/libsyntax/print')
-rw-r--r--src/libsyntax/print/pprust.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index c53594032a0..7cecf4b9af7 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -224,6 +224,7 @@ pub fn token_to_string(tok: &Token) -> String {
             let mut out = match lit {
                 token::Byte(b)           => format!("b'{}'", b),
                 token::Char(c)           => format!("'{}'", c),
+                token::Err(c)            => format!("'{}'", c),
                 token::Float(c)          |
                 token::Integer(c)        => c.to_string(),
                 token::Str_(s)           => format!("\"{}\"", s),
@@ -603,6 +604,14 @@ pub trait PrintState<'a> {
         }
         match lit.node {
             ast::LitKind::Str(st, style) => self.print_string(&st.as_str(), style),
+            ast::LitKind::Err(st) => {
+                let st = st.as_str().escape_debug();
+                let mut res = String::with_capacity(st.len() + 2);
+                res.push('\'');
+                res.push_str(&st);
+                res.push('\'');
+                self.writer().word(res)
+            }
             ast::LitKind::Byte(byte) => {
                 let mut res = String::from("b'");
                 res.extend(ascii::escape_default(byte).map(|c| c as char));