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 /src/libsyntax | |
| parent | b78b749810f4ed53e8287adfb284f9f32f16b73c (diff) | |
| download | rust-8761f79485f11ef03eb6cb569ccb9f4c73e68f11.tar.gz rust-8761f79485f11ef03eb6cb569ccb9f4c73e68f11.zip | |
Remove deriving(ToStr)
This has been superseded by deriving(Show). cc #9806
Diffstat (limited to 'src/libsyntax')
| -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 |
4 files changed, 2 insertions, 136 deletions
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)") - }; -} |
