1
1
use std:: io;
2
2
3
- use rustc_middle:: mir:: pretty:: { PrettyPrintMirOptions , dump_mir_with_options} ;
3
+ use rustc_middle:: mir:: pretty:: {
4
+ PrettyPrintMirOptions , create_dump_file, dump_enabled, dump_mir_to_writer,
5
+ } ;
4
6
use rustc_middle:: mir:: { Body , ClosureRegionRequirements , PassWhere } ;
5
7
use rustc_middle:: ty:: TyCtxt ;
6
8
use rustc_session:: config:: MirIncludeSpans ;
@@ -26,9 +28,39 @@ pub(crate) fn dump_polonius_mir<'tcx>(
26
28
return ;
27
29
}
28
30
31
+ if !dump_enabled ( tcx, "polonius" , body. source . def_id ( ) ) {
32
+ return ;
33
+ }
34
+
29
35
let localized_outlives_constraints = localized_outlives_constraints
30
36
. expect ( "missing localized constraints with `-Zpolonius=next`" ) ;
31
37
38
+ let _: io:: Result < ( ) > = try {
39
+ let mut file = create_dump_file ( tcx, "mir" , false , "polonius" , & 0 , body) ?;
40
+ emit_polonius_dump (
41
+ tcx,
42
+ body,
43
+ regioncx,
44
+ borrow_set,
45
+ localized_outlives_constraints,
46
+ closure_region_requirements,
47
+ & mut file,
48
+ ) ?;
49
+ } ;
50
+ }
51
+
52
+ /// The polonius dump consists of:
53
+ /// - the NLL MIR
54
+ /// - the list of polonius localized constraints
55
+ fn emit_polonius_dump < ' tcx > (
56
+ tcx : TyCtxt < ' tcx > ,
57
+ body : & Body < ' tcx > ,
58
+ regioncx : & RegionInferenceContext < ' tcx > ,
59
+ borrow_set : & BorrowSet < ' tcx > ,
60
+ localized_outlives_constraints : LocalizedOutlivesConstraintSet ,
61
+ closure_region_requirements : & Option < ClosureRegionRequirements < ' tcx > > ,
62
+ out : & mut dyn io:: Write ,
63
+ ) -> io:: Result < ( ) > {
32
64
// We want the NLL extra comments printed by default in NLL MIR dumps (they were removed in
33
65
// #112346). Specifying `-Z mir-include-spans` on the CLI still has priority: for example,
34
66
// they're always disabled in mir-opt tests to make working with blessed dumps easier.
@@ -39,12 +71,12 @@ pub(crate) fn dump_polonius_mir<'tcx>(
39
71
) ,
40
72
} ;
41
73
42
- dump_mir_with_options (
74
+ dump_mir_to_writer (
43
75
tcx,
44
- false ,
45
76
"polonius" ,
46
77
& 0 ,
47
78
body,
79
+ out,
48
80
|pass_where, out| {
49
81
emit_polonius_mir (
50
82
tcx,
@@ -57,7 +89,7 @@ pub(crate) fn dump_polonius_mir<'tcx>(
57
89
)
58
90
} ,
59
91
options,
60
- ) ;
92
+ )
61
93
}
62
94
63
95
/// Produces the actual NLL + Polonius MIR sections to emit during the dumping process.
0 commit comments