rust/compiler/rustc_ty_utils/src/errors.rs
Nicholas Nethercote 5d9dfbd08f 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.
2024-01-29 07:41:41 +11:00

126 lines
3.7 KiB
Rust

//! Errors emitted by ty_utils
use rustc_errors::codes::*;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::{GenericArg, Ty};
use rustc_span::Span;
#[derive(Diagnostic)]
#[diag(ty_utils_needs_drop_overflow)]
pub struct NeedsDropOverflow<'tcx> {
pub query_ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(ty_utils_generic_constant_too_complex)]
#[help]
pub struct GenericConstantTooComplex {
#[primary_span]
pub span: Span,
#[note(ty_utils_maybe_supported)]
pub maybe_supported: Option<()>,
#[subdiagnostic]
pub sub: GenericConstantTooComplexSub,
}
#[derive(Subdiagnostic)]
pub enum GenericConstantTooComplexSub {
#[label(ty_utils_borrow_not_supported)]
BorrowNotSupported(#[primary_span] Span),
#[label(ty_utils_address_and_deref_not_supported)]
AddressAndDerefNotSupported(#[primary_span] Span),
#[label(ty_utils_array_not_supported)]
ArrayNotSupported(#[primary_span] Span),
#[label(ty_utils_block_not_supported)]
BlockNotSupported(#[primary_span] Span),
#[label(ty_utils_never_to_any_not_supported)]
NeverToAnyNotSupported(#[primary_span] Span),
#[label(ty_utils_tuple_not_supported)]
TupleNotSupported(#[primary_span] Span),
#[label(ty_utils_index_not_supported)]
IndexNotSupported(#[primary_span] Span),
#[label(ty_utils_field_not_supported)]
FieldNotSupported(#[primary_span] Span),
#[label(ty_utils_const_block_not_supported)]
ConstBlockNotSupported(#[primary_span] Span),
#[label(ty_utils_adt_not_supported)]
AdtNotSupported(#[primary_span] Span),
#[label(ty_utils_pointer_not_supported)]
PointerNotSupported(#[primary_span] Span),
#[label(ty_utils_yield_not_supported)]
YieldNotSupported(#[primary_span] Span),
#[label(ty_utils_loop_not_supported)]
LoopNotSupported(#[primary_span] Span),
#[label(ty_utils_box_not_supported)]
BoxNotSupported(#[primary_span] Span),
#[label(ty_utils_binary_not_supported)]
BinaryNotSupported(#[primary_span] Span),
#[label(ty_utils_logical_op_not_supported)]
LogicalOpNotSupported(#[primary_span] Span),
#[label(ty_utils_assign_not_supported)]
AssignNotSupported(#[primary_span] Span),
#[label(ty_utils_closure_and_return_not_supported)]
ClosureAndReturnNotSupported(#[primary_span] Span),
#[label(ty_utils_control_flow_not_supported)]
ControlFlowNotSupported(#[primary_span] Span),
#[label(ty_utils_inline_asm_not_supported)]
InlineAsmNotSupported(#[primary_span] Span),
#[label(ty_utils_operation_not_supported)]
OperationNotSupported(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag(ty_utils_unexpected_fnptr_associated_item)]
pub struct UnexpectedFnPtrAssociatedItem {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ty_utils_zero_length_simd_type)]
pub struct ZeroLengthSimdType<'tcx> {
pub ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(ty_utils_multiple_array_fields_simd_type)]
pub struct MultipleArrayFieldsSimdType<'tcx> {
pub ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(ty_utils_oversized_simd_type)]
pub struct OversizedSimdType<'tcx> {
pub ty: Ty<'tcx>,
pub max_lanes: u64,
}
#[derive(Diagnostic)]
#[diag(ty_utils_non_primitive_simd_type)]
pub struct NonPrimitiveSimdType<'tcx> {
pub ty: Ty<'tcx>,
pub e_ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(ty_utils_impl_trait_duplicate_arg)]
pub struct DuplicateArg<'tcx> {
pub arg: GenericArg<'tcx>,
#[primary_span]
#[label]
pub span: Span,
#[note]
pub opaque_span: Span,
}
#[derive(Diagnostic)]
#[diag(ty_utils_impl_trait_not_param, code = E0792)]
pub struct NotParam<'tcx> {
pub arg: GenericArg<'tcx>,
#[primary_span]
#[label]
pub span: Span,
#[note]
pub opaque_span: Span,
}