]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_query_system/src/error.rs
UPDATE - rename DiagnosticHandler trait to IntoDiagnostic
[rust.git] / compiler / rustc_query_system / src / error.rs
1 use rustc_errors::AddToDiagnostic;
2 use rustc_session::Limit;
3 use rustc_span::{Span, Symbol};
4
5 pub struct CycleStack {
6     pub span: Span,
7     pub desc: String,
8 }
9
10 impl AddToDiagnostic for CycleStack {
11     fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) {
12         diag.span_note(self.span, &format!("...which requires {}...", self.desc));
13     }
14 }
15
16 #[derive(Copy, Clone)]
17 pub enum HandleCycleError {
18     Error,
19     Fatal,
20     DelayBug,
21 }
22
23 #[derive(SessionSubdiagnostic)]
24 pub enum StackCount {
25     #[note(query_system::cycle_stack_single)]
26     Single,
27     #[note(query_system::cycle_stack_multiple)]
28     Multiple,
29 }
30
31 #[derive(SessionSubdiagnostic)]
32 pub enum Alias {
33     #[note(query_system::cycle_recursive_ty_alias)]
34     #[help(query_system::cycle_recursive_ty_alias_help1)]
35     #[help(query_system::cycle_recursive_ty_alias_help2)]
36     Ty,
37     #[note(query_system::cycle_recursive_trait_alias)]
38     Trait,
39 }
40
41 #[derive(SessionSubdiagnostic)]
42 #[note(query_system::cycle_usage)]
43 pub struct CycleUsage {
44     #[primary_span]
45     pub span: Span,
46     pub usage: String,
47 }
48
49 #[derive(DiagnosticHandler)]
50 #[diag(query_system::cycle, code = "E0391")]
51 pub struct Cycle {
52     #[primary_span]
53     pub span: Span,
54     pub stack_bottom: String,
55     #[subdiagnostic]
56     pub cycle_stack: Vec<CycleStack>,
57     #[subdiagnostic]
58     pub stack_count: StackCount,
59     #[subdiagnostic]
60     pub alias: Option<Alias>,
61     #[subdiagnostic]
62     pub cycle_usage: Option<CycleUsage>,
63 }
64
65 #[derive(DiagnosticHandler)]
66 #[diag(query_system::reentrant)]
67 pub struct Reentrant;
68
69 #[derive(DiagnosticHandler)]
70 #[diag(query_system::increment_compilation)]
71 #[help]
72 #[note(query_system::increment_compilation_note1)]
73 #[note(query_system::increment_compilation_note2)]
74 pub struct IncrementCompilation {
75     pub run_cmd: String,
76     pub dep_node: String,
77 }
78
79 #[derive(Diagnostic)]
80 #[help]
81 #[diag(query_system::query_overflow)]
82 pub struct QueryOverflow {
83     #[primary_span]
84     pub span: Option<Span>,
85     #[subdiagnostic]
86     pub layout_of_depth: Option<LayoutOfDepth>,
87     pub suggested_limit: Limit,
88     pub crate_name: Symbol,
89 }
90
91 #[derive(Subdiagnostic)]
92 #[note(query_system::layout_of_depth)]
93 pub struct LayoutOfDepth {
94     pub desc: String,
95     pub depth: usize,
96 }