1 //! This file provides API for compiler consumers.
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}
;
10 facts
::{AllFacts as PoloniusInput, RustcFacts}
,
11 location
::{LocationTable, RichLocation}
,
13 BodyWithBorrowckFacts
,
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.
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.
28 /// * Polonius is highly unstable, so expect regular changes in its signature or other details.
29 pub fn get_body_with_borrowck_facts
<'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
()