]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_borrowck/src/consumers.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[rust.git] / compiler / rustc_borrowck / src / consumers.rs
1 #![deny(rustc::untranslatable_diagnostic)]
2 #![deny(rustc::diagnostic_outside_of_impl)]
3 //! This file provides API for compiler consumers.
4
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};
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
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.
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 `tests/run-make/obtain-borrowck/`.
29 ///
30 /// *   Polonius is highly unstable, so expect regular changes in its signature or other details.
31 pub fn get_body_with_borrowck_facts(
32     tcx: TyCtxt<'_>,
33     def: ty::WithOptConstParam<LocalDefId>,
34 ) -> BodyWithBorrowckFacts<'_> {
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()
40 }