]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | ||
85aaf69f SL |
17 | #[macro_export] |
18 | macro_rules! span_fatal { | |
19 | ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ | |
20 | __diagnostic_used!($code); | |
abe05a73 XL |
21 | $session.span_fatal_with_code( |
22 | $span, | |
23 | &format!($($message)*), | |
24 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
25 | ) | |
85aaf69f SL |
26 | }) |
27 | } | |
28 | ||
1a4d82fc JJ |
29 | #[macro_export] |
30 | macro_rules! span_err { | |
31 | ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ | |
32 | __diagnostic_used!($code); | |
abe05a73 XL |
33 | $session.span_err_with_code( |
34 | $span, | |
35 | &format!($($message)*), | |
36 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
37 | ) | |
1a4d82fc JJ |
38 | }) |
39 | } | |
40 | ||
9cc50fc6 SL |
41 | #[macro_export] |
42 | macro_rules! span_warn { | |
43 | ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ | |
44 | __diagnostic_used!($code); | |
abe05a73 XL |
45 | $session.span_warn_with_code( |
46 | $span, | |
47 | &format!($($message)*), | |
48 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
49 | ) | |
9cc50fc6 SL |
50 | }) |
51 | } | |
52 | ||
7cac9316 XL |
53 | #[macro_export] |
54 | macro_rules! struct_err { | |
55 | ($session:expr, $code:ident, $($message:tt)*) => ({ | |
56 | __diagnostic_used!($code); | |
abe05a73 XL |
57 | $session.struct_err_with_code( |
58 | &format!($($message)*), | |
59 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
60 | ) | |
7cac9316 XL |
61 | }) |
62 | } | |
63 | ||
e9174d1e SL |
64 | #[macro_export] |
65 | macro_rules! span_err_or_warn { | |
66 | ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ | |
67 | __diagnostic_used!($code); | |
68 | if $is_warning { | |
abe05a73 XL |
69 | $session.span_warn_with_code( |
70 | $span, | |
71 | &format!($($message)*), | |
72 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
73 | ) | |
e9174d1e | 74 | } else { |
abe05a73 XL |
75 | $session.span_err_with_code( |
76 | $span, | |
77 | &format!($($message)*), | |
78 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
79 | ) | |
e9174d1e SL |
80 | } |
81 | }) | |
82 | } | |
83 | ||
1a4d82fc | 84 | #[macro_export] |
9cc50fc6 | 85 | macro_rules! struct_span_fatal { |
1a4d82fc JJ |
86 | ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ |
87 | __diagnostic_used!($code); | |
abe05a73 XL |
88 | $session.struct_span_fatal_with_code( |
89 | $span, | |
90 | &format!($($message)*), | |
91 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
92 | ) | |
9cc50fc6 SL |
93 | }) |
94 | } | |
95 | ||
96 | #[macro_export] | |
97 | macro_rules! struct_span_err { | |
98 | ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ | |
99 | __diagnostic_used!($code); | |
abe05a73 XL |
100 | $session.struct_span_err_with_code( |
101 | $span, | |
102 | &format!($($message)*), | |
103 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
104 | ) | |
9cc50fc6 SL |
105 | }) |
106 | } | |
107 | ||
041b39d2 XL |
108 | #[macro_export] |
109 | macro_rules! type_error_struct { | |
110 | ($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({ | |
111 | if $typ.references_error() { | |
112 | $session.diagnostic().struct_dummy() | |
113 | } else { | |
114 | struct_span_err!($session, $span, $code, $($message)*) | |
115 | } | |
116 | }) | |
117 | } | |
118 | ||
9cc50fc6 SL |
119 | #[macro_export] |
120 | macro_rules! struct_span_warn { | |
121 | ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ | |
122 | __diagnostic_used!($code); | |
abe05a73 XL |
123 | $session.struct_span_warn_with_code( |
124 | $span, | |
125 | &format!($($message)*), | |
126 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
127 | ) | |
9cc50fc6 SL |
128 | }) |
129 | } | |
130 | ||
131 | #[macro_export] | |
132 | macro_rules! struct_span_err_or_warn { | |
133 | ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ | |
134 | __diagnostic_used!($code); | |
135 | if $is_warning { | |
abe05a73 XL |
136 | $session.struct_span_warn_with_code( |
137 | $span, | |
138 | &format!($($message)*), | |
139 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
140 | ) | |
9cc50fc6 | 141 | } else { |
abe05a73 XL |
142 | $session.struct_span_err_with_code( |
143 | $span, | |
144 | &format!($($message)*), | |
145 | $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), | |
146 | ) | |
9cc50fc6 | 147 | } |
1a4d82fc JJ |
148 | }) |
149 | } | |
150 | ||
151 | #[macro_export] | |
152 | macro_rules! span_note { | |
9cc50fc6 SL |
153 | ($err:expr, $span:expr, $($message:tt)*) => ({ |
154 | ($err).span_note($span, &format!($($message)*)); | |
1a4d82fc JJ |
155 | }) |
156 | } | |
157 | ||
158 | #[macro_export] | |
159 | macro_rules! span_help { | |
9cc50fc6 SL |
160 | ($err:expr, $span:expr, $($message:tt)*) => ({ |
161 | ($err).span_help($span, &format!($($message)*)); | |
1a4d82fc JJ |
162 | }) |
163 | } | |
164 | ||
c34b1796 | 165 | #[macro_export] |
a7813a04 XL |
166 | macro_rules! help { |
167 | ($err:expr, $($message:tt)*) => ({ | |
168 | ($err).help(&format!($($message)*)); | |
c34b1796 AL |
169 | }) |
170 | } | |
171 | ||
1a4d82fc JJ |
172 | #[macro_export] |
173 | macro_rules! register_diagnostics { | |
174 | ($($code:tt),*) => ( | |
175 | $(register_diagnostic! { $code })* | |
c1a9b12d SL |
176 | ); |
177 | ($($code:tt),*,) => ( | |
178 | $(register_diagnostic! { $code })* | |
1a4d82fc JJ |
179 | ) |
180 | } | |
181 | ||
85aaf69f SL |
182 | #[macro_export] |
183 | macro_rules! register_long_diagnostics { | |
184 | ($($code:tt: $description:tt),*) => ( | |
185 | $(register_diagnostic! { $code, $description })* | |
c1a9b12d SL |
186 | ); |
187 | ($($code:tt: $description:tt),*,) => ( | |
188 | $(register_diagnostic! { $code, $description })* | |
85aaf69f SL |
189 | ) |
190 | } |