]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_mir/src/borrow_check/consumers.rs
New upstream version 1.56.0+dfsg1
[rustc.git] / compiler / rustc_mir / src / borrow_check / consumers.rs
1 //! This file provides API for compiler consumers.
2
3 use rustc_hir::def_id::LocalDefId;
4 use rustc_index::vec::IndexVec;
5 use rustc_infer::infer::TyCtxtInferExt;
6 use rustc_middle::mir::Body;
7 use rustc_middle::ty::{self, TyCtxt};
8
9 pub use super::{
10 facts::{AllFacts as PoloniusInput, RustcFacts},
11 location::{LocationTable, RichLocation},
12 nll::PoloniusOutput,
13 BodyWithBorrowckFacts,
14 };
15
16 /// This function computes Polonius facts for the given body. It makes a copy of
17 /// the body because it needs to regenerate the region identifiers.
18 ///
19 /// Note:
20 /// * This function will panic if the required body was already stolen. This
21 /// can, for example, happen when requesting a body of a `const` function
22 /// because they are evaluated during typechecking. The panic can be avoided
23 /// by overriding the `mir_borrowck` query. You can find a complete example
24 /// that shows how to do this at `src/test/run-make/obtain-borrowck/`.
25 /// * This function will also panic if computation of Polonius facts
26 /// (`-Zpolonius` flag) is not enabled.
27 ///
28 /// * Polonius is highly unstable, so expect regular changes in its signature or other details.
29 pub fn get_body_with_borrowck_facts<'tcx>(
30 tcx: TyCtxt<'tcx>,
31 def: ty::WithOptConstParam<LocalDefId>,
32 ) -> BodyWithBorrowckFacts<'tcx> {
33 let (input_body, promoted) = tcx.mir_promoted(def);
34 tcx.infer_ctxt().enter(|infcx| {
35 let input_body: &Body<'_> = &input_body.borrow();
36 let promoted: &IndexVec<_, _> = &promoted.borrow();
37 *super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap()
38 })
39 }