]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_borrowck/src/consumers.rs
Change InferCtxtBuilder from enter to build
[rust.git] / compiler / rustc_borrowck / src / 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::{DefiningAnchor, 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. This function
18 /// should never be invoked during a typical compilation session due to performance
19 /// issues with Polonius.
20 ///
21 /// Note:
22 /// *   This function will panic if the required body was already stolen. This
23 ///     can, for example, happen when requesting a body of a `const` function
24 ///     because they are evaluated during typechecking. The panic can be avoided
25 ///     by overriding the `mir_borrowck` query. You can find a complete example
26 ///     that shows how to do this at `src/test/run-make/obtain-borrowck/`.
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     let infcx = tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(def.did)).build();
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 }