about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLuis Cardoso <61982523+LuisCardosoOliveira@users.noreply.github.com>2022-08-19 15:34:13 +0200
committerLuis Cardoso <61982523+LuisCardosoOliveira@users.noreply.github.com>2022-08-26 16:10:11 +0200
commit706452eba74026c51e8d0fa30aee2497c69eafc0 (patch)
tree6752f312b153cc954032e2dd9413736f52bf14ee
parent8a13871b69924b74cfa1d737f2894068b37ea7ea (diff)
downloadrust-706452eba74026c51e8d0fa30aee2497c69eafc0.tar.gz
rust-706452eba74026c51e8d0fa30aee2497c69eafc0.zip
translations(rustc_session): migrate the file cgu_reuse_tracker
This commit migrates the errors that indicates an incorrect
CGU type and the fatal error that indicates that a CGU has
not been correctly recorded
-rw-r--r--compiler/rustc_error_messages/locales/en-US/session.ftl5
-rw-r--r--compiler/rustc_error_messages/src/lib.rs1
-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
5 files changed, 60 insertions, 5 deletions
diff --git a/compiler/rustc_error_messages/locales/en-US/session.ftl b/compiler/rustc_error_messages/locales/en-US/session.ftl
new file mode 100644
index 00000000000..71d3abc5e6b
--- /dev/null
+++ b/compiler/rustc_error_messages/locales/en-US/session.ftl
@@ -0,0 +1,5 @@
+incorrect_cgu_reuse_type = 
+    CGU-reuse for `{$cgu_user_name}` is `{$actual_reuse}` but should be `{$at_least}``${expected_reuse}`
+
+cgu_not_recorded = 
+    CGU-reuse for `{$cgu_user_name}` is (mangled: `{$cgu_name}`) was not recorded`
\ No newline at end of file
diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs
index 2d001d445be..2fde301d19d 100644
--- a/compiler/rustc_error_messages/src/lib.rs
+++ b/compiler/rustc_error_messages/src/lib.rs
@@ -37,6 +37,7 @@ fluent_messages! {
     builtin_macros => "../locales/en-US/builtin_macros.ftl",
     const_eval => "../locales/en-US/const_eval.ftl",
     expand => "../locales/en-US/expand.ftl",
+    session => "../locales/en-US/session.ftl",
     interface => "../locales/en-US/interface.ftl",
     lint => "../locales/en-US/lint.ftl",
     parser => "../locales/en-US/parser.ftl",
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;