use solang_parser::pt;
pub trait SafeUnwrap<T> {
fn safe_unwrap(&self) -> &T;
fn safe_unwrap_mut(&mut self) -> &mut T;
}
#[inline(never)]
#[cold]
#[track_caller]
fn invalid() -> ! {
panic!("invalid parse tree")
}
macro_rules! impl_ {
($($t:ty),+ $(,)?) => {
$(
impl SafeUnwrap<$t> for Option<$t> {
#[inline]
#[track_caller]
fn safe_unwrap(&self) -> &$t {
match *self {
Some(ref x) => x,
None => invalid(),
}
}
#[inline]
#[track_caller]
fn safe_unwrap_mut(&mut self) -> &mut $t {
match *self {
Some(ref mut x) => x,
None => invalid(),
}
}
}
)+
};
}
impl_!(pt::Identifier, pt::StringLiteral);