]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/ext/deriving/bounds.rs
syntax: Remove use of `pub use` globs
[rust.git] / src / libsyntax / ext / deriving / bounds.rs
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 use ext::deriving::generic::ty::*;
16
17 pub fn expand_deriving_bound(cx: &mut ExtCtxt,
18                              span: Span,
19                              mitem: @MetaItem,
20                              item: @Item,
21                              push: |@Item|) {
22
23     let name = match mitem.node {
24         MetaWord(ref tname) => {
25             match tname.get() {
26                 "Copy" => "Copy",
27                 "Send" => "Send",
28                 "Share" => "Share",
29                 ref tname => {
30                     cx.span_bug(span,
31                                 format!("expected built-in trait name but \
32                                          found {}",
33                                         *tname).as_slice())
34                 }
35             }
36         },
37         _ => {
38             return cx.span_err(span, "unexpected value in deriving, expected \
39                                       a trait")
40         }
41     };
42
43     let trait_def = TraitDef {
44         span: span,
45         attributes: Vec::new(),
46         path: Path::new(vec!("std", "kinds", name)),
47         additional_bounds: Vec::new(),
48         generics: LifetimeBounds::empty(),
49         methods: vec!()
50     };
51
52     trait_def.expand(cx, mitem, item, push)
53 }