]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/macro-crate-multi-decorator-literals.rs
Auto merge of #54919 - alexcrichton:update-cargo, r=Mark-Simulacrum
[rust.git] / src / test / run-pass-fulldeps / macro-crate-multi-decorator-literals.rs
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.
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 #![allow(plugin_as_library)]
12 #![allow(unused_imports)]
13 // aux-build:macro_crate_test.rs
14 // ignore-stage1
15
16 #![feature(plugin, rustc_attrs)]
17 #![plugin(macro_crate_test)]
18
19 #[macro_use]
20 #[no_link]
21 extern crate macro_crate_test;
22
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
25 // the following:
26 //
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)
30 //     }
31 //
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)`.
34
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) {
39     (num, string, float)
40 }
41
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> {
46     match emit {
47         true => Some(num),
48         false => None
49     }
50 }
51
52 fn main() {
53     assert_eq!(simple(), (1, "hello", 3.14));
54     assert_eq!(simple1(), (2, "bye", 6.28));
55     assert_eq!(simple2(), (3, "hi", 1.01));
56
57     assert_eq!(complex(), Some(10));
58     assert_eq!(complex1(), None);
59     assert_eq!(complex2(), Some(20));
60 }