/// Evaluate the type of an array aggregate.
Evaluate the type of an array aggregate.
Evaluate the type of an array aggregate .
pub fn typeval_array_aggregate<'sbc, 'lazy: 'sbc, 'sb: 'lazy, 'ast: 'sb, 'ctx: 'sb>(
    tyc: &TypeckContext<'sbc, 'lazy, 'sb, 'ast, 'ctx>,
    _id: AggregateRef,
    hir: &hir::Aggregate,
    tyctx: &'ctx Ty,
) -> Result<&'ctx Ty> {
    let tyctx_flat = tyc.ctx.deref_named_type(tyctx)?;
    // Determine the index and element types from the context.
    let (index, element) = if let Ty::Array(ref ty) = *tyctx_flat {
        let index = ty.indices[0].ty();
        let element = if ty.indices.len() > 1 {
            tyc.ctx.intern_ty(ArrayTy::new(
                ty.indices.iter().skip(1).cloned().collect(),
                ty.element.clone(),
            ))
        } else {
            ty.element.as_ref()
        };
        (index, element)
    } else {
        unreachable!();
    };
    // Forward the type context and check the index and element types.
    let mut had_fails = false;
    for &pos in &hir.positional {
        match (|| {
            tyc.ctx.set_type_context(pos.value, element);
            let ty = tyc.lazy_typeval(pos.value)?;
            tyc.must_match(element, ty, pos.span);
            Ok(())
        })() {
            Ok(()) => (),
            Err(()) => had_fails = true,
        }
    }
    match hir.named {
        hir::AggregateKind::Both => (),
        hir::AggregateKind::Array(ref fields) => {
            for field in fields {
                match typeck_array_aggregate_element(tyc, field, index, element) {
                    Ok(()) => (),
                    Err(()) => had_fails = true,
                }
            }
        }
        hir::AggregateKind::Record(..) => {
            tyc.emit(
                DiagBuilder2::error("expected an array aggregate, found a record aggregate")
                    .span(hir.span),
            );
            return Err(());
        }
    }
    if let Some(others) = hir.others {
        match (|| {
            tyc.ctx.set_type_context(others.value, element);
            let ty = tyc.lazy_typeval(others.value)?;
            tyc.must_match(element, ty, others.span);
            Ok(())
        })() {
            Ok(()) => (),
            Err(()) => had_fails = true,
        }
    }
    if had_fails {
        Err(())
    } else {
        Ok(tyctx)
    }
}
pub fn typeval_array_aggregate < ' sbc , ' lazy : ' sbc , ' sb : ' lazy , ' ast : ' sb , ' ctx : ' sb > ( tyc : & TypeckContext < ' sbc , ' lazy , ' sb , ' ast , ' ctx > , _id : AggregateRef , hir : & hir :: Aggregate , tyctx : & ' ctx Ty , ) -> Result < & ' ctx Ty > { let tyctx_flat = tyc . ctx . deref_named_type ( tyctx ) ? ; // Determine the index and element types from the context. let ( index , element ) = if let Ty :: Array ( ref ty ) = * tyctx_flat { let index = ty . indices [ 0 ] . ty ( ) ; let element = if ty . indices . len ( ) > 1 { tyc . ctx . intern_ty ( ArrayTy :: new ( ty . indices . iter ( ) . skip ( 1 ) . cloned ( ) . collect ( ) , ty . element . clone ( ) , ) ) } else { ty . element . as_ref ( ) } ; ( index , element ) } else { unreachable ! ( ) ; } ; // Forward the type context and check the index and element types. let mut had_fails = false ; for & pos in & hir . positional { match ( | | { tyc . ctx . set_type_context ( pos . value , element ) ; let ty = tyc . lazy_typeval ( pos . value ) ? ; tyc . must_match ( element , ty , pos . span ) ; Ok ( ( ) ) } ) ( ) { Ok ( ( ) ) => ( ) , Err ( ( ) ) => had_fails = true , } } match hir . named { hir :: AggregateKind :: Both => ( ) , hir :: AggregateKind :: Array ( ref fields ) => { for field in fields { match typeck_array_aggregate_element ( tyc , field , index , element ) { Ok ( ( ) ) => ( ) , Err ( ( ) ) => had_fails = true , } } } hir :: AggregateKind :: Record ( .. ) => { tyc . emit ( DiagBuilder2 :: error ( " " ) . span ( hir . span ) , ) ; return Err ( ( ) ) ; } } if let Some ( others ) = hir . others { match ( | | { tyc . ctx . set_type_context ( others . value , element ) ; let ty = tyc . lazy_typeval ( others . value ) ? ; tyc . must_match ( element , ty , others . span ) ; Ok ( ( ) ) } ) ( ) { Ok ( ( ) ) => ( ) , Err ( ( ) ) => had_fails = true , } } if had_fails { Err ( ( ) ) } else { Ok ( tyctx ) } }
Evaluate the type of an array aggregate.
Evaluate the type of an array aggregate .
tyc
&TypeckContext<'sbc, 'lazy, 'sb, 'ast, 'ctx>
_id
AggregateRef
hir
&hir::Aggregate
tyctx
&'ctx Ty