rapx/analysis/safedrop/
graph.rs

1use super::{bug_records::*, drop::*};
2use crate::analysis::core::{
3    alias_analysis::default::graph::MopGraph, ownedheap_analysis::OHAResultMap,
4};
5use rustc_middle::ty::TyCtxt;
6use rustc_span::def_id::DefId;
7use std::{fmt, vec::Vec};
8
9/// We represent each target function with the `SafeDropGraph` struct and then perform analysis
10/// based on the struct.
11pub struct SafeDropGraph<'tcx> {
12    pub mop_graph: MopGraph<'tcx>,
13    pub bug_records: BugRecords,
14    pub drop_record: Vec<DropRecord>,
15    // analysis of heap item
16    pub adt_owner: OHAResultMap,
17}
18
19impl<'tcx> SafeDropGraph<'tcx> {
20    pub fn new(tcx: TyCtxt<'tcx>, def_id: DefId, adt_owner: OHAResultMap) -> Self {
21        let mop_graph = MopGraph::new(tcx, def_id);
22        let mut drop_record = Vec::<DropRecord>::new();
23        for v in &mop_graph.values {
24            drop_record.push(DropRecord::false_record(v.index));
25        }
26
27        SafeDropGraph {
28            mop_graph,
29            bug_records: BugRecords::new(),
30            drop_record,
31            adt_owner,
32        }
33    }
34}
35
36impl<'tcx> std::fmt::Display for SafeDropGraph<'tcx> {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        writeln!(f, "SafeDropGraph {{")?;
39        writeln!(f, "  MopGraph: {}", self.mop_graph)?;
40        write!(f, "}}")
41    }
42}