22//! compilation. This is used for incremental compilation tests and debug
33//! output.
44
5+ use crate :: errors:: IncorrectCguReuseType ;
6+ // use crate::errors::{CguNotRecorded, IncorrectCguReuseType};
57use rustc_data_structures:: fx:: FxHashMap ;
8+ use rustc_errors:: { DiagnosticArgValue , IntoDiagnosticArg } ;
69use rustc_span:: { Span , Symbol } ;
10+ use std:: borrow:: Cow ;
11+ use std:: fmt:: { self } ;
712use std:: sync:: { Arc , Mutex } ;
813use tracing:: debug;
914
@@ -14,6 +19,22 @@ pub enum CguReuse {
1419 PostLto ,
1520}
1621
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+
1738#[ derive( Copy , Clone , Debug , PartialEq ) ]
1839pub enum ComparisonKind {
1940 Exact ,
@@ -99,18 +120,21 @@ impl CguReuseTracker {
99120
100121 if error {
101122 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+ } ;
107130 }
108131 } else {
109132 let msg = format ! (
110133 "CGU-reuse for `{cgu_user_name}` (mangled: `{cgu_name}`) was \
111134 not recorded"
112135 ) ;
113136 diag. span_fatal ( error_span. 0 , & msg)
137+ // CguNotRecorded { cgu_user_name, cgu_name };
114138 }
115139 }
116140 }
0 commit comments