pub fn type_known_to_meet_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
                                                param_env: ty::ParamEnv<'tcx>,
                                                ty: Ty<'tcx>,
                                                def_id: DefId,
                                                span: Span)
-> bool
{
    debug!("type_known_to_meet_bound(ty={:?}, bound={:?})",
           ty,
           infcx.tcx.item_path_str(def_id));

    let trait_ref = ty::TraitRef {
        def_id,
        substs: infcx.tcx.mk_substs_trait(ty, &[]),
    };
    let obligation = Obligation {
        param_env,
        cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID),
        recursion_depth: 0,
        predicate: trait_ref.to_predicate(),
    };

    let result = infcx.predicate_must_hold(&obligation);
    debug!("type_known_to_meet_ty={:?} bound={} => {:?}",
           ty, infcx.tcx.item_path_str(def_id), result);

    if result && (ty.has_infer_types() || ty.has_closure_types()) {
        // Because of inference "guessing", selection can sometimes claim
        // to succeed while the success requires a guess. To ensure
        // this function's result remains infallible, we must confirm
        // that guess. While imperfect, I believe this is sound.

        // The handling of regions in this area of the code is terrible,
        // see issue #29149. We should be able to improve on this with
        // NLL.
        let mut fulfill_cx = FulfillmentContext::new_ignoring_regions();

        // We can use a dummy node-id here because we won't pay any mind
        // to region obligations that arise (there shouldn't really be any
        // anyhow).
        let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);

        fulfill_cx.register_bound(infcx, param_env, ty, def_id, cause);

        // Note: we only assume something is `Copy` if we can
        // *definitively* show that it implements `Copy`. Otherwise,
        // assume it is move; linear is always ok.
        match fulfill_cx.select_all_or_error(infcx) {
            Ok(()) => {
                debug!("type_known_to_meet_bound: ty={:?} bound={} success",
                       ty,
                       infcx.tcx.item_path_str(def_id));
                true
            }
            Err(e) => {
                debug!("type_known_to_meet_bound: ty={:?} bound={} errors={:?}",
                       ty,
                       infcx.tcx.item_path_str(def_id),
                       e);
                false
            }
        }
    } else {
        result
    }
}
/// Determines whether the type `ty` is known to meet `bound` and
/// returns true if so. Returns false if `ty` either does not meet
/// `bound` or is not known to meet bound (note that this is
/// conservative towards *no impl*, which is the opposite of the
/// `evaluate` methods).
Determines whether the type `ty` is known to meet `bound` and
returns true if so.
Determines whether the type ` ty ` is known to meet ` bound ` and returns true if so .
pub fn type_known_to_meet_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
                                                param_env: ty::ParamEnv<'tcx>,
                                                ty: Ty<'tcx>,
                                                def_id: DefId,
                                                span: Span)
-> bool
{
    debug!("type_known_to_meet_bound(ty={:?}, bound={:?})",
           ty,
           infcx.tcx.item_path_str(def_id));
    let trait_ref = ty::TraitRef {
        def_id,
        substs: infcx.tcx.mk_substs_trait(ty, &[]),
    };
    let obligation = Obligation {
        param_env,
        cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID),
        recursion_depth: 0,
        predicate: trait_ref.to_predicate(),
    };
    let result = infcx.predicate_must_hold(&obligation);
    debug!("type_known_to_meet_ty={:?} bound={} => {:?}",
           ty, infcx.tcx.item_path_str(def_id), result);
    if result && (ty.has_infer_types() || ty.has_closure_types()) {
        // Because of inference "guessing", selection can sometimes claim
        // to succeed while the success requires a guess. To ensure
        // this function's result remains infallible, we must confirm
        // that guess. While imperfect, I believe this is sound.
        // The handling of regions in this area of the code is terrible,
        // see issue #29149. We should be able to improve on this with
        // NLL.
        let mut fulfill_cx = FulfillmentContext::new_ignoring_regions();
        // We can use a dummy node-id here because we won't pay any mind
        // to region obligations that arise (there shouldn't really be any
        // anyhow).
        let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
        fulfill_cx.register_bound(infcx, param_env, ty, def_id, cause);
        // Note: we only assume something is `Copy` if we can
        // *definitively* show that it implements `Copy`. Otherwise,
        // assume it is move; linear is always ok.
        match fulfill_cx.select_all_or_error(infcx) {
            Ok(()) => {
                debug!("type_known_to_meet_bound: ty={:?} bound={} success",
                       ty,
                       infcx.tcx.item_path_str(def_id));
                true
            }
            Err(e) => {
                debug!("type_known_to_meet_bound: ty={:?} bound={} errors={:?}",
                       ty,
                       infcx.tcx.item_path_str(def_id),
                       e);
                false
            }
        }
    } else {
        result
    }
}
pub fn type_known_to_meet_bound < ' a , ' gcx , ' tcx > ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > , param_env : ty :: ParamEnv < ' tcx > , ty : Ty < ' tcx > , def_id : DefId , span : Span ) -> bool { debug ! ( " " ty infcx tcx item_path_str ( def_id ) ) ; let trait_ref = ty :: TraitRef { def_id , substs : infcx . tcx . mk_substs_trait ( ty , & [ ] ) , } ; let obligation = Obligation { param_env , cause : ObligationCause :: misc ( span , ast :: DUMMY_NODE_ID ) , recursion_depth : 0 , predicate : trait_ref . to_predicate ( ) , } ; let result = infcx . predicate_must_hold ( & obligation ) ; debug ! ( " " ty infcx tcx item_path_str ( def_id ) result ) ; if result && ( ty . has_infer_types ( ) || ty . has_closure_types ( ) ) { // Because of inference "guessing", selection can sometimes claim // to succeed while the success requires a guess. To ensure // this function's result remains infallible, we must confirm // that guess. While imperfect, I believe this is sound. // The handling of regions in this area of the code is terrible, // see issue #29149. We should be able to improve on this with // NLL. let mut fulfill_cx = FulfillmentContext :: new_ignoring_regions ( ) ; // We can use a dummy node-id here because we won't pay any mind // to region obligations that arise (there shouldn't really be any // anyhow). let cause = ObligationCause :: misc ( span , ast :: DUMMY_NODE_ID ) ; fulfill_cx . register_bound ( infcx , param_env , ty , def_id , cause ) ; // Note: we only assume something is `Copy` if we can // *definitively* show that it implements `Copy`. Otherwise, // assume it is move; linear is always ok. match fulfill_cx . select_all_or_error ( infcx ) { Ok ( ( ) ) => { debug ! ( " " ty infcx tcx item_path_str ( def_id ) ) ; true } Err ( e ) => { debug ! ( " " ty infcx tcx item_path_str ( def_id ) e ) ; false } } } else { result } }
Determines whether the type `ty` is known to meet `bound` and
returns true if so.
Determines whether the type ` ty ` is known to meet ` bound ` and returns true if so .
infcx
&InferCtxt<'a, 'gcx, 'tcx>
param_env
ty::ParamEnv<'tcx>
ty
Ty<'tcx>
def_id
DefId
span
Span
infcx
&InferCtxt<'a, 'gcx, 'tcx>
param_env
ty::ParamEnv<'tcx>
ty
Ty<'tcx>
def_id
DefId
span
Span