]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/diagnostics/macros.rs
25e0428248df4f7a9a6d03ad9ff75babb52582f5
[rust.git] / src / libsyntax / diagnostics / macros.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 #[macro_export]
12 macro_rules! register_diagnostic {
13     ($code:tt, $description:tt) => (__register_diagnostic! { $code, $description });
14     ($code:tt) => (__register_diagnostic! { $code })
15 }
16
17 #[macro_export]
18 macro_rules! span_fatal {
19     ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
20         __diagnostic_used!($code);
21         $session.span_fatal_with_code($span, &format!($($message)*), stringify!($code))
22     })
23 }
24
25 #[macro_export]
26 macro_rules! span_err {
27     ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
28         __diagnostic_used!($code);
29         $session.span_err_with_code($span, &format!($($message)*), stringify!($code))
30     })
31 }
32
33 #[macro_export]
34 macro_rules! span_warn {
35     ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
36         __diagnostic_used!($code);
37         $session.span_warn_with_code($span, &format!($($message)*), stringify!($code))
38     })
39 }
40
41 #[macro_export]
42 macro_rules! span_err_or_warn {
43     ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
44         __diagnostic_used!($code);
45         if $is_warning {
46             $session.span_warn_with_code($span, &format!($($message)*), stringify!($code))
47         } else {
48             $session.span_err_with_code($span, &format!($($message)*), stringify!($code))
49         }
50     })
51 }
52
53 #[macro_export]
54 macro_rules! struct_span_fatal {
55     ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
56         __diagnostic_used!($code);
57         $session.struct_span_fatal_with_code($span, &format!($($message)*), stringify!($code))
58     })
59 }
60
61 #[macro_export]
62 macro_rules! struct_span_err {
63     ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
64         __diagnostic_used!($code);
65         $session.struct_span_err_with_code($span, &format!($($message)*), stringify!($code))
66     })
67 }
68
69 #[macro_export]
70 macro_rules! struct_span_warn {
71     ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
72         __diagnostic_used!($code);
73         $session.struct_span_warn_with_code($span, &format!($($message)*), stringify!($code))
74     })
75 }
76
77 #[macro_export]
78 macro_rules! struct_span_err_or_warn {
79     ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
80         __diagnostic_used!($code);
81         if $is_warning {
82             $session.struct_span_warn_with_code($span, &format!($($message)*), stringify!($code))
83         } else {
84             $session.struct_span_err_with_code($span, &format!($($message)*), stringify!($code))
85         }
86     })
87 }
88
89 #[macro_export]
90 macro_rules! span_note {
91     ($err:expr, $span:expr, $($message:tt)*) => ({
92         ($err).span_note($span, &format!($($message)*));
93     })
94 }
95
96 #[macro_export]
97 macro_rules! span_help {
98     ($err:expr, $span:expr, $($message:tt)*) => ({
99         ($err).span_help($span, &format!($($message)*));
100     })
101 }
102
103 #[macro_export]
104 macro_rules! help {
105     ($err:expr, $($message:tt)*) => ({
106         ($err).help(&format!($($message)*));
107     })
108 }
109
110 #[macro_export]
111 macro_rules! register_diagnostics {
112     ($($code:tt),*) => (
113         $(register_diagnostic! { $code })*
114     );
115     ($($code:tt),*,) => (
116         $(register_diagnostic! { $code })*
117     )
118 }
119
120 #[macro_export]
121 macro_rules! register_long_diagnostics {
122     ($($code:tt: $description:tt),*) => (
123         $(register_diagnostic! { $code, $description })*
124     );
125     ($($code:tt: $description:tt),*,) => (
126         $(register_diagnostic! { $code, $description })*
127     )
128 }