2
2
//! compilation. This is used for incremental compilation tests and debug
3
3
//! output.
4
4
5
+ use crate :: errors:: IncorrectCguReuseType ;
6
+ // use crate::errors::{CguNotRecorded, IncorrectCguReuseType};
5
7
use rustc_data_structures:: fx:: FxHashMap ;
8
+ use rustc_errors:: { DiagnosticArgValue , IntoDiagnosticArg } ;
6
9
use rustc_span:: { Span , Symbol } ;
10
+ use std:: borrow:: Cow ;
11
+ use std:: fmt:: { self } ;
7
12
use std:: sync:: { Arc , Mutex } ;
8
13
use tracing:: debug;
9
14
@@ -14,6 +19,22 @@ pub enum CguReuse {
14
19
PostLto ,
15
20
}
16
21
22
+ impl fmt:: Display for CguReuse {
23
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
24
+ match * self {
25
+ CguReuse :: No => write ! ( f, "No" ) ,
26
+ CguReuse :: PreLto => write ! ( f, "PreLto " ) ,
27
+ CguReuse :: PostLto => write ! ( f, "PostLto " ) ,
28
+ }
29
+ }
30
+ }
31
+
32
+ impl IntoDiagnosticArg for CguReuse {
33
+ fn into_diagnostic_arg ( self ) -> DiagnosticArgValue < ' static > {
34
+ DiagnosticArgValue :: Str ( Cow :: Owned ( self . to_string ( ) ) )
35
+ }
36
+ }
37
+
17
38
#[ derive( Copy , Clone , Debug , PartialEq ) ]
18
39
pub enum ComparisonKind {
19
40
Exact ,
@@ -99,18 +120,21 @@ impl CguReuseTracker {
99
120
100
121
if error {
101
122
let at_least = if at_least { "at least " } else { "" } ;
102
- let msg = format ! (
103
- "CGU-reuse for `{cgu_user_name}` is `{actual_reuse:?}` but \
104
- should be {at_least}`{expected_reuse:?}`"
105
- ) ;
106
- diag. span_err ( error_span. 0 , & msg) ;
123
+ IncorrectCguReuseType {
124
+ span : error_span. 0 ,
125
+ cgu_user_name : & cgu_user_name,
126
+ actual_reuse,
127
+ expected_reuse,
128
+ at_least,
129
+ } ;
107
130
}
108
131
} else {
109
132
let msg = format ! (
110
133
"CGU-reuse for `{cgu_user_name}` (mangled: `{cgu_name}`) was \
111
134
not recorded"
112
135
) ;
113
136
diag. span_fatal ( error_span. 0 , & msg)
137
+ // CguNotRecorded { cgu_user_name, cgu_name };
114
138
}
115
139
}
116
140
}
0 commit comments