Skip to content

Commit 40f4473

Browse files
committed
replace some usages of [Span]FatalError with error-specific types
1 parent 137f20c commit 40f4473

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

compiler/rustc_error_messages/locales/en-US/monomorphize.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ monomorphize_consider_type_length_limit =
1111
1212
monomorphize_fatal_error = {$error_message}
1313
14+
monomorphize_unknown_partition_strategy = unknown partitioning strategy
15+
16+
monomorphize_symbol_already_defined = symbol `{$symbol}` is already defined
17+
1418
monomorphize_unused_generic_params = item has unused generic parameters
1519
1620
monomorphize_large_assignments =

compiler/rustc_monomorphize/src/errors.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ pub struct FatalError {
3939
pub error_message: String,
4040
}
4141

42-
#[derive(SessionDiagnostic)]
43-
#[diag(monomorphize::fatal_error)]
44-
pub struct SpanFatalError {
45-
#[primary_span]
46-
pub span: Span,
47-
pub error_message: String,
48-
}
49-
5042
pub struct UnusedGenericParams {
5143
pub span: Span,
5244
pub param_spans: Vec<Span>,
@@ -79,3 +71,15 @@ pub struct LargeAssignmentsLint {
7971
pub size: u64,
8072
pub limit: u64,
8173
}
74+
75+
#[derive(SessionDiagnostic)]
76+
#[diag(monomorphize::unknown_partition_strategy)]
77+
pub struct UnknownPartitionStrategy;
78+
79+
#[derive(SessionDiagnostic)]
80+
#[diag(monomorphize::symbol_already_defined)]
81+
pub struct SymbolAlreadyDefined {
82+
#[primary_span]
83+
pub span: Option<Span>,
84+
pub symbol: String,
85+
}

compiler/rustc_monomorphize/src/partitioning/mod.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ use rustc_span::symbol::Symbol;
108108

109109
use crate::collector::InliningMap;
110110
use crate::collector::{self, MonoItemCollectionMode};
111-
use crate::errors::{FatalError, SpanFatalError};
111+
use crate::errors::{SymbolAlreadyDefined, UnknownPartitionStrategy};
112112

113113
pub struct PartitioningCx<'a, 'tcx> {
114114
tcx: TyCtxt<'tcx>,
@@ -151,8 +151,7 @@ fn get_partitioner<'tcx>(tcx: TyCtxt<'tcx>) -> Box<dyn Partitioner<'tcx>> {
151151
match strategy {
152152
"default" => Box::new(default::DefaultPartitioning),
153153
_ => {
154-
let error_message = "unknown partitioning strategy".to_string();
155-
tcx.sess.emit_fatal(FatalError { error_message: error_message.clone() });
154+
tcx.sess.emit_fatal(UnknownPartitionStrategy);
156155
}
157156
}
158157
}
@@ -335,13 +334,7 @@ where
335334
(span1, span2) => span1.or(span2),
336335
};
337336

338-
let error_message = format!("symbol `{}` is already defined", sym1);
339-
340-
if let Some(span) = span {
341-
tcx.sess.emit_fatal(SpanFatalError { span, error_message: error_message.clone() });
342-
} else {
343-
tcx.sess.emit_fatal(FatalError { error_message: error_message.clone() });
344-
}
337+
tcx.sess.emit_fatal(SymbolAlreadyDefined { span, symbol: sym1.to_string() });
345338
}
346339
}
347340
}

0 commit comments

Comments
 (0)