1 // Copyright 2013-2015 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.
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.
11 #![allow(plugin_as_library)]
12 #![allow(unused_imports)]
13 // aux-build:macro_crate_test.rs
16 #![feature(plugin, rustc_attrs)]
17 #![plugin(macro_crate_test)]
21 extern crate macro_crate_test;
23 // The `caller(name, args...)` attribute emits a new nullary function named
24 // `name` that calls the annotated function with `args`. As an example, consider
27 // #[caller(simple, 1, "hello", 3.14)]
28 // fn f(num: isize, string: &'static str, float: f32) -> (isize, &'static str, float) {
29 // (num, string, float)
32 // This results in a function named `simple` that calls `f(1, "hello", 3.14)`.
33 // As a result, the expression `simple()` evaluates to `(1, "helllo", 3.14)`.
35 #[rustc_caller(simple, 1, "hello", 3.14)]
36 #[rustc_caller(simple1, 2, "bye", 6.28)]
37 #[rustc_caller(simple2, 3, "hi", 1.01)]
38 fn f(num: isize, string: &'static str, float: f32) -> (isize, &'static str, f32) {
42 #[rustc_caller(complex, true, 10)]
43 #[rustc_caller(complex1, false, 15)]
44 #[rustc_caller(complex2, true, 20)]
45 fn g(emit: bool, num: i32) -> Option<i32> {
53 assert_eq!(simple(), (1, "hello", 3.14));
54 assert_eq!(simple1(), (2, "bye", 6.28));
55 assert_eq!(simple2(), (3, "hi", 1.01));
57 assert_eq!(complex(), Some(10));
58 assert_eq!(complex1(), None);
59 assert_eq!(complex2(), Some(20));