]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/ext/deriving/cmp/totaleq.rs
libsyntax: Fix errors arising from the automated `~[T]` conversion
[rust.git] / src / libsyntax / ext / deriving / cmp / totaleq.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use ast::{MetaItem, Item, Expr};
12 use codemap::Span;
13 use ext::base::ExtCtxt;
14 use ext::build::AstBuilder;
15 use ext::deriving::generic::*;
16
17 use std::vec_ng::Vec;
18
19 pub fn expand_deriving_totaleq(cx: &mut ExtCtxt,
20                                span: Span,
21                                mitem: @MetaItem,
22                                item: @Item,
23                                push: |@Item|) {
24     fn cs_equals(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
25         cs_and(|cx, span, _, _| cx.expr_bool(span, false),
26                cx, span, substr)
27     }
28
29     let trait_def = TraitDef {
30         span: span,
31         attributes: Vec::new(),
32         path: Path::new(vec!("std", "cmp", "TotalEq")),
33         additional_bounds: Vec::new(),
34         generics: LifetimeBounds::empty(),
35         methods: vec!(
36             MethodDef {
37                 name: "equals",
38                 generics: LifetimeBounds::empty(),
39                 explicit_self: borrowed_explicit_self(),
40                 args: vec!(borrowed_self()),
41                 ret_ty: Literal(Path::new(vec!("bool"))),
42                 inline: true,
43                 const_nonmatching: true,
44                 combine_substructure: cs_equals
45             }
46         )
47     };
48     trait_def.expand(cx, mitem, item, push)
49 }