/// Unpack a slice of waves.
///
/// Ensures that either the waves are all unconditional, or all have a
/// condition except for the optional last one.
Unpack a slice of waves.
Ensures that either the waves are all unconditional, or all have a
condition except for the optional last one.
Unpack a slice of waves . Ensures that either the waves are all unconditional or all have a condition except for the optional last one .
fn unpack_cond_or_uncond_waves(
        &self,
        ast: &'ast [ast::CondWave],
    ) -> Result<CondOrUncond<'ast>> {
        assert!(!ast.is_empty());
        let any_cond = ast.iter().any(|w| w.1.is_some());
        if any_cond {
            // Cut away the optional trailing else without condition.
            let (slice, otherwise) = match *ast.last().unwrap() {
                ast::CondWave(ref wave, None) => (&ast[..ast.len() - 2], Some(wave)),
                _ => (&ast[..], None),
            };
            let conds = slice
                .into_iter()
                .map(|&ast::CondWave(ref wave, ref cond)| match *cond {
                    Some(ref cond) => Ok((wave, cond)),
                    None => {
                        self.emit(
                            DiagBuilder2::error(format!(
                                "`{}` missing a `when` condition",
                                wave.span.extract()
                            ))
                            .span(wave.span)
                            .add_note(
                                "Either all or none of the waveforms or expressions in the \
                                 assignment can have a `when` condition.",
                            ),
                        );
                        Err(())
                    }
                })
                .collect::<Vec<Result<_>>>()
                .into_iter()
                .collect::<Result<Vec<_>>>()?;
            Ok(CondOrUncond::Cond(conds, otherwise))
        } else {
            if ast.len() != 1 {
                self.emit(
                    DiagBuilder2::error(format!("more than one waveform or expression"))
                        .span(ast[0].0.span)
                        .add_note(
                            "An unconditional assignment must have exactly one waveform or \
                             expression.",
                        ),
                );
                Err(())
            } else {
                Ok(CondOrUncond::Uncond(&ast[0].0))
            }
        }
    }
fn unpack_cond_or_uncond_waves ( & self , ast : & ' ast [ ast :: CondWave ] , ) -> Result < CondOrUncond < ' ast > > { assert ! ( ast is_empty ( ) ) ; let any_cond = ast . iter ( ) . any ( | w | w . 1 . is_some ( ) ) ; if any_cond { // Cut away the optional trailing else without condition. let ( slice , otherwise ) = match * ast . last ( ) . unwrap ( ) { ast :: CondWave ( ref wave , None ) => ( & ast [ .. ast . len ( ) - 2 ] , Some ( wave ) ) , _ => ( & ast [ .. ] , None ) , } ; let conds = slice . into_iter ( ) . map ( | & ast :: CondWave ( ref wave , ref cond ) | match * cond { Some ( ref cond ) => Ok ( ( wave , cond ) ) , None => { self . emit ( DiagBuilder2 :: error ( format ! ( " " wave span extract ( ) ) ) . span ( wave . span ) . add_note ( " \
 " , ) , ) ; Err ( ( ) ) } } ) . collect :: < Vec < Result < _ > > > ( ) . into_iter ( ) . collect :: < Result < Vec < _ > > > ( ) ? ; Ok ( CondOrUncond :: Cond ( conds , otherwise ) ) } else { if ast . len ( ) != 1 { self . emit ( DiagBuilder2 :: error ( format ! ( " " ) ) . span ( ast [ 0 ] . 0 . span ) . add_note ( " \
 " , ) , ) ; Err ( ( ) ) } else { Ok ( CondOrUncond :: Uncond ( & ast [ 0 ] . 0 ) ) } } }
Unpack a slice of waves.
Unpack a slice of waves .
&self
ast
&'ast [ast::CondWave]