about summary refs log tree commit diff
path: root/compiler/rustc_session/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_session/src')
-rw-r--r--compiler/rustc_session/src/cgu_reuse_tracker.rs34
-rw-r--r--compiler/rustc_session/src/errors.rs22
-rw-r--r--compiler/rustc_session/src/lib.rs3
3 files changed, 54 insertions, 5 deletions
diff --git a/compiler/rustc_session/src/cgu_reuse_tracker.rs b/compiler/rustc_session/src/cgu_reuse_tracker.rs
index dd64e8ab71e..88fcbf7c113 100644
--- a/compiler/rustc_session/src/cgu_reuse_tracker.rs
+++ b/compiler/rustc_session/src/cgu_reuse_tracker.rs
@@ -2,8 +2,13 @@
 //! compilation. This is used for incremental compilation tests and debug
 //! output.
 
+use crate::errors::IncorrectCguReuseType;
+// use crate::errors::{CguNotRecorded, IncorrectCguReuseType};
 use rustc_data_structures::fx::FxHashMap;
+use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
 use rustc_span::{Span, Symbol};
+use std::borrow::Cow;
+use std::fmt::{self};
 use std::sync::{Arc, Mutex};
 use tracing::debug;
 
@@ -14,6 +19,22 @@ pub enum CguReuse {
     PostLto,
 }
 
+impl fmt::Display for CguReuse {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match *self {
+            CguReuse::No => write!(f, "No"),
+            CguReuse::PreLto => write!(f, "PreLto "),
+            CguReuse::PostLto => write!(f, "PostLto "),
+        }
+    }
+}
+
+impl IntoDiagnosticArg for CguReuse {
+    fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
+        DiagnosticArgValue::Str(Cow::Owned(self.to_string()))
+    }
+}
+
 #[derive(Copy, Clone, Debug, PartialEq)]
 pub enum ComparisonKind {
     Exact,
@@ -99,11 +120,13 @@ impl CguReuseTracker {
 
                     if error {
                         let at_least = if at_least { "at least " } else { "" };
-                        let msg = format!(
-                            "CGU-reuse for `{cgu_user_name}` is `{actual_reuse:?}` but \
-                                           should be {at_least}`{expected_reuse:?}`"
-                        );
-                        diag.span_err(error_span.0, &msg);
+                        IncorrectCguReuseType {
+                            span: error_span.0,
+                            cgu_user_name: &cgu_user_name,
+                            actual_reuse,
+                            expected_reuse,
+                            at_least,
+                        };
                     }
                 } else {
                     let msg = format!(
@@ -111,6 +134,7 @@ impl CguReuseTracker {
                                        not recorded"
                     );
                     diag.span_fatal(error_span.0, &msg)
+                    // CguNotRecorded { cgu_user_name, cgu_name };
                 }
             }
         }
diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs
new file mode 100644
index 00000000000..ef78d1c9836
--- /dev/null
+++ b/compiler/rustc_session/src/errors.rs
@@ -0,0 +1,22 @@
+use crate as rustc_session;
+use crate::cgu_reuse_tracker::CguReuse;
+use rustc_macros::SessionDiagnostic;
+use rustc_span::Span;
+
+#[derive(SessionDiagnostic)]
+#[error(session::incorrect_cgu_reuse_type)]
+pub struct IncorrectCguReuseType<'a> {
+    #[primary_span]
+    pub span: Span,
+    pub cgu_user_name: &'a str,
+    pub actual_reuse: CguReuse,
+    pub expected_reuse: CguReuse,
+    pub at_least: &'a str,
+}
+
+// #[derive(SessionDiagnostic)]
+// #[fatal(session::cgu_not_recorded)]
+// pub struct CguNotRecorded<'a> {
+//     pub cgu_user_name: &'a str,
+//     pub cgu_name: &'a str,
+// }
diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs
index 0617bd5fae7..113bd85135e 100644
--- a/compiler/rustc_session/src/lib.rs
+++ b/compiler/rustc_session/src/lib.rs
@@ -8,9 +8,12 @@
 #![feature(map_many_mut)]
 #![recursion_limit = "256"]
 #![allow(rustc::potential_query_instability)]
+#![deny(rustc::untranslatable_diagnostic)]
+#![deny(rustc::diagnostic_outside_of_impl)]
 
 #[macro_use]
 extern crate rustc_macros;
+pub mod errors;
 
 pub mod cgu_reuse_tracker;
 pub mod utils;