Skip to main content

luaur_ast/methods/
parse_error_raise.rs

1use crate::records::location::Location;
2use crate::records::parse_error::ParseError;
3
4impl ParseError {
5    #[allow(non_snake_case)]
6    pub fn raise(location: Location, format: core::fmt::Arguments<'_>) -> ! {
7        let message = alloc::fmt::format(format);
8
9        // C++ `throw ParseError(...)`. The panic payload MUST be the ParseError
10        // object itself: `Parser::parse` catches the unwind and recovers the error
11        // via `downcast_ref::<ParseError>()`. Panicking with a formatted String
12        // (panic!("{}", ...)) made that downcast fail, so the panic escaped the
13        // parse boundary uncaught (every recursion-/error-limit test crashed).
14        let err =
15            crate::methods::parse_error_parse_error::parse_error_parse_error(location, message);
16        std::panic::panic_any(err);
17    }
18}
19
20#[allow(non_snake_case)]
21pub fn parse_error_raise(location: Location, format: core::fmt::Arguments<'_>) -> ! {
22    ParseError::raise(location, format)
23}