/// Map an AST type data to the corresponding HIR type data.
Map an AST type data to the corresponding HIR type data.
Map an AST type data to the corresponding HIR type data .
fn unpack_type_data<'t>(
    data: &'t ast::TypeData,
    type_name: Spanned<Name>,
    context: AllocContext<'t>,
) -> Result<TypeData<'t>> {
    match *data {
        ast::EnumType(ref paren_elems) => {
            let literals = paren_elems
                .value
                .iter()
                .map(|elem| match paren_elem_to_enum_literal(elem) {
                    Some(x) => Ok(x),
                    None => {
                        context.emit(
                            DiagBuilder2::error(format!(
                                "`{}` is not an enumeration literal",
                                elem.span.extract()
                            ))
                            .span(elem.span)
                            .add_note("expected an identifier or character literal"),
                        );
                        Err(())
                    }
                })
                .collect::<Vec<Result<_>>>()
                .into_iter()
                .collect::<Result<Vec<_>>>()?;
            Ok(TypeData::Enum(Spanned::new(literals, paren_elems.span)))
        }
        ast::RangeType(ref range_expr, ref units) => {
            let termctx = TermContext::new2(context);
            let range_expr = termctx.termify_expr(range_expr)?;
            let range = term::term_to_range(range_expr, context)?;
            match *units {
                Some(ref units) => {
                    let (units, primary) = unpack_units(units, type_name, context)?;
                    Ok(TypeData::Physical(range, units, primary))
                }
                None => Ok(TypeData::Range(range)),
            }
        }
        ast::AccessType(ref subty) => {
            let subty = context.alloc(SubtypeInd2::from_ast(subty, context)?);
            Ok(TypeData::Access(subty))
        }
        _ => unimplemented!(
            "type `{}` unsupported type data {:#?}",
            type_name.value,
            data
        ),
    }
}
fn unpack_type_data < ' t > ( data : & ' t ast :: TypeData , type_name : Spanned < Name > , context : AllocContext < ' t > , ) -> Result < TypeData < ' t > > { match * data { ast :: EnumType ( ref paren_elems ) => { let literals = paren_elems . value . iter ( ) . map ( | elem | match paren_elem_to_enum_literal ( elem ) { Some ( x ) => Ok ( x ) , None => { context . emit ( DiagBuilder2 :: error ( format ! ( " " elem span extract ( ) ) ) . span ( elem . span ) . add_note ( " " ) , ) ; Err ( ( ) ) } } ) . collect :: < Vec < Result < _ > > > ( ) . into_iter ( ) . collect :: < Result < Vec < _ > > > ( ) ? ; Ok ( TypeData :: Enum ( Spanned :: new ( literals , paren_elems . span ) ) ) } ast :: RangeType ( ref range_expr , ref units ) => { let termctx = TermContext :: new2 ( context ) ; let range_expr = termctx . termify_expr ( range_expr ) ? ; let range = term :: term_to_range ( range_expr , context ) ? ; match * units { Some ( ref units ) => { let ( units , primary ) = unpack_units ( units , type_name , context ) ? ; Ok ( TypeData :: Physical ( range , units , primary ) ) } None => Ok ( TypeData :: Range ( range ) ) , } } ast :: AccessType ( ref subty ) => { let subty = context . alloc ( SubtypeInd2 :: from_ast ( subty , context ) ? ) ; Ok ( TypeData :: Access ( subty ) ) } _ => unimplemented ! ( " " type_name value data ) , } }
Map an AST type data to the corresponding HIR type data.
Map an AST type data to the corresponding HIR type data .
data
&'t ast::TypeData
type_name
Spanned<Name>
context
AllocContext<'t>