]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/print/pprust.rs
remove `get_ident` and `get_name`, make `as_str` sound
[rust.git] / src / libsyntax / print / pprust.rs
index 448857389da6172b652d71a16b5704aa90c0164c..6cfe85bc37e8171324258cbcda76f322457931f9 100644 (file)
@@ -251,40 +251,40 @@ pub fn token_to_string(tok: &Token) -> String {
         /* Literals */
         token::Literal(lit, suf) => {
             let mut out = match lit {
-                token::Byte(b)           => format!("b'{}'", b.as_str()),
-                token::Char(c)           => format!("'{}'", c.as_str()),
-                token::Float(c)          => c.as_str().to_string(),
-                token::Integer(c)        => c.as_str().to_string(),
-                token::Str_(s)           => format!("\"{}\"", s.as_str()),
+                token::Byte(b)           => format!("b'{}'", b),
+                token::Char(c)           => format!("'{}'", c),
+                token::Float(c)          => c.to_string(),
+                token::Integer(c)        => c.to_string(),
+                token::Str_(s)           => format!("\"{}\"", s),
                 token::StrRaw(s, n)      => format!("r{delim}\"{string}\"{delim}",
                                                     delim=repeat("#", n),
-                                                    string=s.as_str()),
-                token::Binary(v)         => format!("b\"{}\"", v.as_str()),
+                                                    string=s),
+                token::Binary(v)         => format!("b\"{}\"", v),
                 token::BinaryRaw(s, n)   => format!("br{delim}\"{string}\"{delim}",
                                                     delim=repeat("#", n),
-                                                    string=s.as_str()),
+                                                    string=s),
             };
 
             if let Some(s) = suf {
-                out.push_str(s.as_str())
+                out.push_str(&s.as_str())
             }
 
             out
         }
 
         /* Name components */
-        token::Ident(s, _)          => token::get_ident(s).to_string(),
-        token::Lifetime(s)          => format!("{}", token::get_ident(s)),
+        token::Ident(s, _)          => s.to_string(),
+        token::Lifetime(s)          => s.to_string(),
         token::Underscore           => "_".to_string(),
 
         /* Other */
-        token::DocComment(s)        => s.as_str().to_string(),
+        token::DocComment(s)        => s.to_string(),
         token::SubstNt(s, _)        => format!("${}", s),
         token::MatchNt(s, t, _, _)  => format!("${}:{}", s, t),
         token::Eof                  => "<eof>".to_string(),
         token::Whitespace           => " ".to_string(),
         token::Comment              => "/* */".to_string(),
-        token::Shebang(s)           => format!("/* shebang: {}*/", s.as_str()),
+        token::Shebang(s)           => format!("/* shebang: {}*/", s),
 
         token::SpecialVarNt(var)    => format!("${}", var.as_str()),
 
@@ -819,7 +819,7 @@ pub fn print_item(&mut self, item: &ast::Item) -> io::Result<()> {
                 try!(self.head(&visibility_qualified(item.vis,
                                                      "extern crate")));
                 if let Some(p) = *optional_path {
-                    let val = token::get_name(p);
+                    let val = p.as_str();
                     if val.contains("-") {
                         try!(self.print_string(&val, ast::CookedStr));
                     } else {
@@ -2009,7 +2009,7 @@ pub fn print_decl(&mut self, decl: &ast::Decl) -> io::Result<()> {
     }
 
     pub fn print_ident(&mut self, ident: ast::Ident) -> io::Result<()> {
-        try!(word(&mut self.s, &token::get_ident(ident)));
+        try!(word(&mut self.s, &ident.name.as_str()));
         self.ann.post(self, NodeIdent(&ident))
     }
 
@@ -2018,7 +2018,7 @@ pub fn print_usize(&mut self, i: usize) -> io::Result<()> {
     }
 
     pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
-        try!(word(&mut self.s, &token::get_name(name)));
+        try!(word(&mut self.s, &name.as_str()));
         self.ann.post(self, NodeName(&name))
     }