fn destructure_pattern_to_ty(pat: &ast::Pat,
                             point: usize,
                             ty: &Ty,
                             scope: &Scope) -> Option<Ty> {
    debug!("destructure_pattern_to_ty point {} ty {:?}    ||||||||    pat: {:?}", point, ty, pat);
    match pat.node {
        ast::PatIdent(_ , ref spannedident, _) => {
            if point_is_in_span(point as u32, &spannedident.span) {
                debug!("destructure_pattern_to_ty matched an ident!");
                return Some(ty.clone());
            } else {
                panic!("Expecting the point to be in the patident span. pt: {}", point);
            }
        }
        ast::PatTup(ref tuple_elements) => {
            return match ty {
                &TyTuple(ref typeelems) => {
                    let mut i = 0usize;
                    let mut res = None;
                    for p in tuple_elements.iter() {
                        if point_is_in_span(point as u32, &p.span) {
                            let ref ty = typeelems[i];
                            res = destructure_pattern_to_ty(&**p, point, ty, scope);
                            break;
                        }
                        i += 1;
                    }
                    res
                }
                _ => panic!("Expecting TyTuple")

            }
        }
        ast::PatEnum(ref path, ref children) => {
            let mut i = 0u32;

            let m = resolve_ast_path(path, &scope.filepath, scope.point);
            let contextty = path_to_match(ty.clone());
            if let (Some(m), Some(children)) = (m, children.as_ref()) {
                let mut res = None;
                for p in children.iter() {
                    if point_is_in_span(point as u32, &p.span) {

                        res = typeinf::get_tuplestruct_field_type(i, &m)
                            .and_then(|ty|
                                // if context ty is a match, use its generics
                                if let Some(Ty::TyMatch(ref contextmatch)) = contextty {
                                    path_to_match_including_generics(ty, contextmatch)
                                } else {
                                    path_to_match(ty)
                                })
                            .and_then(|ty| destructure_pattern_to_ty(&**p, point, &ty, scope));

                        break;
                    }
                    i += 1;
                }
                res
            } else {
                None
            }
        }
        _ => {
            debug!("Could not destructure pattern {:?}", pat);
            None
        }
    }
}
// The point must point to an ident within the pattern.
The point must point to an ident within the pattern.
The point must point to an ident within the pattern .
fn destructure_pattern_to_ty(pat: &ast::Pat,
                             point: usize,
                             ty: &Ty,
                             scope: &Scope) -> Option<Ty> {
    debug!("destructure_pattern_to_ty point {} ty {:?}    ||||||||    pat: {:?}", point, ty, pat);
    match pat.node {
        ast::PatIdent(_ , ref spannedident, _) => {
            if point_is_in_span(point as u32, &spannedident.span) {
                debug!("destructure_pattern_to_ty matched an ident!");
                return Some(ty.clone());
            } else {
                panic!("Expecting the point to be in the patident span. pt: {}", point);
            }
        }
        ast::PatTup(ref tuple_elements) => {
            return match ty {
                &TyTuple(ref typeelems) => {
                    let mut i = 0usize;
                    let mut res = None;
                    for p in tuple_elements.iter() {
                        if point_is_in_span(point as u32, &p.span) {
                            let ref ty = typeelems[i];
                            res = destructure_pattern_to_ty(&**p, point, ty, scope);
                            break;
                        }
                        i += 1;
                    }
                    res
                }
                _ => panic!("Expecting TyTuple")
            }
        }
        ast::PatEnum(ref path, ref children) => {
            let mut i = 0u32;
            let m = resolve_ast_path(path, &scope.filepath, scope.point);
            let contextty = path_to_match(ty.clone());
            if let (Some(m), Some(children)) = (m, children.as_ref()) {
                let mut res = None;
                for p in children.iter() {
                    if point_is_in_span(point as u32, &p.span) {
                        res = typeinf::get_tuplestruct_field_type(i, &m)
                            .and_then(|ty|
                                // if context ty is a match, use its generics
                                if let Some(Ty::TyMatch(ref contextmatch)) = contextty {
                                    path_to_match_including_generics(ty, contextmatch)
                                } else {
                                    path_to_match(ty)
                                })
                            .and_then(|ty| destructure_pattern_to_ty(&**p, point, &ty, scope));
                        break;
                    }
                    i += 1;
                }
                res
            } else {
                None
            }
        }
        _ => {
            debug!("Could not destructure pattern {:?}", pat);
            None
        }
    }
}
fn destructure_pattern_to_ty ( pat : & ast :: Pat , point : usize , ty : & Ty , scope : & Scope ) -> Option < Ty > { debug ! ( " " point ty pat ) ; match pat . node { ast :: PatIdent ( _ , ref spannedident , _ ) => { if point_is_in_span ( point as u32 , & spannedident . span ) { debug ! ( " " ) ; return Some ( ty . clone ( ) ) ; } else { panic ! ( " " point ) ; } } ast :: PatTup ( ref tuple_elements ) => { return match ty { & TyTuple ( ref typeelems ) => { let mut i = 0usize ; let mut res = None ; for p in tuple_elements . iter ( ) { if point_is_in_span ( point as u32 , & p . span ) { let ref ty = typeelems [ i ] ; res = destructure_pattern_to_ty ( & * * p , point , ty , scope ) ; break ; } i += 1 ; } res } _ => panic ! ( " " ) } } ast :: PatEnum ( ref path , ref children ) => { let mut i = 0u32 ; let m = resolve_ast_path ( path , & scope . filepath , scope . point ) ; let contextty = path_to_match ( ty . clone ( ) ) ; if let ( Some ( m ) , Some ( children ) ) = ( m , children . as_ref ( ) ) { let mut res = None ; for p in children . iter ( ) { if point_is_in_span ( point as u32 , & p . span ) { res = typeinf :: get_tuplestruct_field_type ( i , & m ) . and_then ( | ty | // if context ty is a match, use its generics if let Some ( Ty :: TyMatch ( ref contextmatch ) ) = contextty { path_to_match_including_generics ( ty , contextmatch ) } else { path_to_match ( ty ) } ) . and_then ( | ty | destructure_pattern_to_ty ( & * * p , point , & ty , scope ) ) ; break ; } i += 1 ; } res } else { None } } _ => { debug ! ( " " pat ) ; None } } }
The point must point to an ident within the pattern.
The point must point to an ident within the pattern .
pat
&ast::Pat
point
usize
ty
&Ty
scope
&Scope