Skip to content

Commit d41112a

Browse files
committed
UPDATE - migrate constant.rs to new diagnostics infrastructure
1 parent 78796ba commit d41112a

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,3 +575,17 @@ pub struct MetadataObjectFileWrite {
575575
pub struct InvalidWindowsSubsystem {
576576
pub subsystem: Symbol,
577577
}
578+
579+
#[derive(Diagnostic)]
580+
#[diag(codegen_ssa_erroneous_constant)]
581+
pub struct ErroneousConstant {
582+
#[primary_span]
583+
pub span: Span,
584+
}
585+
586+
#[derive(Diagnostic)]
587+
#[diag(codegen_ssa_shuffle_indices_evaluation)]
588+
pub struct ShuffleIndicesEvaluation {
589+
#[primary_span]
590+
pub span: Span,
591+
}

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::errors;
12
use crate::mir::operand::OperandRef;
23
use crate::traits::*;
34
use rustc_middle::mir;
@@ -44,7 +45,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4445
self.cx.tcx().const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).map_err(|err| {
4546
match err {
4647
ErrorHandled::Reported(_) => {
47-
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
48+
self.cx.tcx().sess.emit_err(errors::ErroneousConstant { span: constant.span });
4849
}
4950
ErrorHandled::TooGeneric => {
5051
span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err);
@@ -87,7 +88,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
8788
(llval, c.ty())
8889
})
8990
.unwrap_or_else(|_| {
90-
bx.tcx().sess.span_err(span, "could not evaluate shuffle_indices at compile time");
91+
bx.tcx().sess.emit_err(errors::ShuffleIndicesEvaluation { span });
9192
// We've errored, so we don't have to produce working code.
9293
let ty = self.monomorphize(ty);
9394
let llty = bx.backend_type(bx.layout_of(ty));

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,7 @@ codegen_ssa_multiple_main_functions = entry symbol `main` declared multiple time
201201
codegen_ssa_metadata_object_file_write = error writing metadata object file: {$error}
202202
203203
codegen_ssa_invalid_windows_subsystem = invalid windows subsystem `{$subsystem}`, only `windows` and `console` are allowed
204+
205+
codegen_ssa_erroneous_constant = erroneous constant encountered
206+
207+
codegen_ssa_shuffle_indices_evaluation = could not evaluate shuffle_indices at compile time

0 commit comments

Comments
 (0)