1 // Copyright 2014 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, MetaWord, Item};
12 use codemap::Span;
13 use ext::base::ExtCtxt;
14 use ext::deriving::generic::*;
15
16 pub fn expand_deriving_bound(cx: &mut ExtCtxt,
17 span: Span,
18 mitem: @MetaItem,
19 item: @Item,
20 push: |@Item|) {
21
22 let name = match mitem.node {
23 MetaWord(ref tname) => {
24 match tname.get() {
25 "Copy" => "Copy",
26 "Send" => "Send",
27 "Share" => "Share",
28 ref tname => cx.span_bug(span,
29 format!("expected built-in trait name but found {}",
30 *tname))
31 }
32 },
33 _ => return cx.span_err(span, "unexpected value in deriving, expected a trait")
34 };
35
36 let trait_def = TraitDef {
37 span: span,
38 attributes: Vec::new(),
39 path: Path::new(vec!("std", "kinds", name)),
40 additional_bounds: Vec::new(),
41 generics: LifetimeBounds::empty(),
42 methods: vec!()
43 };
44
45 trait_def.expand(cx, mitem, item, push)
46 }