/// Computes the (non-lexical) regions from the input MIR.
///
/// This may result in errors being reported.
Computes the (non-lexical) regions from the input MIR.
This may result in errors being reported.
Computes the ( non - lexical ) regions from the input MIR . This may result in errors being reported .
pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
    infcx: &InferCtxt<'cx, 'gcx, 'tcx>,
    def_id: DefId,
    universal_regions: UniversalRegions<'tcx>,
    mir: &Mir<'tcx>,
    location_table: &LocationTable,
    param_env: ty::ParamEnv<'gcx>,
    flow_inits: &mut FlowAtLocation<MaybeInitializedPlaces<'cx, 'gcx, 'tcx>>,
    move_data: &MoveData<'tcx>,
    borrow_set: &BorrowSet<'tcx>,
    errors_buffer: &mut Vec<Diagnostic>,
) -> (
    RegionInferenceContext<'tcx>,
    Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex>>>,
    Option<ClosureRegionRequirements<'gcx>>,
) {
    let mut all_facts = if AllFacts::enabled(infcx.tcx) {
        Some(AllFacts::default())
    } else {
        None
    };
    let universal_regions = Rc::new(universal_regions);
    let elements = &Rc::new(RegionValueElements::new(mir));
    // Run the MIR type-checker.
    let MirTypeckResults {
        constraints,
        universal_region_relations,
        liveness,
        liveness_map,
    } = type_check::type_check(
        infcx,
        param_env,
        mir,
        def_id,
        &universal_regions,
        location_table,
        borrow_set,
        &mut all_facts,
        flow_inits,
        move_data,
        elements,
        errors_buffer,
    );
    if let Some(all_facts) = &mut all_facts {
        all_facts
            .universal_region
            .extend(universal_regions.universal_regions());
    }
    // Create the region inference context, taking ownership of the
    // region inference data that was contained in `infcx`, and the
    // base constraints generated by the type-check.
    let var_origins = infcx.take_region_var_origins();
    let MirTypeckRegionConstraints {
        mut liveness_constraints,
        outlives_constraints,
        type_tests,
    } = constraints;
    constraint_generation::generate_constraints(
        infcx,
        &mut liveness_constraints,
        &mut all_facts,
        location_table,
        &mir,
        borrow_set,
    );
    let mut regioncx = RegionInferenceContext::new(
        var_origins,
        universal_regions,
        universal_region_relations,
        mir,
        outlives_constraints,
        type_tests,
        liveness_constraints,
        elements,
    );
    // Generate various additional constraints.
    invalidation::generate_invalidates(
        infcx,
        &mut all_facts,
        location_table,
        &mir,
        def_id,
        borrow_set,
    );
    // Dump facts if requested.
    let polonius_output = all_facts.and_then(|all_facts| {
        if infcx.tcx.sess.opts.debugging_opts.nll_facts {
            let def_path = infcx.tcx.hir.def_path(def_id);
            let dir_path =
                PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
            all_facts.write_to_dir(dir_path, location_table).unwrap();
        }
        if infcx.tcx.sess.opts.debugging_opts.polonius {
            let algorithm = env::var("POLONIUS_ALGORITHM")
                .unwrap_or(String::from("DatafrogOpt"));
            let algorithm = Algorithm::from_str(&algorithm).unwrap();
            debug!("compute_regions: using polonius algorithm {:?}", algorithm);
            Some(Rc::new(Output::compute(
                &all_facts,
                algorithm,
                false,
            )))
        } else {
            None
        }
    });
    // Solve the region constraints.
    let closure_region_requirements = regioncx.solve(infcx, &mir, def_id, errors_buffer);
    // Dump MIR results into a file, if that is enabled. This let us
    // write unit-tests, as well as helping with debugging.
    dump_mir_results(
        infcx,
        &liveness,
        &liveness_map,
        MirSource::item(def_id),
        &mir,
        &regioncx,
        &closure_region_requirements,
    );
    // We also have a `#[rustc_nll]` annotation that causes us to dump
    // information
    dump_annotation(infcx, &mir, def_id, &regioncx, &closure_region_requirements, errors_buffer);
    (regioncx, polonius_output, closure_region_requirements)
}
pub ( in borrow_check ) fn compute_regions < ' cx , ' gcx , ' tcx > ( infcx : & InferCtxt < ' cx , ' gcx , ' tcx > , def_id : DefId , universal_regions : UniversalRegions < ' tcx > , mir : & Mir < ' tcx > , location_table : & LocationTable , param_env : ty :: ParamEnv < ' gcx > , flow_inits : & mut FlowAtLocation < MaybeInitializedPlaces < ' cx , ' gcx , ' tcx > > , move_data : & MoveData < ' tcx > , borrow_set : & BorrowSet < ' tcx > , errors_buffer : & mut Vec < Diagnostic > , ) -> ( RegionInferenceContext < ' tcx > , Option < Rc < Output < RegionVid , BorrowIndex , LocationIndex > > > , Option < ClosureRegionRequirements < ' gcx > > , ) { let mut all_facts = if AllFacts :: enabled ( infcx . tcx ) { Some ( AllFacts :: default ( ) ) } else { None } ; let universal_regions = Rc :: new ( universal_regions ) ; let elements = & Rc :: new ( RegionValueElements :: new ( mir ) ) ; // Run the MIR type-checker. let MirTypeckResults { constraints , universal_region_relations , liveness , liveness_map , } = type_check :: type_check ( infcx , param_env , mir , def_id , & universal_regions , location_table , borrow_set , & mut all_facts , flow_inits , move_data , elements , errors_buffer , ) ; if let Some ( all_facts ) = & mut all_facts { all_facts . universal_region . extend ( universal_regions . universal_regions ( ) ) ; } // Create the region inference context, taking ownership of the // region inference data that was contained in `infcx`, and the // base constraints generated by the type-check. let var_origins = infcx . take_region_var_origins ( ) ; let MirTypeckRegionConstraints { mut liveness_constraints , outlives_constraints , type_tests , } = constraints ; constraint_generation :: generate_constraints ( infcx , & mut liveness_constraints , & mut all_facts , location_table , & mir , borrow_set , ) ; let mut regioncx = RegionInferenceContext :: new ( var_origins , universal_regions , universal_region_relations , mir , outlives_constraints , type_tests , liveness_constraints , elements , ) ; // Generate various additional constraints. invalidation :: generate_invalidates ( infcx , & mut all_facts , location_table , & mir , def_id , borrow_set , ) ; // Dump facts if requested. let polonius_output = all_facts . and_then ( | all_facts | { if infcx . tcx . sess . opts . debugging_opts . nll_facts { let def_path = infcx . tcx . hir . def_path ( def_id ) ; let dir_path = PathBuf :: from ( " " ) . join ( def_path . to_filename_friendly_no_crate ( ) ) ; all_facts . write_to_dir ( dir_path , location_table ) . unwrap ( ) ; } if infcx . tcx . sess . opts . debugging_opts . polonius { let algorithm = env :: var ( " " ) . unwrap_or ( String :: from ( " " ) ) ; let algorithm = Algorithm :: from_str ( & algorithm ) . unwrap ( ) ; debug ! ( " " algorithm ) ; Some ( Rc :: new ( Output :: compute ( & all_facts , algorithm , false , ) ) ) } else { None } } ) ; // Solve the region constraints. let closure_region_requirements = regioncx . solve ( infcx , & mir , def_id , errors_buffer ) ; // Dump MIR results into a file, if that is enabled. This let us // write unit-tests, as well as helping with debugging. dump_mir_results ( infcx , & liveness , & liveness_map , MirSource :: item ( def_id ) , & mir , & regioncx , & closure_region_requirements , ) ; // We also have a `#[rustc_nll]` annotation that causes us to dump // information dump_annotation ( infcx , & mir , def_id , & regioncx , & closure_region_requirements , errors_buffer ) ; ( regioncx , polonius_output , closure_region_requirements ) }
Computes the (non-lexical) regions from the input MIR.
Computes the ( non - lexical ) regions from the input MIR .
infcx
&InferCtxt<'cx, 'gcx, 'tcx>
def_id
DefId
universal_regions
UniversalRegions<'tcx>
mir
&Mir<'tcx>
location_table
&LocationTable
param_env
ty::ParamEnv<'gcx>
flow_inits
&mut FlowAtLocation<MaybeInitializedPlaces<'cx, 'gcx, 'tcx>>
move_data
&MoveData<'tcx>
borrow_set
&BorrowSet<'tcx>
errors_buffer
&mut Vec<Diagnostic>