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