tt_call/unexpected.rs
1/// Fail due to an unexpected input token.
2///
3/// The compiler's error will indicate the source of the unexpected token to the
4/// user.
5///
6/// ```compile_fail
7/// use tt_call::error_unexpected;
8///
9/// fn main() {
10/// error_unexpected! { true }
11/// }
12/// ```
13///
14/// ```text
15/// error: no rules expected the token `true`
16/// --> src/unexpected.rs:5:25
17/// |
18/// 5 | error_unexpected! { true }
19/// | ^^^^
20/// ```
21#[macro_export]
22macro_rules! error_unexpected {
23 ($($tokens:tt)+) => {
24 $crate::private_unexpected! {
25 $($tokens)*
26 }
27 };
28}
29
30#[doc(hidden)]
31#[macro_export]
32macro_rules! private_unexpected {
33 () => {};
34}
35
36/// Fail due to an unexpected end of input.
37///
38/// The resulting compiler error is typically not good. Always prefer to use
39/// `error_unexpected!` or `error_unexpected_last!` if there are tokens on which
40/// an error could reasonably be triggered.
41///
42/// ```compile_fail
43/// use tt_call::error_eof;
44///
45/// fn main() {
46/// error_eof!{}
47/// }
48/// ```
49///
50/// ```text
51/// error: unexpected end of macro invocation
52/// --> src/unexpected.rs:5:5
53/// |
54/// 5 | error_eof!{}
55/// | ^^^^^^^^^^^^
56/// ```
57#[macro_export]
58macro_rules! error_eof {
59 () => {
60 $crate::private_eof! {}
61 };
62}
63
64#[doc(hidden)]
65#[macro_export]
66macro_rules! private_eof {
67 ($never:tt) => {};
68}
69
70/// Fail due to an unexpected input token, faulting the last token.
71///
72/// The compiler's error will indicate the source of the unexpected token to the
73/// user.
74///
75/// ```compile_fail
76/// use tt_call::error_unexpected_last;
77///
78/// fn main() {
79/// error_unexpected_last! { aaa bbb ccc }
80/// }
81/// ```
82///
83/// ```text
84/// error: no rules expected the token `true`
85/// --> src/unexpected.rs:5:38
86/// |
87/// 5 | error_unexpected_last! { aaa bbb ccc }
88/// | ^^^
89/// ```
90#[macro_export]
91macro_rules! error_unexpected_last {
92 ($($tokens:tt)+) => {
93 $crate::private_unexpected_last! {
94 $($tokens)*
95 }
96 };
97}
98
99#[doc(hidden)]
100#[macro_export]
101macro_rules! private_unexpected_last {
102 ($last:tt) => {
103 $crate::error_unexpected! {
104 $last
105 }
106 };
107
108 ($skip:tt $($rest:tt)*) => {
109 $crate::private_unexpected_last! {
110 $($rest)*
111 }
112 };
113}
114
115#[doc(hidden)]
116#[macro_export]
117macro_rules! private_unexpected_close_empty_square_brackets {
118 ([_]) => {};
119}
120
121#[doc(hidden)]
122#[macro_export]
123macro_rules! private_unexpected_close_square_bracket_after_ty_semicolon {
124 ([$ty:ty; _]) => {};
125}