fn compute_opt_region_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
                                  span: Span,
                                  explicit_region_bounds: &[&ast::Lifetime],
                                  principal_trait_ref: Option<ty::PolyTraitRef<'tcx>>,
                                  builtin_bounds: ty::BuiltinBounds)
                                  -> Option<ty::Region>
{
    debug!("compute_opt_region_bound(explicit_region_bounds={:?}, \
           principal_trait_ref={}, builtin_bounds={})",
           explicit_region_bounds,
           principal_trait_ref.repr(tcx),
           builtin_bounds.repr(tcx));

    if explicit_region_bounds.len() > 1 {
        tcx.sess.span_err(
            explicit_region_bounds[1].span,
            format!("only a single explicit lifetime bound is permitted").as_slice());
    }

    if explicit_region_bounds.len() != 0 {
        // Explicitly specified region bound. Use that.
        let r = explicit_region_bounds[0];
        return Some(ast_region_to_region(tcx, r));
    }

    // No explicit region bound specified. Therefore, examine trait
    // bounds and see if we can derive region bounds from those.
    let derived_region_bounds =
        ty::object_region_bounds(tcx, principal_trait_ref.as_ref(), builtin_bounds);

    // If there are no derived region bounds, then report back that we
    // can find no region bound.
    if derived_region_bounds.len() == 0 {
        return None;
    }

    // If any of the derived region bounds are 'static, that is always
    // the best choice.
    if derived_region_bounds.iter().any(|r| ty::ReStatic == *r) {
        return Some(ty::ReStatic);
    }

    // Determine whether there is exactly one unique region in the set
    // of derived region bounds. If so, use that. Otherwise, report an
    // error.
    let r = derived_region_bounds[0];
    if derived_region_bounds.slice_from(1).iter().any(|r1| r != *r1) {
        tcx.sess.span_err(
            span,
            &format!("ambiguous lifetime bound, \
                     explicit lifetime bound required")[]);
    }
    return Some(r);
}
/// Given the bounds on a type parameter / existential type, determines what single region bound
/// (if any) we can use to summarize this type. The basic idea is that we will use the bound the
/// user provided, if they provided one, and otherwise search the supertypes of trait bounds for
/// region bounds. It may be that we can derive no bound at all, in which case we return `None`.
Given the bounds on a type parameter / existential type, determines what single region bound
(if any) we can use to summarize this type. The basic idea is that we will use the bound the
user provided, if they provided one, and otherwise search the supertypes of trait bounds for
region bounds. It may be that we can derive no bound at all, in which case we return `None`.
Given the bounds on a type parameter / existential type determines what single region bound ( if any ) we can use to summarize this type . The basic idea is that we will use the bound the user provided if they provided one and otherwise search the supertypes of trait bounds for region bounds . It may be that we can derive no bound at all in which case we return ` None ` .
fn compute_opt_region_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
                                  span: Span,
                                  explicit_region_bounds: &[&ast::Lifetime],
                                  principal_trait_ref: Option<ty::PolyTraitRef<'tcx>>,
                                  builtin_bounds: ty::BuiltinBounds)
                                  -> Option<ty::Region>
{
    debug!("compute_opt_region_bound(explicit_region_bounds={:?}, \
           principal_trait_ref={}, builtin_bounds={})",
           explicit_region_bounds,
           principal_trait_ref.repr(tcx),
           builtin_bounds.repr(tcx));
    if explicit_region_bounds.len() > 1 {
        tcx.sess.span_err(
            explicit_region_bounds[1].span,
            format!("only a single explicit lifetime bound is permitted").as_slice());
    }
    if explicit_region_bounds.len() != 0 {
        // Explicitly specified region bound. Use that.
        let r = explicit_region_bounds[0];
        return Some(ast_region_to_region(tcx, r));
    }
    // No explicit region bound specified. Therefore, examine trait
    // bounds and see if we can derive region bounds from those.
    let derived_region_bounds =
        ty::object_region_bounds(tcx, principal_trait_ref.as_ref(), builtin_bounds);
    // If there are no derived region bounds, then report back that we
    // can find no region bound.
    if derived_region_bounds.len() == 0 {
        return None;
    }
    // If any of the derived region bounds are 'static, that is always
    // the best choice.
    if derived_region_bounds.iter().any(|r| ty::ReStatic == *r) {
        return Some(ty::ReStatic);
    }
    // Determine whether there is exactly one unique region in the set
    // of derived region bounds. If so, use that. Otherwise, report an
    // error.
    let r = derived_region_bounds[0];
    if derived_region_bounds.slice_from(1).iter().any(|r1| r != *r1) {
        tcx.sess.span_err(
            span,
            &format!("ambiguous lifetime bound, \
                     explicit lifetime bound required")[]);
    }
    return Some(r);
}
fn compute_opt_region_bound < ' tcx > ( tcx : & ty :: ctxt < ' tcx > , span : Span , explicit_region_bounds : & [ & ast :: Lifetime ] , principal_trait_ref : Option < ty :: PolyTraitRef < ' tcx > > , builtin_bounds : ty :: BuiltinBounds ) -> Option < ty :: Region > { debug ! ( " \
 " explicit_region_bounds principal_trait_ref repr ( tcx ) builtin_bounds repr ( tcx ) ) ; if explicit_region_bounds . len ( ) > 1 { tcx . sess . span_err ( explicit_region_bounds [ 1 ] . span , format ! ( " " ) . as_slice ( ) ) ; } if explicit_region_bounds . len ( ) != 0 { // Explicitly specified region bound. Use that. let r = explicit_region_bounds [ 0 ] ; return Some ( ast_region_to_region ( tcx , r ) ) ; } // No explicit region bound specified. Therefore, examine trait // bounds and see if we can derive region bounds from those. let derived_region_bounds = ty :: object_region_bounds ( tcx , principal_trait_ref . as_ref ( ) , builtin_bounds ) ; // If there are no derived region bounds, then report back that we // can find no region bound. if derived_region_bounds . len ( ) == 0 { return None ; } // If any of the derived region bounds are 'static, that is always // the best choice. if derived_region_bounds . iter ( ) . any ( | r | ty :: ReStatic == * r ) { return Some ( ty :: ReStatic ) ; } // Determine whether there is exactly one unique region in the set // of derived region bounds. If so, use that. Otherwise, report an // error. let r = derived_region_bounds [ 0 ] ; if derived_region_bounds . slice_from ( 1 ) . iter ( ) . any ( | r1 | r != * r1 ) { tcx . sess . span_err ( span , & format ! ( " \
 " ) [ ] ) ; } return Some ( r ) ; }
Given the bounds on a type parameter / existential type, determines what single region bound
(if any) we can use to summarize this type.
Given the bounds on a type parameter / existential type determines what single region bound ( if any ) we can use to summarize this type .
tcx
&ty::ctxt<'tcx>
span
Span
explicit_region_bounds
&[&ast::Lifetime]
principal_trait_ref
Option<ty::PolyTraitRef<'tcx>>
builtin_bounds
ty::BuiltinBounds
tcx
&ty::ctxt<'tcx>
span
Span
explicit_region_bounds
&[&ast::Lifetime]
principal_trait_ref
Option<ty::PolyTraitRef<'tcx>>
builtin_bounds
ty::BuiltinBounds