diff options
| author | bors <bors@rust-lang.org> | 2014-07-08 20:06:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-08 20:06:40 +0000 |
| commit | 8bb34a3146e6ba4bc7902a85de90cf4f8064ace0 (patch) | |
| tree | f5dd9ae1066eb755649fcced85e998d72147de19 /src/libsyntax/parse | |
| parent | 35e21346216cc4c5a3b22bb6fb316f8c867f8c92 (diff) | |
| parent | 12c334a77b897f7b1cb6cff3c56a71ecb89c82af (diff) | |
| download | rust-8bb34a3146e6ba4bc7902a85de90cf4f8064ace0.tar.gz rust-8bb34a3146e6ba4bc7902a85de90cf4f8064ace0.zip | |
auto merge of #15493 : brson/rust/tostr, r=pcwalton
This updates https://github.com/rust-lang/rust/pull/15075. Rename `ToStr::to_str` to `ToString::to_string`. The naive renaming ends up with two `to_string` functions defined on strings in the prelude (the other defined via `collections::str::StrAllocating`). To remedy this I removed `StrAllocating::to_string`, making all conversions from `&str` to `String` go through `Show`. This has a measurable impact on the speed of this conversion, but the sense I get from others is that it's best to go ahead and unify `to_string` and address performance for all `to_string` conversions in `core::fmt`. `String::from_str(...)` still works as a manual fast-path. Note that the patch was done with a script, and ended up renaming a number of other `*_to_str` functions, particularly inside of rustc. All the ones I saw looked correct, and I didn't notice any additional API breakage. Closes #15046.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/attr.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 76 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 24 |
4 files changed, 52 insertions, 52 deletions
diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index e47080dadfd..53489e32837 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -91,7 +91,7 @@ impl<'a> ParserAttr for Parser<'a> { (mk_sp(lo, hi), meta_item, style) } _ => { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal(format!("expected `#` but found `{}`", token_str).as_slice()); } diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index f00c1ab4455..73e5bb97f51 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -369,7 +369,7 @@ pub fn gather_comments_and_literals(span_diagnostic: &diagnostic::SpanHandler, literals.push(Literal {lit: s.to_string(), pos: sp.lo}); }) } else { - debug!("tok: {}", token::to_str(&tok)); + debug!("tok: {}", token::to_string(&tok)); } first_read = false; } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3119d341281..a3917e93197 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -362,24 +362,24 @@ impl<'a> Parser<'a> { } } // convert a token to a string using self's reader - pub fn token_to_str(token: &token::Token) -> String { - token::to_str(token) + pub fn token_to_string(token: &token::Token) -> String { + token::to_string(token) } // convert the current token to a string using self's reader - pub fn this_token_to_str(&mut self) -> String { - Parser::token_to_str(&self.token) + pub fn this_token_to_string(&mut self) -> String { + Parser::token_to_string(&self.token) } pub fn unexpected_last(&mut self, t: &token::Token) -> ! { - let token_str = Parser::token_to_str(t); + let token_str = Parser::token_to_string(t); let last_span = self.last_span; self.span_fatal(last_span, format!("unexpected token: `{}`", token_str).as_slice()); } pub fn unexpected(&mut self) -> ! { - let this_token = self.this_token_to_str(); + let this_token = self.this_token_to_string(); self.fatal(format!("unexpected token: `{}`", this_token).as_slice()); } @@ -389,8 +389,8 @@ impl<'a> Parser<'a> { if self.token == *t { self.bump(); } else { - let token_str = Parser::token_to_str(t); - let this_token_str = self.this_token_to_str(); + let token_str = Parser::token_to_string(t); + let this_token_str = self.this_token_to_string(); self.fatal(format!("expected `{}` but found `{}`", token_str, this_token_str).as_slice()) @@ -403,15 +403,15 @@ impl<'a> Parser<'a> { pub fn expect_one_of(&mut self, edible: &[token::Token], inedible: &[token::Token]) { - fn tokens_to_str(tokens: &[token::Token]) -> String { + fn tokens_to_string(tokens: &[token::Token]) -> String { let mut i = tokens.iter(); // This might be a sign we need a connect method on Iterator. let b = i.next() - .map_or("".to_string(), |t| Parser::token_to_str(t)); + .map_or("".to_string(), |t| Parser::token_to_string(t)); i.fold(b, |b,a| { let mut b = b; b.push_str("`, `"); - b.push_str(Parser::token_to_str(a).as_slice()); + b.push_str(Parser::token_to_string(a).as_slice()); b }) } @@ -421,8 +421,8 @@ impl<'a> Parser<'a> { // leave it in the input } else { let expected = edible.iter().map(|x| (*x).clone()).collect::<Vec<_>>().append(inedible); - let expect = tokens_to_str(expected.as_slice()); - let actual = self.this_token_to_str(); + let expect = tokens_to_string(expected.as_slice()); + let actual = self.this_token_to_string(); self.fatal( (if expected.len() != 1 { (format!("expected one of `{}` but found `{}`", @@ -511,7 +511,7 @@ impl<'a> Parser<'a> { self.bug("ident interpolation not converted to real token"); } _ => { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal((format!("expected ident, found `{}`", token_str)).as_slice()) } @@ -555,7 +555,7 @@ impl<'a> Parser<'a> { pub fn expect_keyword(&mut self, kw: keywords::Keyword) { if !self.eat_keyword(kw) { let id_interned_str = token::get_ident(kw.to_ident()); - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal(format!("expected `{}`, found `{}`", id_interned_str, token_str).as_slice()) } @@ -564,7 +564,7 @@ impl<'a> Parser<'a> { // signal an error if the given string is a strict keyword pub fn check_strict_keywords(&mut self) { if token::is_strict_keyword(&self.token) { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); let span = self.span; self.span_err(span, format!("found `{}` in ident position", @@ -575,7 +575,7 @@ impl<'a> Parser<'a> { // signal an error if the current token is a reserved keyword pub fn check_reserved_keywords(&mut self) { if token::is_reserved_keyword(&self.token) { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal(format!("`{}` is a reserved keyword", token_str).as_slice()) } @@ -592,9 +592,9 @@ impl<'a> Parser<'a> { self.replace_token(token::BINOP(token::AND), lo, span.hi) } _ => { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); let found_token = - Parser::token_to_str(&token::BINOP(token::AND)); + Parser::token_to_string(&token::BINOP(token::AND)); self.fatal(format!("expected `{}`, found `{}`", found_token, token_str).as_slice()) @@ -613,9 +613,9 @@ impl<'a> Parser<'a> { self.replace_token(token::BINOP(token::OR), lo, span.hi) } _ => { - let found_token = self.this_token_to_str(); + let found_token = self.this_token_to_string(); let token_str = - Parser::token_to_str(&token::BINOP(token::OR)); + Parser::token_to_string(&token::BINOP(token::OR)); self.fatal(format!("expected `{}`, found `{}`", token_str, found_token).as_slice()) @@ -666,8 +666,8 @@ impl<'a> Parser<'a> { fn expect_lt(&mut self) { if !self.eat_lt(true) { - let found_token = self.this_token_to_str(); - let token_str = Parser::token_to_str(&token::LT); + let found_token = self.this_token_to_string(); + let token_str = Parser::token_to_string(&token::LT); self.fatal(format!("expected `{}`, found `{}`", token_str, found_token).as_slice()) @@ -717,8 +717,8 @@ impl<'a> Parser<'a> { self.replace_token(token::EQ, lo, span.hi) } _ => { - let gt_str = Parser::token_to_str(&token::GT); - let this_token_str = self.this_token_to_str(); + let gt_str = Parser::token_to_string(&token::GT); + let this_token_str = self.this_token_to_string(); self.fatal(format!("expected `{}`, found `{}`", gt_str, this_token_str).as_slice()) @@ -1246,7 +1246,7 @@ impl<'a> Parser<'a> { } _ => { - let token_str = p.this_token_to_str(); + let token_str = p.this_token_to_string(); p.fatal((format!("expected `;` or `{{` but found `{}`", token_str)).as_slice()) } @@ -2230,7 +2230,7 @@ impl<'a> Parser<'a> { None => {} Some(&sp) => p.span_note(sp, "unclosed delimiter"), }; - let token_str = p.this_token_to_str(); + let token_str = p.this_token_to_string(); p.fatal(format!("incorrect close delimiter: `{}`", token_str).as_slice()) }, @@ -2821,7 +2821,7 @@ impl<'a> Parser<'a> { if self.token == token::DOTDOT { self.bump(); if self.token != token::RBRACE { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal(format!("expected `{}`, found `{}`", "}", token_str).as_slice()) } @@ -2842,7 +2842,7 @@ impl<'a> Parser<'a> { let subpat = if self.token == token::COLON { match bind_type { BindByRef(..) | BindByValue(MutMutable) => { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal(format!("unexpected `{}`", token_str).as_slice()) } @@ -3252,7 +3252,7 @@ impl<'a> Parser<'a> { } else { "" }; - let tok_str = self.this_token_to_str(); + let tok_str = self.this_token_to_string(); self.fatal(format!("expected {}`(` or `{{`, but found `{}`", ident_str, tok_str).as_slice()) @@ -3742,7 +3742,7 @@ impl<'a> Parser<'a> { fn expect_self_ident(&mut self) { if !self.is_self_ident() { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal(format!("expected `self` but found `{}`", token_str).as_slice()) } @@ -3875,7 +3875,7 @@ impl<'a> Parser<'a> { vec!(Arg::new_self(explicit_self_sp, mutbl_self)) } _ => { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal(format!("expected `,` or `)`, found `{}`", token_str).as_slice()) } @@ -4044,7 +4044,7 @@ impl<'a> Parser<'a> { // Parses two variants (with the region/type params always optional): // impl<T> Foo { ... } - // impl<T> ToStr for ~[T] { ... } + // impl<T> ToString for ~[T] { ... } fn parse_item_impl(&mut self) -> ItemInfo { // First, parse type parameters if necessary. let generics = self.parse_generics(); @@ -4179,7 +4179,7 @@ impl<'a> Parser<'a> { is_tuple_like = true; fields = Vec::new(); } else { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal(format!("expected `{}`, `(`, or `;` after struct \ name but found `{}`", "{", token_str).as_slice()) @@ -4210,7 +4210,7 @@ impl<'a> Parser<'a> { token::RBRACE => {} _ => { let span = self.span; - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.span_fatal(span, format!("expected `,`, or `}}` but found `{}`", token_str).as_slice()) @@ -4291,7 +4291,7 @@ impl<'a> Parser<'a> { the module"); } _ => { - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.fatal(format!("expected item but found `{}`", token_str).as_slice()) } @@ -4571,7 +4571,7 @@ impl<'a> Parser<'a> { } _ => { let span = self.span; - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.span_fatal(span, format!("expected extern crate name but \ found `{}`", @@ -4829,7 +4829,7 @@ impl<'a> Parser<'a> { } let span = self.span; - let token_str = self.this_token_to_str(); + let token_str = self.this_token_to_string(); self.span_fatal(span, format!("expected `{}` or `fn` but found `{}`", "{", token_str).as_slice()); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 367b18916ac..84834f54a04 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -141,7 +141,7 @@ impl fmt::Show for Nonterminal { } } -pub fn binop_to_str(o: BinOp) -> &'static str { +pub fn binop_to_string(o: BinOp) -> &'static str { match o { PLUS => "+", MINUS => "-", @@ -156,7 +156,7 @@ pub fn binop_to_str(o: BinOp) -> &'static str { } } -pub fn to_str(t: &Token) -> String { +pub fn to_string(t: &Token) -> String { match *t { EQ => "=".to_string(), LT => "<".to_string(), @@ -169,9 +169,9 @@ pub fn to_str(t: &Token) -> String { TILDE => "~".to_string(), OROR => "||".to_string(), ANDAND => "&&".to_string(), - BINOP(op) => binop_to_str(op).to_string(), + BINOP(op) => binop_to_string(op).to_string(), BINOPEQ(op) => { - let mut s = binop_to_str(op).to_string(); + let mut s = binop_to_string(op).to_string(); s.push_str("="); s } @@ -215,15 +215,15 @@ pub fn to_str(t: &Token) -> String { res.push_char('\''); res } - LIT_INT(i, t) => ast_util::int_ty_to_str(t, Some(i)), - LIT_UINT(u, t) => ast_util::uint_ty_to_str(t, Some(u)), - LIT_INT_UNSUFFIXED(i) => { (i as u64).to_str() } + LIT_INT(i, t) => ast_util::int_ty_to_string(t, Some(i)), + LIT_UINT(u, t) => ast_util::uint_ty_to_string(t, Some(u)), + LIT_INT_UNSUFFIXED(i) => { (i as u64).to_string() } LIT_FLOAT(s, t) => { let mut body = String::from_str(get_ident(s).get()); if body.as_slice().ends_with(".") { body.push_char('0'); // `10.f` is not a float literal } - body.push_str(ast_util::float_ty_to_str(t).as_slice()); + body.push_str(ast_util::float_ty_to_string(t).as_slice()); body } LIT_FLOAT_UNSUFFIXED(s) => { @@ -262,8 +262,8 @@ pub fn to_str(t: &Token) -> String { EOF => "<eof>".to_string(), INTERPOLATED(ref nt) => { match nt { - &NtExpr(ref e) => ::print::pprust::expr_to_str(&**e), - &NtMeta(ref e) => ::print::pprust::meta_item_to_str(&**e), + &NtExpr(ref e) => ::print::pprust::expr_to_string(&**e), + &NtMeta(ref e) => ::print::pprust::meta_item_to_string(&**e), _ => { let mut s = "an interpolated ".to_string(); match *nt { @@ -693,7 +693,7 @@ pub fn gensym_ident(s: &str) -> ast::Ident { } // create a fresh name that maps to the same string as the old one. -// note that this guarantees that str_ptr_eq(ident_to_str(src),interner_get(fresh_name(src))); +// note that this guarantees that str_ptr_eq(ident_to_string(src),interner_get(fresh_name(src))); // that is, that the new name and the old one are connected to ptr_eq strings. pub fn fresh_name(src: &ast::Ident) -> Name { let interner = get_ident_interner(); @@ -702,7 +702,7 @@ pub fn fresh_name(src: &ast::Ident) -> Name { // good error messages and uses of struct names in ambiguous could-be-binding // locations. Also definitely destroys the guarantee given above about ptr_eq. /*let num = rand::task_rng().gen_uint_range(0,0xffff); - gensym(format!("{}_{}",ident_to_str(src),num))*/ + gensym(format!("{}_{}",ident_to_string(src),num))*/ } // create a fresh mark. |
