From 12c334a77b897f7b1cb6cff3c56a71ecb89c82af Mon Sep 17 00:00:00 2001 From: Richo Healey Date: Sat, 21 Jun 2014 03:39:03 -0700 Subject: std: Rename the `ToStr` trait to `ToString`, and `to_str` to `to_string`. [breaking-change] --- src/libsyntax/parse/attr.rs | 2 +- src/libsyntax/parse/lexer/comments.rs | 2 +- src/libsyntax/parse/parser.rs | 76 +++++++++++++++++------------------ src/libsyntax/parse/token.rs | 24 +++++------ 4 files changed, 52 insertions(+), 52 deletions(-) (limited to 'src/libsyntax/parse') 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 6b6387b0127..52cf2ff3741 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -363,24 +363,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()); } @@ -390,8 +390,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()) @@ -404,15 +404,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 }) } @@ -422,8 +422,8 @@ impl<'a> Parser<'a> { // leave it in the input } else { let expected = edible.iter().map(|x| (*x).clone()).collect::>().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 `{}`", @@ -512,7 +512,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()) } @@ -556,7 +556,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()) } @@ -565,7 +565,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", @@ -576,7 +576,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()) } @@ -593,9 +593,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()) @@ -614,9 +614,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()) @@ -667,8 +667,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()) @@ -718,8 +718,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()) @@ -1247,7 +1247,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()) } @@ -2231,7 +2231,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()) }, @@ -2822,7 +2822,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()) } @@ -2843,7 +2843,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()) } @@ -3253,7 +3253,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()) @@ -3714,7 +3714,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()) } @@ -3847,7 +3847,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()) } @@ -4016,7 +4016,7 @@ impl<'a> Parser<'a> { // Parses two variants (with the region/type params always optional): // impl Foo { ... } - // impl ToStr for ~[T] { ... } + // impl ToString for ~[T] { ... } fn parse_item_impl(&mut self) -> ItemInfo { // First, parse type parameters if necessary. let generics = self.parse_generics(); @@ -4151,7 +4151,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()) @@ -4182,7 +4182,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()) @@ -4265,7 +4265,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()) } @@ -4545,7 +4545,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 `{}`", @@ -4803,7 +4803,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 dcf37e37ff0..df33f9dccc6 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -140,7 +140,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 => "-", @@ -155,7 +155,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(), @@ -168,9 +168,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 } @@ -213,15 +213,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) => { @@ -260,8 +260,8 @@ pub fn to_str(t: &Token) -> String { 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 { @@ -691,7 +691,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(); @@ -700,7 +700,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. -- cgit 1.4.1-3-g733a5