pub(crate) fn type_check<'mir, 'tcx>(
    infcx: &InferCtxt<'_, 'tcx>,
    param_env: ty::ParamEnv<'tcx>,
    body: &Body<'tcx>,
    promoted: &IndexVec<Promoted, Body<'tcx>>,
    universal_regions: &Rc<UniversalRegions<'tcx>>,
    location_table: &LocationTable,
    borrow_set: &BorrowSet<'tcx>,
    all_facts: &mut Option<AllFacts>,
    flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
    move_data: &MoveData<'tcx>,
    elements: &Rc<RegionValueElements>,
    upvars: &[Upvar<'tcx>],
    use_polonius: bool,
) -> MirTypeckResults<'tcx> {
    let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
    let mut universe_causes = FxHashMap::default();
    universe_causes.insert(ty::UniverseIndex::from_u32(0), UniverseInfo::other());
    let mut constraints = MirTypeckRegionConstraints {
        placeholder_indices: PlaceholderIndices::default(),
        placeholder_index_to_region: IndexVec::default(),
        liveness_constraints: LivenessValues::new(elements.clone()),
        outlives_constraints: OutlivesConstraintSet::default(),
        member_constraints: MemberConstraintSet::default(),
        closure_bounds_mapping: Default::default(),
        type_tests: Vec::default(),
        universe_causes,
    };

    let CreateResult {
        universal_region_relations,
        region_bound_pairs,
        normalized_inputs_and_output,
    } = free_region_relations::create(
        infcx,
        param_env,
        Some(implicit_region_bound),
        universal_regions,
        &mut constraints,
    );

    for u in ty::UniverseIndex::ROOT..infcx.universe() {
        let info = UniverseInfo::other();
        constraints.universe_causes.insert(u, info);
    }

    let mut borrowck_context = BorrowCheckContext {
        universal_regions,
        location_table,
        borrow_set,
        all_facts,
        constraints: &mut constraints,
        upvars,
    };

    let opaque_type_values = type_check_internal(
        infcx,
        param_env,
        body,
        promoted,
        &region_bound_pairs,
        implicit_region_bound,
        &mut borrowck_context,
        |mut cx| {
            cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
            liveness::generate(
                &mut cx,
                body,
                elements,
                flow_inits,
                move_data,
                location_table,
                use_polonius,
            );

            translate_outlives_facts(&mut cx);
            let opaque_type_values =
                infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();

            opaque_type_values
                .into_iter()
                .map(|(opaque_type_key, decl)| {
                    cx.fully_perform_op(
                        Locations::All(body.span),
                        ConstraintCategory::OpaqueType,
                        CustomTypeOp::new(
                            |infcx| {
                                infcx.register_member_constraints(
                                    param_env,
                                    opaque_type_key,
                                    decl.hidden_type.ty,
                                    decl.hidden_type.span,
                                );
                                Ok(InferOk { value: (), obligations: vec![] })
                            },
                            || "opaque_type_map".to_string(),
                        ),
                    )
                    .unwrap();
                    let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
                    trace!(
                        "finalized opaque type {:?} to {:#?}",
                        opaque_type_key,
                        hidden_type.ty.kind()
                    );
                    if hidden_type.has_infer_types_or_consts() {
                        infcx.tcx.sess.delay_span_bug(
                            decl.hidden_type.span,
                            &format!("could not resolve {:#?}", hidden_type.ty.kind()),
                        );
                        hidden_type.ty = infcx.tcx.ty_error();
                    }

                    (opaque_type_key, (hidden_type, decl.origin))
                })
                .collect()
        },
    );

    MirTypeckResults { constraints, universal_region_relations, opaque_type_values }
}
/// Type checks the given `mir` in the context of the inference
/// context `infcx`. Returns any region constraints that have yet to
/// be proven. This result includes liveness constraints that
/// ensure that regions appearing in the types of all local variables
/// are live at all points where that local variable may later be
/// used.
///
/// This phase of type-check ought to be infallible -- this is because
/// the original, HIR-based type-check succeeded. So if any errors
/// occur here, we will get a `bug!` reported.
///
/// # Parameters
///
/// - `infcx` -- inference context to use
/// - `param_env` -- parameter environment to use for trait solving
/// - `body` -- MIR body to type-check
/// - `promoted` -- map of promoted constants within `body`
/// - `universal_regions` -- the universal regions from `body`s function signature
/// - `location_table` -- MIR location map of `body`
/// - `borrow_set` -- information about borrows occurring in `body`
/// - `all_facts` -- when using Polonius, this is the generated set of Polonius facts
/// - `flow_inits` -- results of a maybe-init dataflow analysis
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
/// - `elements` -- MIR region map
Type checks the given `mir` in the context of the inference
context `infcx`. Returns any region constraints that have yet to
be proven. This result includes liveness constraints that
ensure that regions appearing in the types of all local variables
are live at all points where that local variable may later be
used.


Type checks the given ` mir ` in the context of the inference context ` infcx ` . Returns any region constraints that have yet to be proven . This result includes liveness constraints that ensure that regions appearing in the types of all local variables are live at all points where that local variable may later be used .
pub(crate) fn type_check<'mir, 'tcx>(
    infcx: &InferCtxt<'_, 'tcx>,
    param_env: ty::ParamEnv<'tcx>,
    body: &Body<'tcx>,
    promoted: &IndexVec<Promoted, Body<'tcx>>,
    universal_regions: &Rc<UniversalRegions<'tcx>>,
    location_table: &LocationTable,
    borrow_set: &BorrowSet<'tcx>,
    all_facts: &mut Option<AllFacts>,
    flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
    move_data: &MoveData<'tcx>,
    elements: &Rc<RegionValueElements>,
    upvars: &[Upvar<'tcx>],
    use_polonius: bool,
) -> MirTypeckResults<'tcx> {
    let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
    let mut universe_causes = FxHashMap::default();
    universe_causes.insert(ty::UniverseIndex::from_u32(0), UniverseInfo::other());
    let mut constraints = MirTypeckRegionConstraints {
        placeholder_indices: PlaceholderIndices::default(),
        placeholder_index_to_region: IndexVec::default(),
        liveness_constraints: LivenessValues::new(elements.clone()),
        outlives_constraints: OutlivesConstraintSet::default(),
        member_constraints: MemberConstraintSet::default(),
        closure_bounds_mapping: Default::default(),
        type_tests: Vec::default(),
        universe_causes,
    };
    let CreateResult {
        universal_region_relations,
        region_bound_pairs,
        normalized_inputs_and_output,
    } = free_region_relations::create(
        infcx,
        param_env,
        Some(implicit_region_bound),
        universal_regions,
        &mut constraints,
    );
    for u in ty::UniverseIndex::ROOT..infcx.universe() {
        let info = UniverseInfo::other();
        constraints.universe_causes.insert(u, info);
    }
    let mut borrowck_context = BorrowCheckContext {
        universal_regions,
        location_table,
        borrow_set,
        all_facts,
        constraints: &mut constraints,
        upvars,
    };
    let opaque_type_values = type_check_internal(
        infcx,
        param_env,
        body,
        promoted,
        &region_bound_pairs,
        implicit_region_bound,
        &mut borrowck_context,
        |mut cx| {
            cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
            liveness::generate(
                &mut cx,
                body,
                elements,
                flow_inits,
                move_data,
                location_table,
                use_polonius,
            );
            translate_outlives_facts(&mut cx);
            let opaque_type_values =
                infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
            opaque_type_values
                .into_iter()
                .map(|(opaque_type_key, decl)| {
                    cx.fully_perform_op(
                        Locations::All(body.span),
                        ConstraintCategory::OpaqueType,
                        CustomTypeOp::new(
                            |infcx| {
                                infcx.register_member_constraints(
                                    param_env,
                                    opaque_type_key,
                                    decl.hidden_type.ty,
                                    decl.hidden_type.span,
                                );
                                Ok(InferOk { value: (), obligations: vec![] })
                            },
                            || "opaque_type_map".to_string(),
                        ),
                    )
                    .unwrap();
                    let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
                    trace!(
                        "finalized opaque type {:?} to {:#?}",
                        opaque_type_key,
                        hidden_type.ty.kind()
                    );
                    if hidden_type.has_infer_types_or_consts() {
                        infcx.tcx.sess.delay_span_bug(
                            decl.hidden_type.span,
                            &format!("could not resolve {:#?}", hidden_type.ty.kind()),
                        );
                        hidden_type.ty = infcx.tcx.ty_error();
                    }
                    (opaque_type_key, (hidden_type, decl.origin))
                })
                .collect()
        },
    );
    MirTypeckResults { constraints, universal_region_relations, opaque_type_values }
}
pub ( crate ) fn type_check < ' mir , ' tcx > ( infcx : & InferCtxt < ' _ , ' tcx > , param_env : ty :: ParamEnv < ' tcx > , body : & Body < ' tcx > , promoted : & IndexVec < Promoted , Body < ' tcx > > , universal_regions : & Rc < UniversalRegions < ' tcx > > , location_table : & LocationTable , borrow_set : & BorrowSet < ' tcx > , all_facts : & mut Option < AllFacts > , flow_inits : & mut ResultsCursor < ' mir , ' tcx , MaybeInitializedPlaces < ' mir , ' tcx > > , move_data : & MoveData < ' tcx > , elements : & Rc < RegionValueElements > , upvars : & [ Upvar < ' tcx > ] , use_polonius : bool , ) -> MirTypeckResults < ' tcx > { let implicit_region_bound = infcx . tcx . mk_region ( ty :: ReVar ( universal_regions . fr_fn_body ) ) ; let mut universe_causes = FxHashMap :: default ( ) ; universe_causes . insert ( ty :: UniverseIndex :: from_u32 ( 0 ) , UniverseInfo :: other ( ) ) ; let mut constraints = MirTypeckRegionConstraints { placeholder_indices : PlaceholderIndices :: default ( ) , placeholder_index_to_region : IndexVec :: default ( ) , liveness_constraints : LivenessValues :: new ( elements . clone ( ) ) , outlives_constraints : OutlivesConstraintSet :: default ( ) , member_constraints : MemberConstraintSet :: default ( ) , closure_bounds_mapping : Default :: default ( ) , type_tests : Vec :: default ( ) , universe_causes , } ; let CreateResult { universal_region_relations , region_bound_pairs , normalized_inputs_and_output , } = free_region_relations :: create ( infcx , param_env , Some ( implicit_region_bound ) , universal_regions , & mut constraints , ) ; for u in ty :: UniverseIndex :: ROOT .. infcx . universe ( ) { let info = UniverseInfo :: other ( ) ; constraints . universe_causes . insert ( u , info ) ; } let mut borrowck_context = BorrowCheckContext { universal_regions , location_table , borrow_set , all_facts , constraints : & mut constraints , upvars , } ; let opaque_type_values = type_check_internal ( infcx , param_env , body , promoted , & region_bound_pairs , implicit_region_bound , & mut borrowck_context , | mut cx | { cx . equate_inputs_and_outputs ( & body , universal_regions , & normalized_inputs_and_output ) ; liveness :: generate ( & mut cx , body , elements , flow_inits , move_data , location_table , use_polonius , ) ; translate_outlives_facts ( & mut cx ) ; let opaque_type_values = infcx . inner . borrow_mut ( ) . opaque_type_storage . take_opaque_types ( ) ; opaque_type_values . into_iter ( ) . map ( | ( opaque_type_key , decl ) | { cx . fully_perform_op ( Locations :: All ( body . span ) , ConstraintCategory :: OpaqueType , CustomTypeOp :: new ( | infcx | { infcx . register_member_constraints ( param_env , opaque_type_key , decl . hidden_type . ty , decl . hidden_type . span , ) ; Ok ( InferOk { value : ( ) , obligations : vec ! [ ] } ) } , | | " " . to_string ( ) , ) , ) . unwrap ( ) ; let mut hidden_type = infcx . resolve_vars_if_possible ( decl . hidden_type ) ; trace ! ( " " opaque_type_key hidden_type ty kind ( ) ) ; if hidden_type . has_infer_types_or_consts ( ) { infcx . tcx . sess . delay_span_bug ( decl . hidden_type . span , & format ! ( " " hidden_type ty kind ( ) ) , ) ; hidden_type . ty = infcx . tcx . ty_error ( ) ; } ( opaque_type_key , ( hidden_type , decl . origin ) ) } ) . collect ( ) } , ) ; MirTypeckResults { constraints , universal_region_relations , opaque_type_values } }
Type checks the given `mir` in the context of the inference
context `infcx`.
Type checks the given ` mir ` in the context of the inference context ` infcx ` .
infcx
&InferCtxt<'_, 'tcx>
inference context to use
inference context to use
param_env
ty::ParamEnv<'tcx>
parameter environment to use for trait solving
parameter environment to use for trait solving
body
&Body<'tcx>
MIR body to type-check
MIR body to type - check
promoted
&IndexVec<Promoted, Body<'tcx>>
map of promoted constants within `body`
map of promoted constants within ` body `
universal_regions
&Rc<UniversalRegions<'tcx>>
the universal regions from `body`s function signature
the universal regions from ` body ` s function signature
location_table
&LocationTable
MIR location map of `body`
MIR location map of ` body `
borrow_set
&BorrowSet<'tcx>
information about borrows occurring in `body`
information about borrows occurring in ` body `
all_facts
&mut Option<AllFacts>
when using Polonius, this is the generated set of Polonius facts
when using Polonius this is the generated set of Polonius facts
flow_inits
&mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>
results of a maybe-init dataflow analysis
results of a maybe - init dataflow analysis
move_data
&MoveData<'tcx>
move-data constructed when performing the maybe-init dataflow analysis
move - data constructed when performing the maybe - init dataflow analysis
elements
&Rc<RegionValueElements>
MIR region map
MIR region map
upvars
&[Upvar<'tcx>]
use_polonius
bool