]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/diagnostics/macros.rs
Introduce a "origin/cause" for new requirements (or bugfixes...) introduced by RFC...
[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_err_or_warn {
35     ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
36         __diagnostic_used!($code);
37         if $is_warning {
38             $session.span_warn_with_code($span, &format!($($message)*), stringify!($code))
39         } else {
40             $session.span_err_with_code($span, &format!($($message)*), stringify!($code))
41         }
42     })
43 }
44
45 #[macro_export]
46 macro_rules! span_warn {
47     ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
48         __diagnostic_used!($code);
49         $session.span_warn_with_code($span, &format!($($message)*), stringify!($code))
50     })
51 }
52
53 #[macro_export]
54 macro_rules! span_note {
55     ($session:expr, $span:expr, $($message:tt)*) => ({
56         ($session).span_note($span, &format!($($message)*))
57     })
58 }
59
60 #[macro_export]
61 macro_rules! span_help {
62     ($session:expr, $span:expr, $($message:tt)*) => ({
63         ($session).span_help($span, &format!($($message)*))
64     })
65 }
66
67 #[macro_export]
68 macro_rules! fileline_help {
69     ($session:expr, $span:expr, $($message:tt)*) => ({
70         ($session).fileline_help($span, &format!($($message)*))
71     })
72 }
73
74 #[macro_export]
75 macro_rules! register_diagnostics {
76     ($($code:tt),*) => (
77         $(register_diagnostic! { $code })*
78     );
79     ($($code:tt),*,) => (
80         $(register_diagnostic! { $code })*
81     )
82 }
83
84 #[macro_export]
85 macro_rules! register_long_diagnostics {
86     ($($code:tt: $description:tt),*) => (
87         $(register_diagnostic! { $code, $description })*
88     );
89     ($($code:tt: $description:tt),*,) => (
90         $(register_diagnostic! { $code, $description })*
91     )
92 }