@@ -4,22 +4,31 @@ pub(super) struct ProofTreeFormatter<'a, 'b> {
4
4
f : & ' a mut ( dyn Write + ' b ) ,
5
5
}
6
6
7
+ enum IndentorState {
8
+ StartWithNewline ,
9
+ OnNewline ,
10
+ Inline ,
11
+ }
12
+
7
13
/// A formatter which adds 4 spaces of indentation to its input before
8
14
/// passing it on to its nested formatter.
9
15
///
10
16
/// We can use this for arbitrary levels of indentation by nesting it.
11
17
struct Indentor < ' a , ' b > {
12
18
f : & ' a mut ( dyn Write + ' b ) ,
13
- on_newline : bool ,
19
+ state : IndentorState ,
14
20
}
15
21
16
22
impl Write for Indentor < ' _ , ' _ > {
17
23
fn write_str ( & mut self , s : & str ) -> std:: fmt:: Result {
18
24
for line in s. split_inclusive ( '\n' ) {
19
- if self . on_newline {
20
- self . f . write_str ( " " ) ?;
25
+ match self . state {
26
+ IndentorState :: StartWithNewline => self . f . write_str ( "\n " ) ?,
27
+ IndentorState :: OnNewline => self . f . write_str ( " " ) ?,
28
+ IndentorState :: Inline => { }
21
29
}
22
- self . on_newline = line. ends_with ( '\n' ) ;
30
+ self . state =
31
+ if line. ends_with ( '\n' ) { IndentorState :: OnNewline } else { IndentorState :: Inline } ;
23
32
self . f . write_str ( line) ?;
24
33
}
25
34
@@ -32,11 +41,15 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
32
41
ProofTreeFormatter { f }
33
42
}
34
43
35
- fn nested < F , R > ( & mut self , func : F ) -> R
44
+ fn nested < F > ( & mut self , func : F ) -> std :: fmt :: Result
36
45
where
37
- F : FnOnce ( & mut ProofTreeFormatter < ' _ , ' _ > ) -> R ,
46
+ F : FnOnce ( & mut ProofTreeFormatter < ' _ , ' _ > ) -> std :: fmt :: Result ,
38
47
{
39
- func ( & mut ProofTreeFormatter { f : & mut Indentor { f : self . f , on_newline : true } } )
48
+ write ! ( self . f, " {{" ) ?;
49
+ func ( & mut ProofTreeFormatter {
50
+ f : & mut Indentor { f : self . f , state : IndentorState :: StartWithNewline } ,
51
+ } ) ?;
52
+ writeln ! ( self . f, "}}" )
40
53
}
41
54
42
55
pub ( super ) fn format_goal_evaluation ( & mut self , eval : & GoalEvaluation < ' _ > ) -> std:: fmt:: Result {
@@ -47,7 +60,7 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
47
60
IsNormalizesToHack :: Yes => "NORMALIZES-TO HACK GOAL" ,
48
61
} ,
49
62
} ;
50
- writeln ! ( self . f, "{}: {:?}" , goal_text, eval. uncanonicalized_goal) ?;
63
+ write ! ( self . f, "{}: {:?}" , goal_text, eval. uncanonicalized_goal) ?;
51
64
self . nested ( |this| this. format_canonical_goal_evaluation ( & eval. evaluation ) )
52
65
}
53
66
@@ -69,7 +82,7 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
69
82
}
70
83
CanonicalGoalEvaluationKind :: Evaluation { revisions } => {
71
84
for ( n, step) in revisions. iter ( ) . enumerate ( ) {
72
- writeln ! ( self . f, "REVISION {n}" ) ?;
85
+ write ! ( self . f, "REVISION {n}" ) ?;
73
86
self . nested ( |this| this. format_evaluation_step ( step) ) ?;
74
87
}
75
88
writeln ! ( self . f, "RESULT: {:?}" , eval. result)
@@ -88,25 +101,25 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
88
101
pub ( super ) fn format_probe ( & mut self , probe : & Probe < ' _ > ) -> std:: fmt:: Result {
89
102
match & probe. kind {
90
103
ProbeKind :: Root { result } => {
91
- writeln ! ( self . f, "ROOT RESULT: {result:?}" )
104
+ write ! ( self . f, "ROOT RESULT: {result:?}" )
92
105
}
93
106
ProbeKind :: NormalizedSelfTyAssembly => {
94
- writeln ! ( self . f, "NORMALIZING SELF TY FOR ASSEMBLY:" )
107
+ write ! ( self . f, "NORMALIZING SELF TY FOR ASSEMBLY:" )
95
108
}
96
109
ProbeKind :: UnsizeAssembly => {
97
- writeln ! ( self . f, "ASSEMBLING CANDIDATES FOR UNSIZING:" )
110
+ write ! ( self . f, "ASSEMBLING CANDIDATES FOR UNSIZING:" )
98
111
}
99
112
ProbeKind :: UpcastProjectionCompatibility => {
100
- writeln ! ( self . f, "PROBING FOR PROJECTION COMPATIBILITY FOR UPCASTING:" )
113
+ write ! ( self . f, "PROBING FOR PROJECTION COMPATIBILITY FOR UPCASTING:" )
101
114
}
102
115
ProbeKind :: CommitIfOk => {
103
- writeln ! ( self . f, "COMMIT_IF_OK:" )
116
+ write ! ( self . f, "COMMIT_IF_OK:" )
104
117
}
105
118
ProbeKind :: MiscCandidate { name, result } => {
106
- writeln ! ( self . f, "CANDIDATE {name}: {result:?}" )
119
+ write ! ( self . f, "CANDIDATE {name}: {result:?}" )
107
120
}
108
121
ProbeKind :: TraitCandidate { source, result } => {
109
- writeln ! ( self . f, "CANDIDATE {source:?}: {result:?}" )
122
+ write ! ( self . f, "CANDIDATE {source:?}: {result:?}" )
110
123
}
111
124
} ?;
112
125
@@ -137,7 +150,7 @@ impl<'a, 'b> ProofTreeFormatter<'a, 'b> {
137
150
writeln ! ( self . f, "TRY_EVALUATE_ADDED_GOALS: {:?}" , added_goals_evaluation. result) ?;
138
151
139
152
for ( n, iterations) in added_goals_evaluation. evaluations . iter ( ) . enumerate ( ) {
140
- writeln ! ( self . f, "ITERATION {n}" ) ?;
153
+ write ! ( self . f, "ITERATION {n}" ) ?;
141
154
self . nested ( |this| {
142
155
for goal_evaluation in iterations {
143
156
this. format_goal_evaluation ( goal_evaluation) ?;
0 commit comments