pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                              region_context: DefId,
                                              unnormalized_env: ty::ParamEnv<'tcx>,
                                              cause: ObligationCause<'tcx>)
                                              -> ty::ParamEnv<'tcx>
{
    // I'm not wild about reporting errors here; I'd prefer to
    // have the errors get reported at a defined place (e.g.,
    // during typeck). Instead I have all parameter
    // environments, in effect, going through this function
    // and hence potentially reporting errors. This ensurse of
    // course that we never forget to normalize (the
    // alternative seemed like it would involve a lot of
    // manual invocations of this fn -- and then we'd have to
    // deal with the errors at each of those sites).
    //
    // In any case, in practice, typeck constructs all the
    // parameter environments once for every fn as it goes,
    // and errors will get reported then; so after typeck we
    // can be sure that no errors should occur.

    let span = cause.span;

    debug!("normalize_param_env_or_error(unnormalized_env={:?})",
           unnormalized_env);

    let predicates: Vec<_> =
        util::elaborate_predicates(tcx, unnormalized_env.caller_bounds.to_vec())
        .collect();

    debug!("normalize_param_env_or_error: elaborated-predicates={:?}",
           predicates);

    let elaborated_env = ty::ParamEnv::new(tcx.intern_predicates(&predicates),
                                           unnormalized_env.reveal);

    tcx.infer_ctxt().enter(|infcx| {
        // FIXME. We should really... do something with these region
        // obligations. But this call just continues the older
        // behavior (i.e., doesn't cause any new bugs), and it would
        // take some further refactoring to actually solve them. In
        // particular, we would have to handle implied bounds
        // properly, and that code is currently largely confined to
        // regionck (though I made some efforts to extract it
        // out). -nmatsakis
        //
        // @arielby: In any case, these obligations are checked
        // by wfcheck anyway, so I'm not sure we have to check
        // them here too, and we will remove this function when
        // we move over to lazy normalization *anyway*.
        let fulfill_cx = FulfillmentContext::new_ignoring_regions();

        let predicates = match fully_normalize(
            &infcx,
            fulfill_cx,
            cause,
            elaborated_env,
            // You would really want to pass infcx.param_env.caller_bounds here,
            // but that is an interned slice, and fully_normalize takes &T and returns T, so
            // without further refactoring, a slice can't be used. Luckily, we still have the
            // predicate vector from which we created the ParamEnv in infcx, so we
            // can pass that instead. It's roundabout and a bit brittle, but this code path
            // ought to be refactored anyway, and until then it saves us from having to copy.
            &predicates,
        ) {
            Ok(predicates) => predicates,
            Err(errors) => {
                infcx.report_fulfillment_errors(&errors, None, false);
                // An unnormalized env is better than nothing.
                return elaborated_env;
            }
        };

        debug!("normalize_param_env_or_error: normalized predicates={:?}",
            predicates);

        let region_scope_tree = region::ScopeTree::default();

        // We can use the `elaborated_env` here; the region code only
        // cares about declarations like `'a: 'b`.
        let outlives_env = OutlivesEnvironment::new(elaborated_env);

        infcx.resolve_regions_and_report_errors(region_context, &region_scope_tree, &outlives_env);

        let predicates = match infcx.fully_resolve(&predicates) {
            Ok(predicates) => predicates,
            Err(fixup_err) => {
                // If we encounter a fixup error, it means that some type
                // variable wound up unconstrained. I actually don't know
                // if this can happen, and I certainly don't expect it to
                // happen often, but if it did happen it probably
                // represents a legitimate failure due to some kind of
                // unconstrained variable, and it seems better not to ICE,
                // all things considered.
                tcx.sess.span_err(span, &fixup_err.to_string());
                // An unnormalized env is better than nothing.
                return elaborated_env;
            }
        };

        let predicates = match tcx.lift_to_global(&predicates) {
            Some(predicates) => predicates,
            None => return elaborated_env,
        };

        debug!("normalize_param_env_or_error: resolved predicates={:?}",
               predicates);

        ty::ParamEnv::new(tcx.intern_predicates(&predicates), unnormalized_env.reveal)
    })
}
// FIXME: this is gonna need to be removed ...
/// Normalizes the parameter environment, reporting errors if they occur.
this is gonna need to be removed
Normalizes the parameter environment, reporting errors if they occur.
this is gonna need to be removed Normalizes the parameter environment reporting errors if they occur .
pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                              region_context: DefId,
                                              unnormalized_env: ty::ParamEnv<'tcx>,
                                              cause: ObligationCause<'tcx>)
                                              -> ty::ParamEnv<'tcx>
{
    // I'm not wild about reporting errors here; I'd prefer to
    // have the errors get reported at a defined place (e.g.,
    // during typeck). Instead I have all parameter
    // environments, in effect, going through this function
    // and hence potentially reporting errors. This ensurse of
    // course that we never forget to normalize (the
    // alternative seemed like it would involve a lot of
    // manual invocations of this fn -- and then we'd have to
    // deal with the errors at each of those sites).
    //
    // In any case, in practice, typeck constructs all the
    // parameter environments once for every fn as it goes,
    // and errors will get reported then; so after typeck we
    // can be sure that no errors should occur.
    let span = cause.span;
    debug!("normalize_param_env_or_error(unnormalized_env={:?})",
           unnormalized_env);
    let predicates: Vec<_> =
        util::elaborate_predicates(tcx, unnormalized_env.caller_bounds.to_vec())
        .collect();
    debug!("normalize_param_env_or_error: elaborated-predicates={:?}",
           predicates);
    let elaborated_env = ty::ParamEnv::new(tcx.intern_predicates(&predicates),
                                           unnormalized_env.reveal);
    tcx.infer_ctxt().enter(|infcx| {
        // FIXME. We should really... do something with these region
        // obligations. But this call just continues the older
        // behavior (i.e., doesn't cause any new bugs), and it would
        // take some further refactoring to actually solve them. In
        // particular, we would have to handle implied bounds
        // properly, and that code is currently largely confined to
        // regionck (though I made some efforts to extract it
        // out). -nmatsakis
        //
        // @arielby: In any case, these obligations are checked
        // by wfcheck anyway, so I'm not sure we have to check
        // them here too, and we will remove this function when
        // we move over to lazy normalization *anyway*.
        let fulfill_cx = FulfillmentContext::new_ignoring_regions();
        let predicates = match fully_normalize(
            &infcx,
            fulfill_cx,
            cause,
            elaborated_env,
            // You would really want to pass infcx.param_env.caller_bounds here,
            // but that is an interned slice, and fully_normalize takes &T and returns T, so
            // without further refactoring, a slice can't be used. Luckily, we still have the
            // predicate vector from which we created the ParamEnv in infcx, so we
            // can pass that instead. It's roundabout and a bit brittle, but this code path
            // ought to be refactored anyway, and until then it saves us from having to copy.
            &predicates,
        ) {
            Ok(predicates) => predicates,
            Err(errors) => {
                infcx.report_fulfillment_errors(&errors, None, false);
                // An unnormalized env is better than nothing.
                return elaborated_env;
            }
        };
        debug!("normalize_param_env_or_error: normalized predicates={:?}",
            predicates);
        let region_scope_tree = region::ScopeTree::default();
        // We can use the `elaborated_env` here; the region code only
        // cares about declarations like `'a: 'b`.
        let outlives_env = OutlivesEnvironment::new(elaborated_env);
        infcx.resolve_regions_and_report_errors(region_context, &region_scope_tree, &outlives_env);
        let predicates = match infcx.fully_resolve(&predicates) {
            Ok(predicates) => predicates,
            Err(fixup_err) => {
                // If we encounter a fixup error, it means that some type
                // variable wound up unconstrained. I actually don't know
                // if this can happen, and I certainly don't expect it to
                // happen often, but if it did happen it probably
                // represents a legitimate failure due to some kind of
                // unconstrained variable, and it seems better not to ICE,
                // all things considered.
                tcx.sess.span_err(span, &fixup_err.to_string());
                // An unnormalized env is better than nothing.
                return elaborated_env;
            }
        };
        let predicates = match tcx.lift_to_global(&predicates) {
            Some(predicates) => predicates,
            None => return elaborated_env,
        };
        debug!("normalize_param_env_or_error: resolved predicates={:?}",
               predicates);
        ty::ParamEnv::new(tcx.intern_predicates(&predicates), unnormalized_env.reveal)
    })
}
pub fn normalize_param_env_or_error < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , region_context : DefId , unnormalized_env : ty :: ParamEnv < ' tcx > , cause : ObligationCause < ' tcx > ) -> ty :: ParamEnv < ' tcx > { // I'm not wild about reporting errors here; I'd prefer to // have the errors get reported at a defined place (e.g., // during typeck). Instead I have all parameter // environments, in effect, going through this function // and hence potentially reporting errors. This ensurse of // course that we never forget to normalize (the // alternative seemed like it would involve a lot of // manual invocations of this fn -- and then we'd have to // deal with the errors at each of those sites). // // In any case, in practice, typeck constructs all the // parameter environments once for every fn as it goes, // and errors will get reported then; so after typeck we // can be sure that no errors should occur. let span = cause . span ; debug ! ( " " unnormalized_env ) ; let predicates : Vec < _ > = util :: elaborate_predicates ( tcx , unnormalized_env . caller_bounds . to_vec ( ) ) . collect ( ) ; debug ! ( " " predicates ) ; let elaborated_env = ty :: ParamEnv :: new ( tcx . intern_predicates ( & predicates ) , unnormalized_env . reveal ) ; tcx . infer_ctxt ( ) . enter ( | infcx | { // FIXME. We should really... do something with these region // obligations. But this call just continues the older // behavior (i.e., doesn't cause any new bugs), and it would // take some further refactoring to actually solve them. In // particular, we would have to handle implied bounds // properly, and that code is currently largely confined to // regionck (though I made some efforts to extract it // out). -nmatsakis // // @arielby: In any case, these obligations are checked // by wfcheck anyway, so I'm not sure we have to check // them here too, and we will remove this function when // we move over to lazy normalization *anyway*. let fulfill_cx = FulfillmentContext :: new_ignoring_regions ( ) ; let predicates = match fully_normalize ( & infcx , fulfill_cx , cause , elaborated_env , // You would really want to pass infcx.param_env.caller_bounds here, // but that is an interned slice, and fully_normalize takes &T and returns T, so // without further refactoring, a slice can't be used. Luckily, we still have the // predicate vector from which we created the ParamEnv in infcx, so we // can pass that instead. It's roundabout and a bit brittle, but this code path // ought to be refactored anyway, and until then it saves us from having to copy. & predicates , ) { Ok ( predicates ) => predicates , Err ( errors ) => { infcx . report_fulfillment_errors ( & errors , None , false ) ; // An unnormalized env is better than nothing. return elaborated_env ; } } ; debug ! ( " " predicates ) ; let region_scope_tree = region :: ScopeTree :: default ( ) ; // We can use the `elaborated_env` here; the region code only // cares about declarations like `'a: 'b`. let outlives_env = OutlivesEnvironment :: new ( elaborated_env ) ; infcx . resolve_regions_and_report_errors ( region_context , & region_scope_tree , & outlives_env ) ; let predicates = match infcx . fully_resolve ( & predicates ) { Ok ( predicates ) => predicates , Err ( fixup_err ) => { // If we encounter a fixup error, it means that some type // variable wound up unconstrained. I actually don't know // if this can happen, and I certainly don't expect it to // happen often, but if it did happen it probably // represents a legitimate failure due to some kind of // unconstrained variable, and it seems better not to ICE, // all things considered. tcx . sess . span_err ( span , & fixup_err . to_string ( ) ) ; // An unnormalized env is better than nothing. return elaborated_env ; } } ; let predicates = match tcx . lift_to_global ( & predicates ) { Some ( predicates ) => predicates , None => return elaborated_env , } ; debug ! ( " " predicates ) ; ty :: ParamEnv :: new ( tcx . intern_predicates ( & predicates ) , unnormalized_env . reveal ) } ) }
FIXME: this is gonna need to be removed ...
Normalizes the parameter environment, reporting errors if they occur.
FIXME : this is gonna need to be removed ... Normalizes the parameter environment reporting errors if they occur .
tcx
TyCtxt<'a, 'tcx, 'tcx>
region_context
DefId
unnormalized_env
ty::ParamEnv<'tcx>
cause
ObligationCause<'tcx>
tcx
TyCtxt<'a, 'tcx, 'tcx>
region_context
DefId
unnormalized_env
ty::ParamEnv<'tcx>
cause
ObligationCause<'tcx>