From e1128fe55d91ca60086de45c911b4568d2eec9ee Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 31 Mar 2021 13:43:46 -0600 Subject: awolnation voice BAIL --- src/makefile/conditional.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/makefile/conditional.rs') 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) { 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, }) } } -- cgit v1.2.3