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