]> git.lizzy.rs Git - rust.git/commitdiff
replace some usages of [Span]FatalError with error-specific types
authorNathan Stocks <cleancut@github.com>
Tue, 23 Aug 2022 17:20:01 +0000 (11:20 -0600)
committerNathan Stocks <cleancut@github.com>
Thu, 25 Aug 2022 17:06:45 +0000 (11:06 -0600)
compiler/rustc_error_messages/locales/en-US/monomorphize.ftl
compiler/rustc_monomorphize/src/errors.rs
compiler/rustc_monomorphize/src/partitioning/mod.rs

index 4c67c6f5cb46dff622ad70086ab18f9f966cd2f3..48ddb54b79e795eb3c67f96b69bb5dda24e32f01 100644 (file)
@@ -11,6 +11,10 @@ monomorphize_consider_type_length_limit =
 
 monomorphize_fatal_error = {$error_message}
 
+monomorphize_unknown_partition_strategy = unknown partitioning strategy
+
+monomorphize_symbol_already_defined = symbol `{$symbol}` is already defined
+
 monomorphize_unused_generic_params = item has unused generic parameters
 
 monomorphize_large_assignments =
index 62ebac97136ceb274fc6a3a418bfced016af263a..fa7655f262425947d417674d54f81f36d2e110b5 100644 (file)
@@ -39,14 +39,6 @@ pub struct FatalError {
     pub error_message: String,
 }
 
-#[derive(SessionDiagnostic)]
-#[diag(monomorphize::fatal_error)]
-pub struct SpanFatalError {
-    #[primary_span]
-    pub span: Span,
-    pub error_message: String,
-}
-
 pub struct UnusedGenericParams {
     pub span: Span,
     pub param_spans: Vec<Span>,
@@ -79,3 +71,15 @@ pub struct LargeAssignmentsLint {
     pub size: u64,
     pub limit: u64,
 }
+
+#[derive(SessionDiagnostic)]
+#[diag(monomorphize::unknown_partition_strategy)]
+pub struct UnknownPartitionStrategy;
+
+#[derive(SessionDiagnostic)]
+#[diag(monomorphize::symbol_already_defined)]
+pub struct SymbolAlreadyDefined {
+    #[primary_span]
+    pub span: Option<Span>,
+    pub symbol: String,
+}
index d88b7e0a813604a79ec7a18164530f30bfb367c9..3d9197c7549c7d1e1dc831730917792e7f5b79aa 100644 (file)
 
 use crate::collector::InliningMap;
 use crate::collector::{self, MonoItemCollectionMode};
-use crate::errors::{FatalError, SpanFatalError};
+use crate::errors::{SymbolAlreadyDefined, UnknownPartitionStrategy};
 
 pub struct PartitioningCx<'a, 'tcx> {
     tcx: TyCtxt<'tcx>,
@@ -151,8 +151,7 @@ fn get_partitioner<'tcx>(tcx: TyCtxt<'tcx>) -> Box<dyn Partitioner<'tcx>> {
     match strategy {
         "default" => Box::new(default::DefaultPartitioning),
         _ => {
-            let error_message = "unknown partitioning strategy".to_string();
-            tcx.sess.emit_fatal(FatalError { error_message: error_message.clone() });
+            tcx.sess.emit_fatal(UnknownPartitionStrategy);
         }
     }
 }
@@ -335,13 +334,7 @@ fn assert_symbols_are_distinct<'a, 'tcx, I>(tcx: TyCtxt<'tcx>, mono_items: I)
                 (span1, span2) => span1.or(span2),
             };
 
-            let error_message = format!("symbol `{}` is already defined", sym1);
-
-            if let Some(span) = span {
-                tcx.sess.emit_fatal(SpanFatalError { span, error_message: error_message.clone() });
-            } else {
-                tcx.sess.emit_fatal(FatalError { error_message: error_message.clone() });
-            }
+            tcx.sess.emit_fatal(SymbolAlreadyDefined { span, symbol: sym1.to_string() });
         }
     }
 }