]> git.proxmox.com Git - rustc.git/blob - src/libsyntax/diagnostics/macros.rs
New upstream version 1.23.0+dfsg1
[rustc.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(
22 $span,
23 &format!($($message)*),
24 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
25 )
26 })
27 }
28
29 #[macro_export]
30 macro_rules! span_err {
31 ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
32 __diagnostic_used!($code);
33 $session.span_err_with_code(
34 $span,
35 &format!($($message)*),
36 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
37 )
38 })
39 }
40
41 #[macro_export]
42 macro_rules! span_warn {
43 ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
44 __diagnostic_used!($code);
45 $session.span_warn_with_code(
46 $span,
47 &format!($($message)*),
48 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
49 )
50 })
51 }
52
53 #[macro_export]
54 macro_rules! struct_err {
55 ($session:expr, $code:ident, $($message:tt)*) => ({
56 __diagnostic_used!($code);
57 $session.struct_err_with_code(
58 &format!($($message)*),
59 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
60 )
61 })
62 }
63
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 {
69 $session.span_warn_with_code(
70 $span,
71 &format!($($message)*),
72 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
73 )
74 } else {
75 $session.span_err_with_code(
76 $span,
77 &format!($($message)*),
78 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
79 )
80 }
81 })
82 }
83
84 #[macro_export]
85 macro_rules! struct_span_fatal {
86 ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
87 __diagnostic_used!($code);
88 $session.struct_span_fatal_with_code(
89 $span,
90 &format!($($message)*),
91 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
92 )
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);
100 $session.struct_span_err_with_code(
101 $span,
102 &format!($($message)*),
103 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
104 )
105 })
106 }
107
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
119 #[macro_export]
120 macro_rules! struct_span_warn {
121 ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
122 __diagnostic_used!($code);
123 $session.struct_span_warn_with_code(
124 $span,
125 &format!($($message)*),
126 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
127 )
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 {
136 $session.struct_span_warn_with_code(
137 $span,
138 &format!($($message)*),
139 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
140 )
141 } else {
142 $session.struct_span_err_with_code(
143 $span,
144 &format!($($message)*),
145 $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
146 )
147 }
148 })
149 }
150
151 #[macro_export]
152 macro_rules! span_note {
153 ($err:expr, $span:expr, $($message:tt)*) => ({
154 ($err).span_note($span, &format!($($message)*));
155 })
156 }
157
158 #[macro_export]
159 macro_rules! span_help {
160 ($err:expr, $span:expr, $($message:tt)*) => ({
161 ($err).span_help($span, &format!($($message)*));
162 })
163 }
164
165 #[macro_export]
166 macro_rules! help {
167 ($err:expr, $($message:tt)*) => ({
168 ($err).help(&format!($($message)*));
169 })
170 }
171
172 #[macro_export]
173 macro_rules! register_diagnostics {
174 ($($code:tt),*) => (
175 $(register_diagnostic! { $code })*
176 );
177 ($($code:tt),*,) => (
178 $(register_diagnostic! { $code })*
179 )
180 }
181
182 #[macro_export]
183 macro_rules! register_long_diagnostics {
184 ($($code:tt: $description:tt),*) => (
185 $(register_diagnostic! { $code, $description })*
186 );
187 ($($code:tt: $description:tt),*,) => (
188 $(register_diagnostic! { $code, $description })*
189 )
190 }