]>
Commit | Line | Data |
---|---|---|
487cf647 FG |
1 | #![deny(rustc::untranslatable_diagnostic)] |
2 | #![deny(rustc::diagnostic_outside_of_impl)] | |
94222f64 XL |
3 | //! This file provides API for compiler consumers. |
4 | ||
5 | use rustc_hir::def_id::LocalDefId; | |
6 | use rustc_index::vec::IndexVec; | |
064997fb | 7 | use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt}; |
94222f64 XL |
8 | use rustc_middle::mir::Body; |
9 | use rustc_middle::ty::{self, TyCtxt}; | |
10 | ||
11 | pub use super::{ | |
12 | facts::{AllFacts as PoloniusInput, RustcFacts}, | |
13 | location::{LocationTable, RichLocation}, | |
14 | nll::PoloniusOutput, | |
15 | BodyWithBorrowckFacts, | |
16 | }; | |
17 | ||
18 | /// This function computes Polonius facts for the given body. It makes a copy of | |
c295e0f8 XL |
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. | |
94222f64 XL |
22 | /// |
23 | /// Note: | |
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/`. | |
94222f64 XL |
29 | /// |
30 | /// * Polonius is highly unstable, so expect regular changes in its signature or other details. | |
31 | pub fn get_body_with_borrowck_facts<'tcx>( | |
32 | tcx: TyCtxt<'tcx>, | |
33 | def: ty::WithOptConstParam<LocalDefId>, | |
34 | ) -> BodyWithBorrowckFacts<'tcx> { | |
35 | let (input_body, promoted) = tcx.mir_promoted(def); | |
2b03887a FG |
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() | |
94222f64 | 40 | } |