diff options
Diffstat (limited to 'src/makefile/conditional.rs')
-rw-r--r-- | src/makefile/conditional.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/makefile/conditional.rs b/src/makefile/conditional.rs index 6795051..0b4de01 100644 --- a/src/makefile/conditional.rs +++ b/src/makefile/conditional.rs @@ -1,3 +1,5 @@ +use anyhow::bail; + use super::token::TokenString; pub enum Line { @@ -47,12 +49,13 @@ pub enum StateAction { } impl StateAction { + #[allow(clippy::panic)] pub fn apply_to(self, stack: &mut Vec<State>) { match self { Self::Push(state) => stack.push(state), Self::Replace(state) => match stack.last_mut() { Some(x) => *x = state, - None => panic!("applying Replace on an empty condition stack"), + None => panic!("internal error: applying Replace on an empty condition stack"), }, Self::Pop => { stack.pop(); @@ -154,7 +157,7 @@ impl Line { State::SkippingUntilEndIf } Some(State::SkippingUntilElseOrEndIf) => State::Executing, - None => panic!("got an Else but not in a conditional"), + None => bail!("got an Else but not in a conditional"), }), Self::ElseIf(inner_condition) => match current_state { Some(State::Executing) | Some(State::SkippingUntilEndIf) => { @@ -163,9 +166,12 @@ impl Line { Some(State::SkippingUntilElseOrEndIf) => { inner_condition.action(current_state, is_macro_defined, expand_macro)? } - None => panic!("got an ElseIf but not in a conditional"), + None => bail!("got an ElseIf but not in a conditional"), + }, + Self::EndIf => match current_state { + Some(_) => StateAction::Pop, + None => bail!("got an EndIf but not in a conditional"), }, - Self::EndIf => StateAction::Pop, }) } } |