Skip to content

Commit 0d0a3da

Browse files
pcwaltonhuonw
authored andcommitted
libsyntax: Remove uses of token::ident_to_str()
1 parent 875c9ce commit 0d0a3da

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

src/librustdoc/clean.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
//! This module contains the "cleaned" pieces of the AST, and the functions
1212
//! that clean them.
1313
14-
use its = syntax::parse::token::ident_to_str;
15-
1614
use syntax;
1715
use syntax::ast;
1816
use syntax::ast_map;
@@ -893,7 +891,8 @@ fn path_to_str(p: &ast::Path) -> ~str {
893891

894892
impl Clean<~str> for ast::Ident {
895893
fn clean(&self) -> ~str {
896-
its(self).to_owned()
894+
let string = token::get_ident(self.name);
895+
string.get().to_owned()
897896
}
898897
}
899898

src/libsyntax/parse/token.rs

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,29 @@ pub fn to_str(input: @IdentInterner, t: &Token) -> ~str {
188188
}
189189
LIT_INT_UNSUFFIXED(i) => { i.to_str() }
190190
LIT_FLOAT(ref s, t) => {
191-
let mut body = ident_to_str(s).to_owned();
191+
let body_string = get_ident(s.name);
192+
let mut body = body_string.get().to_str();
192193
if body.ends_with(".") {
193194
body.push_char('0'); // `10.f` is not a float literal
194195
}
195196
body + ast_util::float_ty_to_str(t)
196197
}
197198
LIT_FLOAT_UNSUFFIXED(ref s) => {
198-
let mut body = ident_to_str(s).to_owned();
199+
let body_string = get_ident(s.name);
200+
let mut body = body_string.get().to_owned();
199201
if body.ends_with(".") {
200202
body.push_char('0'); // `10.f` is not a float literal
201203
}
202204
body
203205
}
204-
LIT_STR(ref s) => { format!("\"{}\"", ident_to_str(s).escape_default()) }
206+
LIT_STR(ref s) => {
207+
let literal_string = get_ident(s.name);
208+
format!("\"{}\"", literal_string.get().escape_default())
209+
}
205210
LIT_STR_RAW(ref s, n) => {
211+
let literal_string = get_ident(s.name);
206212
format!("r{delim}\"{string}\"{delim}",
207-
delim="#".repeat(n), string=ident_to_str(s))
213+
delim="#".repeat(n), string=literal_string.get())
208214
}
209215

210216
/* Name components */
@@ -213,7 +219,10 @@ pub fn to_str(input: @IdentInterner, t: &Token) -> ~str {
213219
UNDERSCORE => ~"_",
214220

215221
/* Other */
216-
DOC_COMMENT(ref s) => ident_to_str(s).to_owned(),
222+
DOC_COMMENT(ref s) => {
223+
let comment_string = get_ident(s.name);
224+
comment_string.get().to_str()
225+
}
217226
EOF => ~"<eof>",
218227
INTERPOLATED(ref nt) => {
219228
match nt {
@@ -647,11 +656,6 @@ pub fn interner_get(name : Name) -> @str {
647656
get_ident_interner().get(name)
648657
}
649658

650-
// maps an identifier to the string that it corresponds to
651-
pub fn ident_to_str(id : &ast::Ident) -> @str {
652-
interner_get(id.name)
653-
}
654-
655659
// maps a string to an identifier with an empty syntax context
656660
pub fn str_to_ident(str : &str) -> ast::Ident {
657661
ast::Ident::new(intern(str))
@@ -768,23 +772,4 @@ mod test {
768772
let a1 = mark_ident(a,92);
769773
assert!(mtwt_token_eq(&IDENT(a,true),&IDENT(a1,false)));
770774
}
771-
772-
773-
#[test] fn str_ptr_eq_tests(){
774-
let a = @"abc";
775-
let b = @"abc";
776-
let c = a;
777-
assert!(str_ptr_eq(a,c));
778-
assert!(!str_ptr_eq(a,b));
779-
}
780-
781-
#[test] fn fresh_name_pointer_sharing() {
782-
let ghi = str_to_ident("ghi");
783-
assert_eq!(ident_to_str(&ghi),@"ghi");
784-
assert!(str_ptr_eq(ident_to_str(&ghi),ident_to_str(&ghi)))
785-
let fresh = ast::Ident::new(fresh_name(&ghi));
786-
assert_eq!(ident_to_str(&fresh),@"ghi");
787-
assert!(str_ptr_eq(ident_to_str(&ghi),ident_to_str(&fresh)));
788-
}
789-
790775
}

0 commit comments

Comments
 (0)