1use rustc_errors::codes::*;
4use rustc_macros::{Diagnostic, Subdiagnostic};
5use rustc_middle::ty::{GenericArg, Ty};
6use rustc_span::Span;
7
8#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NeedsDropOverflow<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NeedsDropOverflow { query_ty: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overflow while checking whether `{$query_ty}` requires drop")));
;
diag.arg("query_ty", __binding_0);
diag
}
}
}
}
};Diagnostic)]
9#[diag("overflow while checking whether `{$query_ty}` requires drop")]
10pub(crate) struct NeedsDropOverflow<'tcx> {
11 pub query_ty: Ty<'tcx>,
12}
13
14#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
GenericConstantTooComplex where G: rustc_errors::EmissionGuarantee
{
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
GenericConstantTooComplex {
span: __binding_0,
maybe_supported: __binding_1,
sub: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overly complex generic constant")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider moving this anonymous constant into a `const` function")));
;
diag.span(__binding_0);
if __binding_1 {
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this operation may be supported in the future")));
}
diag.subdiagnostic(__binding_2);
diag
}
}
}
}
};Diagnostic)]
15#[diag("overly complex generic constant")]
16#[help("consider moving this anonymous constant into a `const` function")]
17pub(crate) struct GenericConstantTooComplex {
18 #[primary_span]
19 pub span: Span,
20 #[note("this operation may be supported in the future")]
21 pub maybe_supported: bool,
22 #[subdiagnostic]
23 pub sub: GenericConstantTooComplexSub,
24}
25
26#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for GenericConstantTooComplexSub {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
GenericConstantTooComplexSub::BorrowNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("borrowing is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::AddressAndDerefNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("dereferencing or taking the address is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::ArrayNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("array construction is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::BlockNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("blocks are not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::NeverToAnyNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("coercing the `never` type is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::TupleNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("tuple construction is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::IndexNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("indexing is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::FieldNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("field access is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::ConstBlockNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("const blocks are not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::AdtNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("struct/enum construction is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::PointerNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("pointer casts are not allowed in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::YieldNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("coroutine control flow is not allowed in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::LoopNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("loops and loop control flow are not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::BoxNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("allocations are not allowed in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::BinaryNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unsupported binary operation in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::ByUseNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed(".use is not allowed in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::LogicalOpNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unsupported operation in generic constants, short-circuiting operations would imply control flow")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::AssignNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("assignment is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::ClosureAndReturnNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closures and function keywords are not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::ControlFlowNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("control flow is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::InlineAsmNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("assembly is not supported in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
GenericConstantTooComplexSub::OperationNotSupported(__binding_0)
=> {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unsupported operation in generic constants")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
27pub(crate) enum GenericConstantTooComplexSub {
28 #[label("borrowing is not supported in generic constants")]
29 BorrowNotSupported(#[primary_span] Span),
30 #[label("dereferencing or taking the address is not supported in generic constants")]
31 AddressAndDerefNotSupported(#[primary_span] Span),
32 #[label("array construction is not supported in generic constants")]
33 ArrayNotSupported(#[primary_span] Span),
34 #[label("blocks are not supported in generic constants")]
35 BlockNotSupported(#[primary_span] Span),
36 #[label("coercing the `never` type is not supported in generic constants")]
37 NeverToAnyNotSupported(#[primary_span] Span),
38 #[label("tuple construction is not supported in generic constants")]
39 TupleNotSupported(#[primary_span] Span),
40 #[label("indexing is not supported in generic constants")]
41 IndexNotSupported(#[primary_span] Span),
42 #[label("field access is not supported in generic constants")]
43 FieldNotSupported(#[primary_span] Span),
44 #[label("const blocks are not supported in generic constants")]
45 ConstBlockNotSupported(#[primary_span] Span),
46 #[label("struct/enum construction is not supported in generic constants")]
47 AdtNotSupported(#[primary_span] Span),
48 #[label("pointer casts are not allowed in generic constants")]
49 PointerNotSupported(#[primary_span] Span),
50 #[label("coroutine control flow is not allowed in generic constants")]
51 YieldNotSupported(#[primary_span] Span),
52 #[label("loops and loop control flow are not supported in generic constants")]
53 LoopNotSupported(#[primary_span] Span),
54 #[label("allocations are not allowed in generic constants")]
55 BoxNotSupported(#[primary_span] Span),
56 #[label("unsupported binary operation in generic constants")]
57 BinaryNotSupported(#[primary_span] Span),
58 #[label(".use is not allowed in generic constants")]
59 ByUseNotSupported(#[primary_span] Span),
60 #[label(
61 "unsupported operation in generic constants, short-circuiting operations would imply control flow"
62 )]
63 LogicalOpNotSupported(#[primary_span] Span),
64 #[label("assignment is not supported in generic constants")]
65 AssignNotSupported(#[primary_span] Span),
66 #[label("closures and function keywords are not supported in generic constants")]
67 ClosureAndReturnNotSupported(#[primary_span] Span),
68 #[label("control flow is not supported in generic constants")]
69 ControlFlowNotSupported(#[primary_span] Span),
70 #[label("assembly is not supported in generic constants")]
71 InlineAsmNotSupported(#[primary_span] Span),
72 #[label("unsupported operation in generic constants")]
73 OperationNotSupported(#[primary_span] Span),
74}
75
76#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnexpectedFnPtrAssociatedItem where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
UnexpectedFnPtrAssociatedItem { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("`FnPtr` trait with unexpected associated item")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
77#[diag("`FnPtr` trait with unexpected associated item")]
78pub(crate) struct UnexpectedFnPtrAssociatedItem {
79 #[primary_span]
80 pub span: Span,
81}
82
83#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NonPrimitiveSimdType<'tcx> where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NonPrimitiveSimdType { ty: __binding_0, e_ty: __binding_1 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("monomorphising SIMD type `{$ty}` with a non-primitive-scalar (integer/float/pointer) element type `{$e_ty}`")));
;
diag.arg("ty", __binding_0);
diag.arg("e_ty", __binding_1);
diag
}
}
}
}
};Diagnostic)]
84#[diag(
85 "monomorphising SIMD type `{$ty}` with a non-primitive-scalar (integer/float/pointer) element type `{$e_ty}`"
86)]
87pub(crate) struct NonPrimitiveSimdType<'tcx> {
88 pub ty: Ty<'tcx>,
89 pub e_ty: Ty<'tcx>,
90}
91
92#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
DuplicateArg<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
DuplicateArg {
arg: __binding_0,
span: __binding_1,
opaque_span: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("non-defining opaque type use in defining scope")));
;
diag.arg("arg", __binding_0);
diag.span(__binding_1);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("generic argument `{$arg}` used twice")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for this opaque type")));
diag
}
}
}
}
};Diagnostic)]
93#[diag("non-defining opaque type use in defining scope")]
94pub(crate) struct DuplicateArg<'tcx> {
95 pub arg: GenericArg<'tcx>,
96 #[primary_span]
97 #[label("generic argument `{$arg}` used twice")]
98 pub span: Span,
99 #[note("for this opaque type")]
100 pub opaque_span: Span,
101}
102
103#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
NotParam<'tcx> where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
NotParam {
arg: __binding_0,
span: __binding_1,
opaque_span: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("non-defining opaque type use in defining scope")));
diag.code(E0792);
;
diag.arg("arg", __binding_0);
diag.span(__binding_1);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("argument `{$arg}` is not a generic parameter")));
diag.span_note(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for this opaque type")));
diag
}
}
}
}
};Diagnostic)]
104#[diag("non-defining opaque type use in defining scope", code = E0792)]
105pub(crate) struct NotParam<'tcx> {
106 pub arg: GenericArg<'tcx>,
107 #[primary_span]
108 #[label("argument `{$arg}` is not a generic parameter")]
109 pub span: Span,
110 #[note("for this opaque type")]
111 pub opaque_span: Span,
112}