Convert to inline diagnostics in rustc_ty_utils

This commit is contained in:
Jonathan Brouwer 2026-02-03 21:31:28 +01:00
parent 55407b8cdb
commit 590fa1e6cb
No known key found for this signature in database
GPG key ID: 13619B051B673C52
7 changed files with 38 additions and 102 deletions

View file

@ -3817,7 +3817,6 @@ dependencies = [
"rustc_span",
"rustc_target",
"rustc_trait_selection",
"rustc_ty_utils",
"serde_json",
"shlex",
"tracing",
@ -4809,7 +4808,6 @@ dependencies = [
"rustc_abi",
"rustc_data_structures",
"rustc_errors",
"rustc_fluent_macro",
"rustc_hashes",
"rustc_hir",
"rustc_index",

View file

@ -49,7 +49,6 @@ rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_ty_utils = { path = "../rustc_ty_utils" }
serde_json = "1.0.59"
shlex = "1.0"
tracing = { version = "0.1.35" }

View file

@ -143,7 +143,6 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
rustc_resolve::DEFAULT_LOCALE_RESOURCE,
rustc_session::DEFAULT_LOCALE_RESOURCE,
rustc_trait_selection::DEFAULT_LOCALE_RESOURCE,
rustc_ty_utils::DEFAULT_LOCALE_RESOURCE,
// tidy-alphabetical-end
];

View file

@ -9,7 +9,6 @@ itertools = "0.12"
rustc_abi = { path = "../rustc_abi" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
rustc_hashes = { path = "../rustc_hashes" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }

View file

@ -1,61 +0,0 @@
ty_utils_address_and_deref_not_supported = dereferencing or taking the address is not supported in generic constants
ty_utils_adt_not_supported = struct/enum construction is not supported in generic constants
ty_utils_array_not_supported = array construction is not supported in generic constants
ty_utils_assign_not_supported = assignment is not supported in generic constants
ty_utils_binary_not_supported = unsupported binary operation in generic constants
ty_utils_block_not_supported = blocks are not supported in generic constants
ty_utils_borrow_not_supported = borrowing is not supported in generic constants
ty_utils_box_not_supported = allocations are not allowed in generic constants
ty_utils_by_use_not_supported = .use is not allowed in generic constants
ty_utils_closure_and_return_not_supported = closures and function keywords are not supported in generic constants
ty_utils_const_block_not_supported = const blocks are not supported in generic constants
ty_utils_control_flow_not_supported = control flow is not supported in generic constants
ty_utils_field_not_supported = field access is not supported in generic constants
ty_utils_generic_constant_too_complex = overly complex generic constant
.help = consider moving this anonymous constant into a `const` function
.maybe_supported = this operation may be supported in the future
ty_utils_impl_trait_duplicate_arg = non-defining opaque type use in defining scope
.label = generic argument `{$arg}` used twice
.note = for this opaque type
ty_utils_impl_trait_not_param = non-defining opaque type use in defining scope
.label = argument `{$arg}` is not a generic parameter
.note = for this opaque type
ty_utils_index_not_supported = indexing is not supported in generic constants
ty_utils_inline_asm_not_supported = assembly is not supported in generic constants
ty_utils_logical_op_not_supported = unsupported operation in generic constants, short-circuiting operations would imply control flow
ty_utils_loop_not_supported = loops and loop control flow are not supported in generic constants
ty_utils_needs_drop_overflow = overflow while checking whether `{$query_ty}` requires drop
ty_utils_never_to_any_not_supported = coercing the `never` type is not supported in generic constants
ty_utils_non_primitive_simd_type = monomorphising SIMD type `{$ty}` with a non-primitive-scalar (integer/float/pointer) element type `{$e_ty}`
ty_utils_operation_not_supported = unsupported operation in generic constants
ty_utils_pointer_not_supported = pointer casts are not allowed in generic constants
ty_utils_tuple_not_supported = tuple construction is not supported in generic constants
ty_utils_unexpected_fnptr_associated_item = `FnPtr` trait with unexpected associated item
ty_utils_yield_not_supported = coroutine control flow is not allowed in generic constants

View file

@ -6,18 +6,18 @@ use rustc_middle::ty::{GenericArg, Ty};
use rustc_span::Span;
#[derive(Diagnostic)]
#[diag(ty_utils_needs_drop_overflow)]
#[diag("overflow while checking whether `{$query_ty}` requires drop")]
pub(crate) struct NeedsDropOverflow<'tcx> {
pub query_ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(ty_utils_generic_constant_too_complex)]
#[help]
#[diag("overly complex generic constant")]
#[help("consider moving this anonymous constant into a `const` function")]
pub(crate) struct GenericConstantTooComplex {
#[primary_span]
pub span: Span,
#[note(ty_utils_maybe_supported)]
#[note("this operation may be supported in the future")]
pub maybe_supported: bool,
#[subdiagnostic]
pub sub: GenericConstantTooComplexSub,
@ -25,84 +25,88 @@ pub(crate) struct GenericConstantTooComplex {
#[derive(Subdiagnostic)]
pub(crate) enum GenericConstantTooComplexSub {
#[label(ty_utils_borrow_not_supported)]
#[label("borrowing is not supported in generic constants")]
BorrowNotSupported(#[primary_span] Span),
#[label(ty_utils_address_and_deref_not_supported)]
#[label("dereferencing or taking the address is not supported in generic constants")]
AddressAndDerefNotSupported(#[primary_span] Span),
#[label(ty_utils_array_not_supported)]
#[label("array construction is not supported in generic constants")]
ArrayNotSupported(#[primary_span] Span),
#[label(ty_utils_block_not_supported)]
#[label("blocks are not supported in generic constants")]
BlockNotSupported(#[primary_span] Span),
#[label(ty_utils_never_to_any_not_supported)]
#[label("coercing the `never` type is not supported in generic constants")]
NeverToAnyNotSupported(#[primary_span] Span),
#[label(ty_utils_tuple_not_supported)]
#[label("tuple construction is not supported in generic constants")]
TupleNotSupported(#[primary_span] Span),
#[label(ty_utils_index_not_supported)]
#[label("indexing is not supported in generic constants")]
IndexNotSupported(#[primary_span] Span),
#[label(ty_utils_field_not_supported)]
#[label("field access is not supported in generic constants")]
FieldNotSupported(#[primary_span] Span),
#[label(ty_utils_const_block_not_supported)]
#[label("const blocks are not supported in generic constants")]
ConstBlockNotSupported(#[primary_span] Span),
#[label(ty_utils_adt_not_supported)]
#[label("struct/enum construction is not supported in generic constants")]
AdtNotSupported(#[primary_span] Span),
#[label(ty_utils_pointer_not_supported)]
#[label("pointer casts are not allowed in generic constants")]
PointerNotSupported(#[primary_span] Span),
#[label(ty_utils_yield_not_supported)]
#[label("coroutine control flow is not allowed in generic constants")]
YieldNotSupported(#[primary_span] Span),
#[label(ty_utils_loop_not_supported)]
#[label("loops and loop control flow are not supported in generic constants")]
LoopNotSupported(#[primary_span] Span),
#[label(ty_utils_box_not_supported)]
#[label("allocations are not allowed in generic constants")]
BoxNotSupported(#[primary_span] Span),
#[label(ty_utils_binary_not_supported)]
#[label("unsupported binary operation in generic constants")]
BinaryNotSupported(#[primary_span] Span),
#[label(ty_utils_by_use_not_supported)]
#[label(".use is not allowed in generic constants")]
ByUseNotSupported(#[primary_span] Span),
#[label(ty_utils_logical_op_not_supported)]
#[label(
"unsupported operation in generic constants, short-circuiting operations would imply control flow"
)]
LogicalOpNotSupported(#[primary_span] Span),
#[label(ty_utils_assign_not_supported)]
#[label("assignment is not supported in generic constants")]
AssignNotSupported(#[primary_span] Span),
#[label(ty_utils_closure_and_return_not_supported)]
#[label("closures and function keywords are not supported in generic constants")]
ClosureAndReturnNotSupported(#[primary_span] Span),
#[label(ty_utils_control_flow_not_supported)]
#[label("control flow is not supported in generic constants")]
ControlFlowNotSupported(#[primary_span] Span),
#[label(ty_utils_inline_asm_not_supported)]
#[label("assembly is not supported in generic constants")]
InlineAsmNotSupported(#[primary_span] Span),
#[label(ty_utils_operation_not_supported)]
#[label("unsupported operation in generic constants")]
OperationNotSupported(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag(ty_utils_unexpected_fnptr_associated_item)]
#[diag("`FnPtr` trait with unexpected associated item")]
pub(crate) struct UnexpectedFnPtrAssociatedItem {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(ty_utils_non_primitive_simd_type)]
#[diag(
"monomorphising SIMD type `{$ty}` with a non-primitive-scalar (integer/float/pointer) element type `{$e_ty}`"
)]
pub(crate) struct NonPrimitiveSimdType<'tcx> {
pub ty: Ty<'tcx>,
pub e_ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(ty_utils_impl_trait_duplicate_arg)]
#[diag("non-defining opaque type use in defining scope")]
pub(crate) struct DuplicateArg<'tcx> {
pub arg: GenericArg<'tcx>,
#[primary_span]
#[label]
#[label("generic argument `{$arg}` used twice")]
pub span: Span,
#[note]
#[note("for this opaque type")]
pub opaque_span: Span,
}
#[derive(Diagnostic)]
#[diag(ty_utils_impl_trait_not_param, code = E0792)]
#[diag("non-defining opaque type use in defining scope", code = E0792)]
pub(crate) struct NotParam<'tcx> {
pub arg: GenericArg<'tcx>,
#[primary_span]
#[label]
#[label("argument `{$arg}` is not a generic parameter")]
pub span: Span,
#[note]
#[note("for this opaque type")]
pub opaque_span: Span,
}

View file

@ -31,8 +31,6 @@ pub mod sig_types;
mod structural_match;
mod ty;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
pub fn provide(providers: &mut Providers) {
abi::provide(providers);
assoc::provide(providers);