]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_borrowck/src/consumers.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / compiler / rustc_borrowck / src / consumers.rs
CommitLineData
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
5use rustc_hir::def_id::LocalDefId;
353b0b11 6use rustc_index::vec::IndexSlice;
064997fb 7use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
94222f64
XL
8use rustc_middle::mir::Body;
9use rustc_middle::ty::{self, TyCtxt};
10
11pub 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
9c376795 28/// that shows how to do this at `tests/run-make/obtain-borrowck/`.
94222f64
XL
29///
30/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
9c376795
FG
31pub fn get_body_with_borrowck_facts(
32 tcx: TyCtxt<'_>,
94222f64 33 def: ty::WithOptConstParam<LocalDefId>,
9c376795 34) -> BodyWithBorrowckFacts<'_> {
94222f64 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();
353b0b11 38 let promoted: &IndexSlice<_, _> = &promoted.borrow();
2b03887a 39 *super::do_mir_borrowck(&infcx, input_body, promoted, true).1.unwrap()
94222f64 40}