1//! Errors emitted by ty_utils
23use rustc_errors::codes::*;
4use rustc_macros::{Diagnostic, Subdiagnostic};
5use rustc_middle::ty::{GenericArg, Ty};
6use rustc_span::Span;
78#[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> {
11pub query_ty: Ty<'tcx>,
12}
1314#[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]
19pub span: Span,
20#[note("this operation may be supported in the future")]
21pub maybe_supported: bool,
22#[subdiagnostic]
23pub sub: GenericConstantTooComplexSub,
24}
2526#[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)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("borrowing is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::AddressAndDerefNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("dereferencing or taking the address is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::ArrayNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("array construction is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::BlockNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("blocks are not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::NeverToAnyNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("coercing the `never` type is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::TupleNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("tuple construction is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::IndexNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("indexing is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::FieldNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("field access is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::ConstBlockNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("const blocks are not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::AdtNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("struct/enum construction is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::PointerNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("pointer casts are not allowed in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::YieldNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("coroutine control flow is not allowed in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::LoopNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("loops and loop control flow are not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::BinaryNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unsupported binary operation in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::ByUseNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed(".use is not allowed in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::LogicalOpNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unsupported operation in generic constants, short-circuiting operations would imply control flow")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::AssignNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("assignment is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::ClosureAndReturnNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("closures and function keywords are not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::ControlFlowNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("control flow is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::InlineAsmNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("assembly is not supported in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
GenericConstantTooComplexSub::OperationNotSupported(__binding_0)
=> {
let mut sub_args = rustc_errors::DiagArgMap::default();
let __message =
rustc_errors::format_diag_message(&rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unsupported operation in generic constants")),
&sub_args);
diag.span_label(__binding_0, __message);
}
}
}
}
};Subdiagnostic)]
27pub(crate) enum GenericConstantTooComplexSub {
28#[label("borrowing is not supported in generic constants")]
29BorrowNotSupported(#[primary_span] Span),
30#[label("dereferencing or taking the address is not supported in generic constants")]
31AddressAndDerefNotSupported(#[primary_span] Span),
32#[label("array construction is not supported in generic constants")]
33ArrayNotSupported(#[primary_span] Span),
34#[label("blocks are not supported in generic constants")]
35BlockNotSupported(#[primary_span] Span),
36#[label("coercing the `never` type is not supported in generic constants")]
37NeverToAnyNotSupported(#[primary_span] Span),
38#[label("tuple construction is not supported in generic constants")]
39TupleNotSupported(#[primary_span] Span),
40#[label("indexing is not supported in generic constants")]
41IndexNotSupported(#[primary_span] Span),
42#[label("field access is not supported in generic constants")]
43FieldNotSupported(#[primary_span] Span),
44#[label("const blocks are not supported in generic constants")]
45ConstBlockNotSupported(#[primary_span] Span),
46#[label("struct/enum construction is not supported in generic constants")]
47AdtNotSupported(#[primary_span] Span),
48#[label("pointer casts are not allowed in generic constants")]
49PointerNotSupported(#[primary_span] Span),
50#[label("coroutine control flow is not allowed in generic constants")]
51YieldNotSupported(#[primary_span] Span),
52#[label("loops and loop control flow are not supported in generic constants")]
53LoopNotSupported(#[primary_span] Span),
54#[label("unsupported binary operation in generic constants")]
55BinaryNotSupported(#[primary_span] Span),
56#[label(".use is not allowed in generic constants")]
57ByUseNotSupported(#[primary_span] Span),
58#[label(
59"unsupported operation in generic constants, short-circuiting operations would imply control flow"
60)]
61LogicalOpNotSupported(#[primary_span] Span),
62#[label("assignment is not supported in generic constants")]
63AssignNotSupported(#[primary_span] Span),
64#[label("closures and function keywords are not supported in generic constants")]
65ClosureAndReturnNotSupported(#[primary_span] Span),
66#[label("control flow is not supported in generic constants")]
67ControlFlowNotSupported(#[primary_span] Span),
68#[label("assembly is not supported in generic constants")]
69InlineAsmNotSupported(#[primary_span] Span),
70#[label("unsupported operation in generic constants")]
71OperationNotSupported(#[primary_span] Span),
72}
7374#[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]
78pub span: Span,
79}
8081#[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> {
86pub ty: Ty<'tcx>,
87pub e_ty: Ty<'tcx>,
88}
8990#[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> {
93pub arg: GenericArg<'tcx>,
94#[primary_span]
95 #[label("generic argument `{$arg}` used twice")]
96pub span: Span,
97#[note("for this opaque type")]
98pub opaque_span: Span,
99}
100101#[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> {
104pub arg: GenericArg<'tcx>,
105#[primary_span]
106 #[label("argument `{$arg}` is not a generic parameter")]
107pub span: Span,
108#[note("for this opaque type")]
109pub opaque_span: Span,
110}