1 #![deny(rustc::untranslatable_diagnostic)]
2 #![deny(rustc::diagnostic_outside_of_impl)]
3 //! This file provides API for compiler consumers.
5 use rustc_hir::def_id::LocalDefId;
6 use rustc_index::vec::IndexVec;
7 use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
8 use rustc_middle::mir::Body;
9 use rustc_middle::ty::{self, TyCtxt};
12 facts::{AllFacts as PoloniusInput, RustcFacts},
13 location::{LocationTable, RichLocation},
15 BodyWithBorrowckFacts,
18 /// This function computes Polonius facts for the given body. It makes a copy of
19 /// the body because it needs to regenerate the region identifiers. This function
20 /// should never be invoked during a typical compilation session due to performance
21 /// issues with Polonius.
24 /// * This function will panic if the required body was already stolen. This
25 /// can, for example, happen when requesting a body of a `const` function
26 /// because they are evaluated during typechecking. The panic can be avoided
27 /// by overriding the `mir_borrowck` query. You can find a complete example
28 /// that shows how to do this at `src/test/run-make/obtain-borrowck/`.
30 /// * Polonius is highly unstable, so expect regular changes in its signature or other details.
31 pub fn get_body_with_borrowck_facts<'tcx>(
33 def: ty::WithOptConstParam<LocalDefId>,
34 ) -> BodyWithBorrowckFacts<'tcx> {
35 let (input_body, promoted) = tcx.mir_promoted(def);
36 let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def.did)).build();
37 let input_body: &Body<'_> = &input_body.borrow();
38 let promoted: &IndexVec<_, _> = &promoted.borrow();
39 *super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap()