diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-02-19 19:18:33 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-02-24 00:15:17 -0800 |
| commit | 8761f79485f11ef03eb6cb569ccb9f4c73e68f11 (patch) | |
| tree | 411eefd07ab744efb0d4934e12900a40912b44d6 | |
| parent | b78b749810f4ed53e8287adfb284f9f32f16b73c (diff) | |
| download | rust-8761f79485f11ef03eb6cb569ccb9f4c73e68f11.tar.gz rust-8761f79485f11ef03eb6cb569ccb9f4c73e68f11.zip | |
Remove deriving(ToStr)
This has been superseded by deriving(Show). cc #9806
| -rw-r--r-- | src/libcollections/btree.rs | 8 | ||||
| -rw-r--r-- | src/libcollections/lru_cache.rs | 14 | ||||
| -rw-r--r-- | src/libextra/url.rs | 18 | ||||
| -rw-r--r-- | src/libsyntax/abi.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/crateid.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/to_str.rs | 132 | ||||
| -rw-r--r-- | src/libuuid/lib.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/super-fast-paren-parsing.rs | 2 |
9 files changed, 27 insertions, 159 deletions
diff --git a/src/libcollections/btree.rs b/src/libcollections/btree.rs index cc6a5eda759..171203b00b8 100644 --- a/src/libcollections/btree.rs +++ b/src/libcollections/btree.rs @@ -405,8 +405,8 @@ impl<K: fmt::Show + TotalOrd, V: fmt::Show> fmt::Show for Leaf<K, V> { ///Returns a string representation of a Leaf. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for (i, s) in self.elts.iter().enumerate() { - if i != 0 { if_ok!(write!(f.buf, " // ")) } - if_ok!(write!(f.buf, "{}", *s)) + if i != 0 { try!(write!(f.buf, " // ")) } + try!(write!(f.buf, "{}", *s)) } Ok(()) } @@ -626,8 +626,8 @@ impl<K: fmt::Show + TotalOrd, V: fmt::Show> fmt::Show for Branch<K, V> { ///Returns a string representation of a Branch. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for (i, s) in self.elts.iter().enumerate() { - if i != 0 { if_ok!(write!(f.buf, " // ")) } - if_ok!(write!(f.buf, "{}", *s)) + if i != 0 { try!(write!(f.buf, " // ")) } + try!(write!(f.buf, "{}", *s)) } write!(f.buf, " // rightmost child: ({}) ", *self.rightmost_child) } diff --git a/src/libcollections/lru_cache.rs b/src/libcollections/lru_cache.rs index b5e44cda665..68bc5f1b6c4 100644 --- a/src/libcollections/lru_cache.rs +++ b/src/libcollections/lru_cache.rs @@ -222,24 +222,24 @@ impl<A: fmt::Show + Hash + Eq, B: fmt::Show> fmt::Show for LruCache<A, B> { /// Return a string that lists the key-value pairs from most-recently /// used to least-recently used. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(write!(f.buf, r"\{")); + try!(write!(f.buf, r"\{")); let mut cur = self.head; for i in range(0, self.len()) { - if i > 0 { if_ok!(write!(f.buf, ", ")) } + if i > 0 { try!(write!(f.buf, ", ")) } unsafe { cur = (*cur).next; match (*cur).key { // should never print nil - None => if_ok!(write!(f.buf, "nil")), - Some(ref k) => if_ok!(write!(f.buf, "{}", *k)), + None => try!(write!(f.buf, "nil")), + Some(ref k) => try!(write!(f.buf, "{}", *k)), } } - if_ok!(write!(f.buf, ": ")); + try!(write!(f.buf, ": ")); unsafe { match (*cur).value { // should never print nil - None => if_ok!(write!(f.buf, "nil")), - Some(ref value) => if_ok!(write!(f.buf, "{}", *value)), + None => try!(write!(f.buf, "nil")), + Some(ref value) => try!(write!(f.buf, "{}", *value)), } } } diff --git a/src/libextra/url.rs b/src/libextra/url.rs index 6e0cd72e3e7..0292a18817c 100644 --- a/src/libextra/url.rs +++ b/src/libextra/url.rs @@ -803,25 +803,25 @@ impl fmt::Show for Url { * result in just "http://somehost.com". */ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(write!(f.buf, "{}:", self.scheme)); + try!(write!(f.buf, "{}:", self.scheme)); if !self.host.is_empty() { - if_ok!(write!(f.buf, "//")); + try!(write!(f.buf, "//")); match self.user { - Some(ref user) => if_ok!(write!(f.buf, "{}", *user)), + Some(ref user) => try!(write!(f.buf, "{}", *user)), None => {} } match self.port { - Some(ref port) => if_ok!(write!(f.buf, "{}:{}", self.host, + Some(ref port) => try!(write!(f.buf, "{}:{}", self.host, *port)), - None => if_ok!(write!(f.buf, "{}", self.host)), + None => try!(write!(f.buf, "{}", self.host)), } } - if_ok!(write!(f.buf, "{}", self.path)); + try!(write!(f.buf, "{}", self.path)); if !self.query.is_empty() { - if_ok!(write!(f.buf, "?{}", query_to_str(&self.query))); + try!(write!(f.buf, "?{}", query_to_str(&self.query))); } match self.fragment { @@ -834,9 +834,9 @@ impl fmt::Show for Url { impl fmt::Show for Path { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(write!(f.buf, "{}", self.path)); + try!(write!(f.buf, "{}", self.path)); if !self.query.is_empty() { - if_ok!(write!(f.buf, "?{}", self.query)) + try!(write!(f.buf, "?{}", self.query)) } match self.fragment { diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index faf24da74cc..9349e5c8e98 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -281,7 +281,7 @@ impl fmt::Show for Abi { impl fmt::Show for AbiSet { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(write!(f.buf, "\"")); + try!(write!(f.buf, "\"")); let mut first = true; self.each(|abi| { if first { first = false; } diff --git a/src/libsyntax/crateid.rs b/src/libsyntax/crateid.rs index d04bedc65b5..2417a6fa1ba 100644 --- a/src/libsyntax/crateid.rs +++ b/src/libsyntax/crateid.rs @@ -30,7 +30,7 @@ pub struct CrateId { impl fmt::Show for CrateId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if_ok!(write!(f.buf, "{}", self.path)); + try!(write!(f.buf, "{}", self.path)); let version = match self.version { None => "0.0", Some(ref version) => version.as_slice(), diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 95b9a45b9fc..9c823449d21 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -27,7 +27,6 @@ pub mod encodable; pub mod decodable; pub mod hash; pub mod rand; -pub mod to_str; pub mod show; pub mod zero; pub mod default; @@ -85,7 +84,6 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt, "Rand" => expand!(rand::expand_deriving_rand), - "ToStr" => expand!(to_str::expand_deriving_to_str), "Show" => expand!(show::expand_deriving_show), "Zero" => expand!(zero::expand_deriving_zero), diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs deleted file mode 100644 index 5cb81d9e762..00000000000 --- a/src/libsyntax/ext/deriving/to_str.rs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use ast; -use ast::{MetaItem, Item, Expr}; -use codemap::Span; -use ext::base::ExtCtxt; -use ext::build::AstBuilder; -use ext::deriving::generic::*; -use parse::token::InternedString; -use parse::token; - -pub fn expand_deriving_to_str(cx: &mut ExtCtxt, - span: Span, - mitem: @MetaItem, - item: @Item, - push: |@Item|) { - let trait_def = TraitDef { - span: span, - attributes: ~[], - path: Path::new(~["std", "to_str", "ToStr"]), - additional_bounds: ~[], - generics: LifetimeBounds::empty(), - methods: ~[ - MethodDef { - name: "to_str", - generics: LifetimeBounds::empty(), - explicit_self: borrowed_explicit_self(), - args: ~[], - ret_ty: Ptr(~Literal(Path::new_local("str")), Send), - inline: false, - const_nonmatching: false, - combine_substructure: to_str_substructure - } - ] - }; - trait_def.expand(cx, mitem, item, push) -} - -// It used to be the case that this deriving implementation invoked -// std::repr::repr_to_str, but this isn't sufficient because it -// doesn't invoke the to_str() method on each field. Hence we mirror -// the logic of the repr_to_str() method, but with tweaks to call to_str() -// on sub-fields. -fn to_str_substructure(cx: &mut ExtCtxt, span: Span, substr: &Substructure) - -> @Expr { - let to_str = cx.ident_of("to_str"); - - let doit = |start: &str, - end: InternedString, - name: ast::Ident, - fields: &[FieldInfo]| { - if fields.len() == 0 { - cx.expr_str_uniq(span, token::get_ident(name)) - } else { - let buf = cx.ident_of("buf"); - let interned_str = token::get_ident(name); - let start = - token::intern_and_get_ident(interned_str.get() + start); - let init = cx.expr_str_uniq(span, start); - let mut stmts = ~[cx.stmt_let(span, true, buf, init)]; - let push_str = cx.ident_of("push_str"); - - { - let push = |s: @Expr| { - let ebuf = cx.expr_ident(span, buf); - let call = cx.expr_method_call(span, ebuf, push_str, ~[s]); - stmts.push(cx.stmt_expr(call)); - }; - - for (i, &FieldInfo {name, span, self_, .. }) in fields.iter().enumerate() { - if i > 0 { - push(cx.expr_str(span, InternedString::new(", "))); - } - match name { - None => {} - Some(id) => { - let interned_id = token::get_ident(id); - let name = interned_id.get() + ": "; - push(cx.expr_str(span, - token::intern_and_get_ident(name))); - } - } - push(cx.expr_method_call(span, self_, to_str, ~[])); - } - push(cx.expr_str(span, end)); - } - - cx.expr_block(cx.block(span, stmts, Some(cx.expr_ident(span, buf)))) - } - }; - - return match *substr.fields { - Struct(ref fields) => { - if fields.len() == 0 || fields[0].name.is_none() { - doit("(", - InternedString::new(")"), - substr.type_ident, - *fields) - } else { - doit("{", - InternedString::new("}"), - substr.type_ident, - *fields) - } - } - - EnumMatching(_, variant, ref fields) => { - match variant.node.kind { - ast::TupleVariantKind(..) => - doit("(", - InternedString::new(")"), - variant.node.name, - *fields), - ast::StructVariantKind(..) => - doit("{", - InternedString::new("}"), - variant.node.name, - *fields), - } - } - - _ => cx.bug("expected Struct or EnumMatching in deriving(ToStr)") - }; -} diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index 7a078e4b571..7a3ed09a492 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -65,14 +65,14 @@ extern crate test; extern crate serialize; use std::cast::{transmute,transmute_copy}; -use std::cast::{transmute,transmute_copy}; use std::char::Char; -use std::cmp::Eq; -use std::cmp::Eq; use std::fmt; use std::hash::{Hash, sip}; use std::num::FromStrRadix; use std::rand::Rng; +use std::rand; +use std::str; +use std::vec; use serialize::{Encoder, Encodable, Decoder, Decodable}; diff --git a/src/test/run-pass/super-fast-paren-parsing.rs b/src/test/run-pass/super-fast-paren-parsing.rs index 759b066c8db..70c7200bee9 100644 --- a/src/test/run-pass/super-fast-paren-parsing.rs +++ b/src/test/run-pass/super-fast-paren-parsing.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-pretty + static a: int = ((((((((((((((((((((((((((((((((((((((((((((((((((( ((((((((((((((((((((((((((((((((((((((((((((((((((( |
