pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
    unnormalized_env: ty::ParameterEnvironment<'tcx>,
    cause: ObligationCause<'tcx>)
    -> ty::ParameterEnvironment<'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;
    let body_id = cause.body_id;

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

    let predicates: Vec<_> =
        util::elaborate_predicates(tcx, unnormalized_env.caller_bounds.clone())
        .filter(|p| !p.is_global()) // (*)
        .collect();

    // (*) Any predicate like `i32: Trait<u32>` or whatever doesn't
    // need to be in the *environment* to be proven, so screen those
    // out. This is important for the soundness of inter-fn
    // caching. Note though that we should probably check that these
    // predicates hold at the point where the environment is
    // constructed, but I am not currently doing so out of laziness.
    // -nmatsakis

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

    let elaborated_env = unnormalized_env.with_caller_bounds(predicates);

    tcx.infer_ctxt(None, Some(elaborated_env), ProjectionMode::AnyFinal).enter(|infcx| {
        let predicates = match fully_normalize(&infcx, cause,
                                               &infcx.parameter_environment.caller_bounds) {
            Ok(predicates) => predicates,
            Err(errors) => {
                infcx.report_fulfillment_errors(&errors);
                // An unnormalized env is better than nothing.
                return infcx.parameter_environment;
            }
        };

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

        let free_regions = FreeRegionMap::new();
        infcx.resolve_regions_and_report_errors(&free_regions, body_id);
        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 infcx.parameter_environment;
            }
        };

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

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

        infcx.parameter_environment.with_caller_bounds(predicates)
    })
}
// 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>,
    unnormalized_env: ty::ParameterEnvironment<'tcx>,
    cause: ObligationCause<'tcx>)
    -> ty::ParameterEnvironment<'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;
    let body_id = cause.body_id;
    debug!("normalize_param_env_or_error(unnormalized_env={:?})",
           unnormalized_env);
    let predicates: Vec<_> =
        util::elaborate_predicates(tcx, unnormalized_env.caller_bounds.clone())
        .filter(|p| !p.is_global()) // (*)
        .collect();
    // (*) Any predicate like `i32: Trait<u32>` or whatever doesn't
    // need to be in the *environment* to be proven, so screen those
    // out. This is important for the soundness of inter-fn
    // caching. Note though that we should probably check that these
    // predicates hold at the point where the environment is
    // constructed, but I am not currently doing so out of laziness.
    // -nmatsakis
    debug!("normalize_param_env_or_error: elaborated-predicates={:?}",
           predicates);
    let elaborated_env = unnormalized_env.with_caller_bounds(predicates);
    tcx.infer_ctxt(None, Some(elaborated_env), ProjectionMode::AnyFinal).enter(|infcx| {
        let predicates = match fully_normalize(&infcx, cause,
                                               &infcx.parameter_environment.caller_bounds) {
            Ok(predicates) => predicates,
            Err(errors) => {
                infcx.report_fulfillment_errors(&errors);
                // An unnormalized env is better than nothing.
                return infcx.parameter_environment;
            }
        };
        debug!("normalize_param_env_or_error: normalized predicates={:?}",
            predicates);
        let free_regions = FreeRegionMap::new();
        infcx.resolve_regions_and_report_errors(&free_regions, body_id);
        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 infcx.parameter_environment;
            }
        };
        let predicates = match tcx.lift_to_global(&predicates) {
            Some(predicates) => predicates,
            None => return infcx.parameter_environment
        };
        debug!("normalize_param_env_or_error: resolved predicates={:?}",
            predicates);
        infcx.parameter_environment.with_caller_bounds(predicates)
    })
}
pub fn normalize_param_env_or_error < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , unnormalized_env : ty :: ParameterEnvironment < ' tcx > , cause : ObligationCause < ' tcx > ) -> ty :: ParameterEnvironment < ' 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 ; let body_id = cause . body_id ; debug ! ( " " unnormalized_env ) ; let predicates : Vec < _ > = util :: elaborate_predicates ( tcx , unnormalized_env . caller_bounds . clone ( ) ) . filter ( | p | ! p . is_global ( ) ) // (*) . collect ( ) ; // (*) Any predicate like `i32: Trait<u32>` or whatever doesn't // need to be in the *environment* to be proven, so screen those // out. This is important for the soundness of inter-fn // caching. Note though that we should probably check that these // predicates hold at the point where the environment is // constructed, but I am not currently doing so out of laziness. // -nmatsakis debug ! ( " " predicates ) ; let elaborated_env = unnormalized_env . with_caller_bounds ( predicates ) ; tcx . infer_ctxt ( None , Some ( elaborated_env ) , ProjectionMode :: AnyFinal ) . enter ( | infcx | { let predicates = match fully_normalize ( & infcx , cause , & infcx . parameter_environment . caller_bounds ) { Ok ( predicates ) => predicates , Err ( errors ) => { infcx . report_fulfillment_errors ( & errors ) ; // An unnormalized env is better than nothing. return infcx . parameter_environment ; } } ; debug ! ( " " predicates ) ; let free_regions = FreeRegionMap :: new ( ) ; infcx . resolve_regions_and_report_errors ( & free_regions , body_id ) ; 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 infcx . parameter_environment ; } } ; let predicates = match tcx . lift_to_global ( & predicates ) { Some ( predicates ) => predicates , None => return infcx . parameter_environment } ; debug ! ( " " predicates ) ; infcx . parameter_environment . with_caller_bounds ( predicates ) } ) }
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>
unnormalized_env
ty::ParameterEnvironment<'tcx>
cause
ObligationCause<'tcx>
tcx
TyCtxt<'a, 'tcx, 'tcx>
unnormalized_env
ty::ParameterEnvironment<'tcx>
cause
ObligationCause<'tcx>