rapx/analysis/safedrop/
graph.rs1use super::bug_records::*;
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, usize, vec::Vec};
8
9#[derive(Debug, Copy, Clone)]
10pub struct DropRecord {
11 pub is_dropped: bool,
12 pub drop_at_bb: usize,
13 pub drop_via_local: usize,
14}
15
16impl DropRecord {
17 pub fn new(is_dropped: bool, drop_at_bb: usize, drop_via_local: usize) -> Self {
18 DropRecord {
19 is_dropped,
20 drop_at_bb,
21 drop_via_local,
22 }
23 }
24 pub fn false_record() -> Self {
25 DropRecord {
26 is_dropped: false,
27 drop_at_bb: usize::MAX,
28 drop_via_local: usize::MAX,
29 }
30 }
31}
32
33pub struct SafeDropGraph<'tcx> {
36 pub mop_graph: MopGraph<'tcx>,
37 pub bug_records: BugRecords,
38 pub drop_record: Vec<DropRecord>,
40 pub adt_owner: OHAResultMap,
42}
43
44impl<'tcx> SafeDropGraph<'tcx> {
45 pub fn new(tcx: TyCtxt<'tcx>, def_id: DefId, adt_owner: OHAResultMap) -> Self {
46 let mop_graph = MopGraph::new(tcx, def_id);
47 let mut drop_record = Vec::<DropRecord>::new();
48 for _v in &mop_graph.values {
49 drop_record.push(DropRecord::false_record());
50 }
51
52 SafeDropGraph {
53 mop_graph,
54 bug_records: BugRecords::new(),
55 drop_record,
56 adt_owner,
57 }
58 }
59}
60
61impl<'tcx> std::fmt::Display for SafeDropGraph<'tcx> {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 writeln!(f, "SafeDropGraph {{")?;
64 writeln!(f, " MopGraph: {}", self.mop_graph)?;
65 write!(f, "}}")
66 }
67}