From 8761f79485f11ef03eb6cb569ccb9f4c73e68f11 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 19 Feb 2014 19:18:33 -0800 Subject: Remove deriving(ToStr) This has been superseded by deriving(Show). cc #9806 --- src/libsyntax/ext/deriving/mod.rs | 2 - src/libsyntax/ext/deriving/to_str.rs | 132 ----------------------------------- 2 files changed, 134 deletions(-) delete mode 100644 src/libsyntax/ext/deriving/to_str.rs (limited to 'src/libsyntax/ext') 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 or the MIT license -// , 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)") - }; -} -- cgit 1.4.1-3-g733a5