rustc_query_system/
error.rs1use rustc_errors::codes::*;
2use rustc_macros::{Diagnostic, Subdiagnostic};
3use rustc_span::Span;
4
5#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for CycleStack {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
CycleStack { span: __binding_0, desc: __binding_1 } => {
diag.store_args();
diag.arg("desc", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...which requires {$desc}...")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
6#[note("...which requires {$desc}...")]
7pub(crate) struct CycleStack {
8 #[primary_span]
9 pub span: Span,
10 pub desc: String,
11}
12
13#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for StackCount {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
StackCount::Single => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...which immediately requires {$stack_bottom} again")));
diag.note(__message);
diag.restore_args();
}
StackCount::Multiple => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("...which again requires {$stack_bottom}, completing the cycle")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
14pub(crate) enum StackCount {
15 #[note("...which immediately requires {$stack_bottom} again")]
16 Single,
17 #[note("...which again requires {$stack_bottom}, completing the cycle")]
18 Multiple,
19}
20
21#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for Alias {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
Alias::Ty => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type aliases cannot be recursive")));
diag.note(__message);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider using a struct, enum, or union instead to break the cycle")));
diag.help(__message);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information")));
diag.help(__message);
diag.restore_args();
}
Alias::Trait => {
diag.store_args();
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("trait aliases cannot be recursive")));
diag.note(__message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
22pub(crate) enum Alias {
23 #[note("type aliases cannot be recursive")]
24 #[help("consider using a struct, enum, or union instead to break the cycle")]
25 #[help(
26 "see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information"
27 )]
28 Ty,
29 #[note("trait aliases cannot be recursive")]
30 Trait,
31}
32
33#[derive(const _: () =
{
impl rustc_errors::Subdiagnostic for CycleUsage {
fn add_to_diag<__G>(self, diag: &mut rustc_errors::Diag<'_, __G>)
where __G: rustc_errors::EmissionGuarantee {
match self {
CycleUsage { span: __binding_0, usage: __binding_1 } => {
diag.store_args();
diag.arg("usage", __binding_1);
let __message =
diag.eagerly_translate(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cycle used when {$usage}")));
diag.span_note(__binding_0, __message);
diag.restore_args();
}
}
}
}
};Subdiagnostic)]
34#[note("cycle used when {$usage}")]
35pub(crate) struct CycleUsage {
36 #[primary_span]
37 pub span: Span,
38 pub usage: String,
39}
40
41#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for Cycle 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 {
Cycle {
span: __binding_0,
stack_bottom: __binding_1,
cycle_stack: __binding_2,
stack_count: __binding_3,
alias: __binding_4,
cycle_usage: __binding_5,
note_span: __binding_6 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("cycle detected when {$stack_bottom}")));
diag.code(E0391);
;
diag.arg("stack_bottom", __binding_1);
diag.span(__binding_0);
for __binding_2 in __binding_2 {
diag.subdiagnostic(__binding_2);
}
diag.subdiagnostic(__binding_3);
if let Some(__binding_4) = __binding_4 {
diag.subdiagnostic(__binding_4);
}
if let Some(__binding_5) = __binding_5 {
diag.subdiagnostic(__binding_5);
}
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information")));
diag
}
}
}
}
};Diagnostic)]
42#[diag("cycle detected when {$stack_bottom}", code = E0391)]
43pub(crate) struct Cycle {
44 #[primary_span]
45 pub span: Span,
46 pub stack_bottom: String,
47 #[subdiagnostic]
48 pub cycle_stack: Vec<CycleStack>,
49 #[subdiagnostic]
50 pub stack_count: StackCount,
51 #[subdiagnostic]
52 pub alias: Option<Alias>,
53 #[subdiagnostic]
54 pub cycle_usage: Option<CycleUsage>,
55 #[note(
56 "see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information"
57 )]
58 pub note_span: (),
59}
60
61#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for Reentrant
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 {
Reentrant => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("internal compiler error: reentrant incremental verify failure, suppressing message")));
;
diag
}
}
}
}
};Diagnostic)]
62#[diag("internal compiler error: reentrant incremental verify failure, suppressing message")]
63pub(crate) struct Reentrant;
64
65#[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
IncrementCompilation 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 {
IncrementCompilation {
run_cmd: __binding_0, dep_node: __binding_1 } => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("internal compiler error: encountered incremental compilation error with {$dep_node}")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("please follow the instructions below to create a bug report with the provided information")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("for incremental compilation bugs, having a reproduction is vital")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("an ideal reproduction consists of the code before and some patch that then triggers the bug when applied and compiled again")));
diag.note(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("as a workaround, you can run {$run_cmd} to allow your project to compile")));
;
diag.arg("run_cmd", __binding_0);
diag.arg("dep_node", __binding_1);
diag
}
}
}
}
};Diagnostic)]
66#[diag("internal compiler error: encountered incremental compilation error with {$dep_node}")]
67#[note("please follow the instructions below to create a bug report with the provided information")]
68#[note("for incremental compilation bugs, having a reproduction is vital")]
69#[note(
70 "an ideal reproduction consists of the code before and some patch that then triggers the bug when applied and compiled again"
71)]
72#[note("as a workaround, you can run {$run_cmd} to allow your project to compile")]
73pub(crate) struct IncrementCompilation {
74 pub run_cmd: String,
75 pub dep_node: String,
76}