Stop using String
for error codes.
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
This commit is contained in:
parent
0321de2778
commit
5d9dfbd08f
110 changed files with 1624 additions and 1572 deletions
|
@ -15,7 +15,7 @@ use rustc_data_structures::profiling::{SelfProfilerRef, VerboseTimingGuard};
|
|||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::emitter::Emitter;
|
||||
use rustc_errors::{translation::Translate, DiagCtxt, FatalError, Level};
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, Style};
|
||||
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage, ErrCode, Style};
|
||||
use rustc_fs_util::link_or_copy;
|
||||
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
|
||||
use rustc_incremental::{
|
||||
|
@ -1000,7 +1000,7 @@ type DiagnosticArgName<'source> = Cow<'source, str>;
|
|||
struct Diagnostic {
|
||||
msgs: Vec<(DiagnosticMessage, Style)>,
|
||||
args: FxHashMap<DiagnosticArgName<'static>, rustc_errors::DiagnosticArgValue<'static>>,
|
||||
code: Option<String>,
|
||||
code: Option<ErrCode>,
|
||||
lvl: Level,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_ast::{ast, attr, MetaItemKind, NestedMetaItem};
|
||||
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
|
||||
use rustc_errors::struct_span_code_err;
|
||||
use rustc_errors::{codes::*, struct_span_code_err};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::assert_module_sources::CguReuse;
|
|||
use crate::back::command::Command;
|
||||
use crate::fluent_generated as fluent;
|
||||
use rustc_errors::{
|
||||
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
|
||||
codes::*, DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
|
||||
IntoDiagnosticArg, Level,
|
||||
};
|
||||
use rustc_macros::Diagnostic;
|
||||
|
@ -612,7 +612,7 @@ pub struct UnknownAtomicOperation;
|
|||
|
||||
#[derive(Diagnostic)]
|
||||
pub enum InvalidMonomorphization<'tcx> {
|
||||
#[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = E0511)]
|
||||
BasicIntegerType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -620,7 +620,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = E0511)]
|
||||
BasicFloatType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -628,14 +628,14 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_float_to_int_unchecked, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_float_to_int_unchecked, code = E0511)]
|
||||
FloatToIntUnchecked {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = E0511)]
|
||||
FloatingPointVector {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -644,7 +644,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
in_ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = E0511)]
|
||||
FloatingPointType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -652,14 +652,14 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
in_ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = E0511)]
|
||||
UnrecognizedIntrinsic {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
name: Symbol,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_argument, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_argument, code = E0511)]
|
||||
SimdArgument {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -667,7 +667,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_input, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_input, code = E0511)]
|
||||
SimdInput {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -675,7 +675,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_first, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_first, code = E0511)]
|
||||
SimdFirst {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -683,7 +683,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_second, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_second, code = E0511)]
|
||||
SimdSecond {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -691,7 +691,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_third, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_third, code = E0511)]
|
||||
SimdThird {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -699,7 +699,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_return, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_return, code = E0511)]
|
||||
SimdReturn {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -707,7 +707,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_invalid_bitmask, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_invalid_bitmask, code = E0511)]
|
||||
InvalidBitmask {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -717,7 +717,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
expected_bytes: u64,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_length_input_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_length_input_type, code = E0511)]
|
||||
ReturnLengthInputType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -728,7 +728,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
out_len: u64,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_second_argument_length, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_second_argument_length, code = E0511)]
|
||||
SecondArgumentLength {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -739,7 +739,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
out_len: u64,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_third_argument_length, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_third_argument_length, code = E0511)]
|
||||
ThirdArgumentLength {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -750,7 +750,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
out_len: u64,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_integer_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_integer_type, code = E0511)]
|
||||
ReturnIntegerType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -759,7 +759,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
out_ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_shuffle, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_simd_shuffle, code = E0511)]
|
||||
SimdShuffle {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -767,7 +767,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_length, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_length, code = E0511)]
|
||||
ReturnLength {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -777,7 +777,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
out_len: u64,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_element, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_element, code = E0511)]
|
||||
ReturnElement {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -788,7 +788,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
out_ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_not_constant, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_not_constant, code = E0511)]
|
||||
ShuffleIndexNotConstant {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -796,7 +796,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
arg_idx: u64,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_shuffle_index_out_of_bounds, code = E0511)]
|
||||
ShuffleIndexOutOfBounds {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -805,7 +805,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
total_len: u128,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_inserted_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_inserted_type, code = E0511)]
|
||||
InsertedType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -815,7 +815,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
out_ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_return_type, code = E0511)]
|
||||
ReturnType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -825,7 +825,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ret_ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_return_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_return_type, code = E0511)]
|
||||
ExpectedReturnType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -834,7 +834,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ret_ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_mismatched_lengths, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_mismatched_lengths, code = E0511)]
|
||||
MismatchedLengths {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -843,7 +843,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
v_len: u64,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_mask_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_mask_type, code = E0511)]
|
||||
MaskType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -851,7 +851,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_vector_argument, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_vector_argument, code = E0511)]
|
||||
VectorArgument {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -860,7 +860,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
in_elem: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_cannot_return, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_cannot_return, code = E0511)]
|
||||
CannotReturn {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -870,7 +870,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
expected_bytes: u64,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_element_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_element_type, code = E0511)]
|
||||
ExpectedElementType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -882,7 +882,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
mutability: ExpectedPointerMutability,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_third_arg_element_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_third_arg_element_type, code = E0511)]
|
||||
ThirdArgElementType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -891,7 +891,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
third_arg: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol_of_size, code = E0511)]
|
||||
UnsupportedSymbolOfSize {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -903,7 +903,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ret_ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unsupported_symbol, code = E0511)]
|
||||
UnsupportedSymbol {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -914,7 +914,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ret_ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_cast_fat_pointer, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_cast_fat_pointer, code = E0511)]
|
||||
CastFatPointer {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -922,7 +922,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_pointer, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_pointer, code = E0511)]
|
||||
ExpectedPointer {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -930,7 +930,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_usize, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_usize, code = E0511)]
|
||||
ExpectedUsize {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -938,7 +938,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
ty: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unsupported_cast, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unsupported_cast, code = E0511)]
|
||||
UnsupportedCast {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -949,7 +949,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
out_elem: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unsupported_operation, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_unsupported_operation, code = E0511)]
|
||||
UnsupportedOperation {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
@ -958,7 +958,7 @@ pub enum InvalidMonomorphization<'tcx> {
|
|||
in_elem: Ty<'tcx>,
|
||||
},
|
||||
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_vector_element_type, code = "E0511")]
|
||||
#[diag(codegen_ssa_invalid_monomorphization_expected_vector_element_type, code = E0511)]
|
||||
ExpectedVectorElementType {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue