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::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("unsupported binary operation in generic constants")]
55 BinaryNotSupported(#[primary_span] Span),
56 #[label(".use is not allowed in generic constants")]
57 ByUseNotSupported(#[primary_span] Span),
58 #[label(
59 "unsupported operation in generic constants, short-circuiting operations would imply control flow"
60 )]
61 LogicalOpNotSupported(#[primary_span] Span),
62 #[label("assignment is not supported in generic constants")]
63 AssignNotSupported(#[primary_span] Span),
64 #[label("closures and function keywords are not supported in generic constants")]
65 ClosureAndReturnNotSupported(#[primary_span] Span),
66 #[label("control flow is not supported in generic constants")]
67 ControlFlowNotSupported(#[primary_span] Span),
68 #[label("assembly is not supported in generic constants")]
69 InlineAsmNotSupported(#[primary_span] Span),
70 #[label("unsupported operation in generic constants")]
71 OperationNotSupported(#[primary_span] Span),
72}
73
74#[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)]
75#[diag("`FnPtr` trait with unexpected associated item")]
76pub(crate) struct UnexpectedFnPtrAssociatedItem {
77 #[primary_span]
78 pub span: Span,
79}
80
81#[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)]
82#[diag(
83 "monomorphising SIMD type `{$ty}` with a non-primitive-scalar (integer/float/pointer) element type `{$e_ty}`"
84)]
85pub(crate) struct NonPrimitiveSimdType<'tcx> {
86 pub ty: Ty<'tcx>,
87 pub e_ty: Ty<'tcx>,
88}
89
90#[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)]
91#[diag("non-defining opaque type use in defining scope")]
92pub(crate) struct DuplicateArg<'tcx> {
93 pub arg: GenericArg<'tcx>,
94 #[primary_span]
95 #[label("generic argument `{$arg}` used twice")]
96 pub span: Span,
97 #[note("for this opaque type")]
98 pub opaque_span: Span,
99}
100
101#[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)]
102#[diag("non-defining opaque type use in defining scope", code = E0792)]
103pub(crate) struct NotParam<'tcx> {
104 pub arg: GenericArg<'tcx>,
105 #[primary_span]
106 #[label("argument `{$arg}` is not a generic parameter")]
107 pub span: Span,
108 #[note("for this opaque type")]
109 pub opaque_span: Span,
110}