flowistry_ide/
playground.rs

1use anyhow::Result;
2use log::debug;
3use rustc_data_structures::fx::FxHashSet as HashSet;
4use rustc_hir::BodyId;
5use rustc_middle::ty::TyCtxt;
6use rustc_utils::{BodyExt, mir::borrowck_facts::get_body_with_borrowck_facts};
7use serde::Serialize;
8
9#[derive(Debug, Clone, Serialize, Default)]
10pub struct PlaygroundOutput {
11  outlives: HashSet<(String, String)>,
12}
13
14pub fn playground(tcx: TyCtxt, body_id: BodyId) -> Result<PlaygroundOutput> {
15  let def_id = tcx.hir_body_owner_def_id(body_id);
16  let body_with_facts = get_body_with_borrowck_facts(tcx, def_id);
17  let body = &body_with_facts.body;
18  debug!("{}", body.to_string(tcx).unwrap());
19
20  let subset_base = &body_with_facts.input_facts.as_ref().unwrap().subset_base;
21  let outlives = subset_base
22    .iter()
23    .map(|(sup, sub, _)| (format!("{sup:?}"), format!("{sub:?}")))
24    .collect::<HashSet<_>>();
25
26  Ok(PlaygroundOutput { outlives })
27}