1use std::path::Path;
2use std::{fmt, io};
3
4use rustc_errors::codes::*;
5use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage};
6use rustc_macros::{Diagnostic, Subdiagnostic};
7use rustc_span::{Span, Symbol};
8
9use crate::ty::{Instance, Ty};
10
11#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
DropCheckOverflow<'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 {
DropCheckOverflow {
span: __binding_0, ty: __binding_1, overflow_ty: __binding_2
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overflow while adding drop-check rules for `{$ty}`")));
diag.code(E0320);
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("overflowed on `{$overflow_ty}`")));
;
diag.arg("ty", __binding_1);
diag.arg("overflow_ty", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
12#[diag("overflow while adding drop-check rules for `{$ty}`", code = E0320)]
13#[note("overflowed on `{$overflow_ty}`")]
14pub(crate) struct DropCheckOverflow<'tcx> {
15 #[primary_span]
16 pub span: Span,
17 pub ty: Ty<'tcx>,
18 pub overflow_ty: Ty<'tcx>,
19}
20
21#[derive(const _: () =
{
impl<'_sess, 'a, G> rustc_errors::Diagnostic<'_sess, G> for
FailedWritingFile<'a> 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 {
FailedWritingFile { path: __binding_0, error: __binding_1 }
=> {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("failed to write file {$path}: {$error}\"")));
;
diag.arg("path", __binding_0);
diag.arg("error", __binding_1);
diag
}
}
}
}
};Diagnostic)]
22#[diag("failed to write file {$path}: {$error}\"")]
23pub(crate) struct FailedWritingFile<'a> {
24 pub path: &'a Path,
25 pub error: io::Error,
26}
27
28#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
OpaqueHiddenTypeMismatch<'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 {
OpaqueHiddenTypeMismatch {
self_ty: __binding_0,
other_ty: __binding_1,
other_span: __binding_2,
sub: __binding_3 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("concrete type differs from previous defining opaque type use")));
;
diag.arg("self_ty", __binding_0);
diag.arg("other_ty", __binding_1);
diag.span(__binding_2);
diag.span_label(__binding_2,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("expected `{$self_ty}`, got `{$other_ty}`")));
diag.subdiagnostic(__binding_3);
diag
}
}
}
}
};Diagnostic)]
29#[diag("concrete type differs from previous defining opaque type use")]
30pub(crate) struct OpaqueHiddenTypeMismatch<'tcx> {
31 pub self_ty: Ty<'tcx>,
32 pub other_ty: Ty<'tcx>,
33 #[primary_span]
34 #[label("expected `{$self_ty}`, got `{$other_ty}`")]
35 pub other_span: Span,
36 #[subdiagnostic]
37 pub sub: TypeMismatchReason,
38}
39
40#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
UnsupportedUnion 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 {
UnsupportedUnion { ty_name: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("we don't support unions yet: '{$ty_name}'")));
;
diag.arg("ty_name", __binding_0);
diag
}
}
}
}
};Diagnostic)]
41#[diag("we don't support unions yet: '{$ty_name}'")]
42pub struct UnsupportedUnion {
43 pub ty_name: String,
44}
45
46#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
AutodiffUnsafeInnerConstRef<'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 {
AutodiffUnsafeInnerConstRef {
span: __binding_0, ty: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reading from a `Duplicated` const {$ty} is unsafe")));
;
diag.arg("ty", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
48#[diag("reading from a `Duplicated` const {$ty} is unsafe")]
49pub struct AutodiffUnsafeInnerConstRef<'tcx> {
50 #[primary_span]
51 pub span: Span,
52 pub ty: Ty<'tcx>,
53}
54
55#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for TypeMismatchReason {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
TypeMismatchReason::ConflictType { span: __binding_0 } => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("this expression supplies two conflicting concrete types for the same opaque type")));
diag.span_label(__binding_0, __message);
diag.restore_args();
}
TypeMismatchReason::PreviousUse { span: __binding_0 } => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("previous use here")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
56pub enum TypeMismatchReason {
57 #[label("this expression supplies two conflicting concrete types for the same opaque type")]
58 ConflictType {
59 #[primary_span]
60 span: Span,
61 },
62 #[note("previous use here")]
63 PreviousUse {
64 #[primary_span]
65 span: Span,
66 },
67}
68
69#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
RecursionLimitReached<'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 {
RecursionLimitReached {
span: __binding_0,
ty: __binding_1,
suggested_limit: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reached the recursion limit finding the struct tail for `{$ty}`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]`")));
;
diag.arg("ty", __binding_1);
diag.arg("suggested_limit", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
70#[diag("reached the recursion limit finding the struct tail for `{$ty}`")]
71#[help(
72 "consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]`"
73)]
74pub(crate) struct RecursionLimitReached<'tcx> {
75 #[primary_span]
76 pub span: Span,
77 pub ty: Ty<'tcx>,
78 pub suggested_limit: rustc_hir::limit::Limit,
79}
80
81#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ConstEvalNonIntError 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 {
ConstEvalNonIntError { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constant evaluation of enum discriminant resulted in non-integer")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
82#[diag("constant evaluation of enum discriminant resulted in non-integer")]
83pub(crate) struct ConstEvalNonIntError {
84 #[primary_span]
85 pub span: Span,
86}
87
88#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
StrictCoherenceNeedsNegativeCoherence 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 {
StrictCoherenceNeedsNegativeCoherence {
span: __binding_0, attr_span: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled")));
;
diag.span(__binding_0);
diag.span_label(__binding_1,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("due to this attribute")));
diag
}
}
}
}
};Diagnostic)]
89#[diag(
90 "to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled"
91)]
92pub(crate) struct StrictCoherenceNeedsNegativeCoherence {
93 #[primary_span]
94 pub span: Span,
95 #[label("due to this attribute")]
96 pub attr_span: Span,
97}
98
99#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
RequiresLangItem 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 {
RequiresLangItem { span: __binding_0, name: __binding_1 } =>
{
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("requires `{$name}` lang_item")));
;
diag.arg("name", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
100#[diag("requires `{$name}` lang_item")]
101pub(crate) struct RequiresLangItem {
102 #[primary_span]
103 pub span: Span,
104 pub name: Symbol,
105}
106
107#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ConstNotUsedTraitAlias 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 {
ConstNotUsedTraitAlias { ct: __binding_0, span: __binding_1
} => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("const parameter `{$ct}` is part of concrete type but not used in parameter list for the `impl Trait` type alias")));
;
diag.arg("ct", __binding_0);
diag.span(__binding_1);
diag
}
}
}
}
};Diagnostic)]
108#[diag(
109 "const parameter `{$ct}` is part of concrete type but not used in parameter list for the `impl Trait` type alias"
110)]
111pub(super) struct ConstNotUsedTraitAlias {
112 pub ct: String,
113 #[primary_span]
114 pub span: Span,
115}
116
117pub struct CustomSubdiagnostic<'a> {
118 pub msg: fn() -> DiagMessage,
119 pub add_args: Box<dyn FnOnce(&mut dyn FnMut(DiagArgName, DiagArgValue)) + 'a>,
120}
121
122impl<'a> CustomSubdiagnostic<'a> {
123 pub fn label(x: fn() -> DiagMessage) -> Self {
124 Self::label_and_then(x, |_| {})
125 }
126 pub fn label_and_then<F: FnOnce(&mut dyn FnMut(DiagArgName, DiagArgValue)) + 'a>(
127 msg: fn() -> DiagMessage,
128 f: F,
129 ) -> Self {
130 Self { msg, add_args: Box::new(move |x| f(x)) }
131 }
132}
133
134impl fmt::Debug for CustomSubdiagnostic<'_> {
135 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
136 f.debug_struct("CustomSubdiagnostic").finish_non_exhaustive()
137 }
138}
139
140#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
LayoutError<'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 {
LayoutError::Unknown { ty: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type `{$ty}` has an unknown layout")));
;
diag.arg("ty", __binding_0);
diag
}
LayoutError::TooGeneric { ty: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type `{$ty}` does not have a fixed layout")));
;
diag.arg("ty", __binding_0);
diag
}
LayoutError::Overflow { ty: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("values of the type `{$ty}` are too big for the target architecture")));
;
diag.arg("ty", __binding_0);
diag
}
LayoutError::SimdTooManyLanes {
ty: __binding_0, max_lanes: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the SIMD type `{$ty}` has more elements than the limit {$max_lanes}")));
;
diag.arg("ty", __binding_0);
diag.arg("max_lanes", __binding_1);
diag
}
LayoutError::SimdZeroLength { ty: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the SIMD type `{$ty}` has zero elements")));
;
diag.arg("ty", __binding_0);
diag
}
LayoutError::NormalizationFailure {
ty: __binding_0, failure_ty: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized")));
;
diag.arg("ty", __binding_0);
diag.arg("failure_ty", __binding_1);
diag
}
LayoutError::Cycle => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("a cycle occurred during layout computation")));
;
diag
}
LayoutError::ReferencesError => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("the type has an unknown layout")));
;
diag
}
}
}
}
};Diagnostic)]
141pub enum LayoutError<'tcx> {
142 #[diag("the type `{$ty}` has an unknown layout")]
143 Unknown { ty: Ty<'tcx> },
144
145 #[diag("the type `{$ty}` does not have a fixed layout")]
146 TooGeneric { ty: Ty<'tcx> },
147
148 #[diag("values of the type `{$ty}` are too big for the target architecture")]
149 Overflow { ty: Ty<'tcx> },
150
151 #[diag("the SIMD type `{$ty}` has more elements than the limit {$max_lanes}")]
152 SimdTooManyLanes { ty: Ty<'tcx>, max_lanes: u64 },
153
154 #[diag("the SIMD type `{$ty}` has zero elements")]
155 SimdZeroLength { ty: Ty<'tcx> },
156
157 #[diag("unable to determine layout for `{$ty}` because `{$failure_ty}` cannot be normalized")]
158 NormalizationFailure { ty: Ty<'tcx>, failure_ty: String },
159
160 #[diag("a cycle occurred during layout computation")]
161 Cycle,
162
163 #[diag("the type has an unknown layout")]
164 ReferencesError,
165}
166
167#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
ErroneousConstant 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 {
ErroneousConstant { span: __binding_0 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("erroneous constant encountered")));
;
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
168#[diag("erroneous constant encountered")]
169pub(crate) struct ErroneousConstant {
170 #[primary_span]
171 pub span: Span,
172}
173
174#[derive(const _: () =
{
impl<'_sess, 'tcx, G> rustc_errors::Diagnostic<'_sess, G> for
TypeLengthLimit<'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 {
TypeLengthLimit {
span: __binding_0,
instance: __binding_1,
type_length: __binding_2 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("reached the type-length limit while instantiating `{$instance}`")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider adding a `#![type_length_limit=\"{$type_length}\"]` attribute to your crate")));
;
diag.arg("instance", __binding_1);
diag.arg("type_length", __binding_2);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
175#[diag("reached the type-length limit while instantiating `{$instance}`")]
176#[help("consider adding a `#![type_length_limit=\"{$type_length}\"]` attribute to your crate")]
177pub(crate) struct TypeLengthLimit<'tcx> {
178 #[primary_span]
179 pub span: Span,
180 pub instance: Instance<'tcx>,
181 pub type_length: usize,
182}
183
184#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MaxNumNodesInValtree 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 {
MaxNumNodesInValtree {
span: __binding_0, global_const_id: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("maximum number of nodes exceeded in constant {$global_const_id}")));
;
diag.arg("global_const_id", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
185#[diag("maximum number of nodes exceeded in constant {$global_const_id}")]
186pub(crate) struct MaxNumNodesInValtree {
187 #[primary_span]
188 pub span: Span,
189 pub global_const_id: String,
190}
191
192#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
InvalidConstInValtree 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 {
InvalidConstInValtree {
span: __binding_0, global_const_id: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constant {$global_const_id} cannot be used as pattern")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constants that reference mutable or external memory cannot be used as patterns")));
;
diag.arg("global_const_id", __binding_1);
diag.span(__binding_0);
diag
}
}
}
}
};Diagnostic)]
193#[diag("constant {$global_const_id} cannot be used as pattern")]
194#[note("constants that reference mutable or external memory cannot be used as patterns")]
195pub(crate) struct InvalidConstInValtree {
196 #[primary_span]
197 pub span: Span,
198 pub global_const_id: String,
199}