pub fn eval_length<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                             count: hir::BodyId,
                             reason: &str)
                             -> Result<usize, ErrorReported>
{
    let hint = UncheckedExprHint(tcx.types.usize);
    let count_expr = &tcx.hir.body(count).value;
    match ConstContext::new(tcx, count).eval(count_expr, hint) {
        Ok(Integral(Usize(count))) => {
            let val = count.as_u64(tcx.sess.target.uint_type);
            assert_eq!(val as usize as u64, val);
            Ok(val as usize)
        },
        Ok(const_val) => {
            struct_span_err!(tcx.sess, count_expr.span, E0306,
                             "expected `usize` for {}, found {}",
                             reason,
                             const_val.description())
                .span_label(count_expr.span, &format!("expected `usize`"))
                .emit();

            Err(ErrorReported)
        }
        Err(err) => {
            let mut diag = report_const_eval_err(
                tcx, &err, count_expr.span, reason);

            if let hir::ExprPath(hir::QPath::Resolved(None, ref path)) = count_expr.node {
                if let Def::Local(..) = path.def {
                    diag.note(&format!("`{}` is a variable",
                                       tcx.hir.node_to_pretty_string(count_expr.id)));
                }
            }

            diag.emit();
            Err(ErrorReported)
        }
    }
}
/// Returns the value of the length-valued expression
Returns the value of the length-valued expression
Returns the value of the length - valued expression
pub fn eval_length<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                             count: hir::BodyId,
                             reason: &str)
                             -> Result<usize, ErrorReported>
{
    let hint = UncheckedExprHint(tcx.types.usize);
    let count_expr = &tcx.hir.body(count).value;
    match ConstContext::new(tcx, count).eval(count_expr, hint) {
        Ok(Integral(Usize(count))) => {
            let val = count.as_u64(tcx.sess.target.uint_type);
            assert_eq!(val as usize as u64, val);
            Ok(val as usize)
        },
        Ok(const_val) => {
            struct_span_err!(tcx.sess, count_expr.span, E0306,
                             "expected `usize` for {}, found {}",
                             reason,
                             const_val.description())
                .span_label(count_expr.span, &format!("expected `usize`"))
                .emit();
            Err(ErrorReported)
        }
        Err(err) => {
            let mut diag = report_const_eval_err(
                tcx, &err, count_expr.span, reason);
            if let hir::ExprPath(hir::QPath::Resolved(None, ref path)) = count_expr.node {
                if let Def::Local(..) = path.def {
                    diag.note(&format!("`{}` is a variable",
                                       tcx.hir.node_to_pretty_string(count_expr.id)));
                }
            }
            diag.emit();
            Err(ErrorReported)
        }
    }
}
pub fn eval_length < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , count : hir :: BodyId , reason : & str ) -> Result < usize , ErrorReported > { let hint = UncheckedExprHint ( tcx . types . usize ) ; let count_expr = & tcx . hir . body ( count ) . value ; match ConstContext :: new ( tcx , count ) . eval ( count_expr , hint ) { Ok ( Integral ( Usize ( count ) ) ) => { let val = count . as_u64 ( tcx . sess . target . uint_type ) ; assert_eq ! ( val as usize as u64 val ) ; Ok ( val as usize ) } , Ok ( const_val ) => { struct_span_err ! ( tcx sess count_expr span E0306 " " reason const_val description ( ) ) . span_label ( count_expr . span , & format ! ( " " ) ) . emit ( ) ; Err ( ErrorReported ) } Err ( err ) => { let mut diag = report_const_eval_err ( tcx , & err , count_expr . span , reason ) ; if let hir :: ExprPath ( hir :: QPath :: Resolved ( None , ref path ) ) = count_expr . node { if let Def :: Local ( .. ) = path . def { diag . note ( & format ! ( " " tcx hir node_to_pretty_string ( count_expr id ) ) ) ; } } diag . emit ( ) ; Err ( ErrorReported ) } } }
Returns the value of the length-valued expression
Returns the value of the length - valued expression
tcx
TyCtxt<'a, 'tcx, 'tcx>
count
hir::BodyId
reason
&str