]> git.lizzy.rs Git - rust.git/commitdiff
Remove deriving(ToStr)
authorAlex Crichton <alex@alexcrichton.com>
Thu, 20 Feb 2014 03:18:33 +0000 (19:18 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 24 Feb 2014 08:15:17 +0000 (00:15 -0800)
This has been superseded by deriving(Show).

cc #9806

src/libcollections/btree.rs
src/libcollections/lru_cache.rs
src/libextra/url.rs
src/libsyntax/abi.rs
src/libsyntax/crateid.rs
src/libsyntax/ext/deriving/mod.rs
src/libsyntax/ext/deriving/to_str.rs [deleted file]
src/libuuid/lib.rs
src/test/run-pass/super-fast-paren-parsing.rs

index cc6a5eda7594f623e848dc4754719783895b2bdb..171203b00b806c7e35f47f5a339a20be559a9d7e 100644 (file)
@@ -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)
     }
index b5e44cda6658757950600319d327b7e826456578..68bc5f1b6c4ff60c7818b604b1ebfd475d29e4f1 100644 (file)
@@ -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)),
                 }
             }
         }
index 6e0cd72e3e7c125a05c4bf97f54d3f750e27c810..0292a18817ccd8bf457bb56d60b66a18b0effdfd 100644 (file)
@@ -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 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
 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 {
index faf24da74ccfc8040d009f016d8a091079506a21..9349e5c8e98d67c13d42a4c1d7ce5b39d51f4245 100644 (file)
@@ -281,7 +281,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
 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; }
index d04bedc65b5c5e84e836f80ac8d6455e8659f5bb..2417a6fa1bacf9063081c0d0deb3021e8321f5e6 100644 (file)
@@ -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(),
index 95b9a45b9fc2d19e59c16fd9177defdefb298579..9c823449d2141590f5e89c917bbdd1efaa60b093 100644 (file)
@@ -27,7 +27,6 @@
 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 @@ macro_rules! expand(($func:path) => ($func(cx, titem.span,
 
                             "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 (file)
index 5cb81d9..0000000
+++ /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)")
-    };
-}
index 7a078e4b571b2a8ffb6792bb029f34f4479b7d23..7a3ed09a492d710ce3c4583ef29f247fef8d3c9a 100644 (file)
@@ -64,15 +64,15 @@ fn main() {
 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};
 
index 759b066c8dbf5d257fb7056bf2abb6e36116a6f5..70c7200bee9aeb4433866b5bcb5707e2285bdf15 100644 (file)
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// ignore-pretty
+
 static a: int =
 (((((((((((((((((((((((((((((((((((((((((((((((((((
 (((((((((((((((((((((((((((((((((((((((((((((((((((