|
1 |
| -use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed}; |
2 |
| -use rustc_session::SessionDiagnostic; |
| 1 | +use rustc_errors::AddSubdiagnostic; |
3 | 2 | use rustc_span::Span;
|
4 | 3 |
|
5 |
| -pub struct Cycle { |
| 4 | +pub struct CycleStack { |
6 | 5 | pub span: Span,
|
7 |
| - pub stack_bottom: String, |
8 |
| - pub upper_stack_info: Vec<(Span, String)>, |
9 |
| - pub recursive_ty_alias: bool, |
10 |
| - pub recursive_trait_alias: bool, |
11 |
| - pub cycle_usage: Option<(Span, String)>, |
| 6 | + pub desc: String, |
12 | 7 | }
|
13 | 8 |
|
14 |
| -impl SessionDiagnostic<'_> for Cycle { |
15 |
| - fn into_diagnostic( |
16 |
| - self, |
17 |
| - sess: &'_ rustc_session::parse::ParseSess, |
18 |
| - ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { |
19 |
| - let mut diag = sess.struct_err(rustc_errors::fluent::query_system::cycle); |
20 |
| - diag.set_span(self.span); |
21 |
| - diag.code(rustc_errors::DiagnosticId::Error("E0391".to_string())); |
22 |
| - let upper_stack_len = self.upper_stack_info.len(); |
23 |
| - for (span, desc) in self.upper_stack_info.into_iter() { |
24 |
| - // FIXME(#100717): use fluent translation |
25 |
| - diag.span_note(span, &format!("...which requires {}...", desc)); |
26 |
| - } |
27 |
| - diag.set_arg("stack_bottom", self.stack_bottom); |
28 |
| - if upper_stack_len == 0 { |
29 |
| - diag.note(rustc_errors::fluent::query_system::cycle_stack_single); |
30 |
| - } else { |
31 |
| - diag.note(rustc_errors::fluent::query_system::cycle_stack_multiple); |
32 |
| - } |
33 |
| - if self.recursive_trait_alias { |
34 |
| - diag.note(rustc_errors::fluent::query_system::cycle_recursive_trait_alias); |
35 |
| - } else if self.recursive_ty_alias { |
36 |
| - diag.note(rustc_errors::fluent::query_system::cycle_recursive_ty_alias); |
37 |
| - diag.help(rustc_errors::fluent::query_system::cycle_recursive_ty_alias_help1); |
38 |
| - diag.help(rustc_errors::fluent::query_system::cycle_recursive_ty_alias_help2); |
39 |
| - } |
40 |
| - if let Some((span, desc)) = self.cycle_usage { |
41 |
| - diag.set_arg("usage", desc); |
42 |
| - diag.span_note(span, rustc_errors::fluent::query_system::cycle_usage); |
43 |
| - } |
44 |
| - diag |
| 9 | +impl AddSubdiagnostic for CycleStack { |
| 10 | + fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { |
| 11 | + diag.span_note(self.span, &format!("...which requires {}...", self.desc)); |
45 | 12 | }
|
46 | 13 | }
|
47 | 14 |
|
| 15 | +#[derive(SessionSubdiagnostic)] |
| 16 | +pub enum StackCount { |
| 17 | + #[note(query_system::cycle_stack_single)] |
| 18 | + Single, |
| 19 | + #[note(query_system::cycle_stack_multiple)] |
| 20 | + Multiple, |
| 21 | +} |
| 22 | + |
| 23 | +#[derive(SessionSubdiagnostic)] |
| 24 | +pub enum Alias { |
| 25 | + #[note(query_system::cycle_recursive_ty_alias)] |
| 26 | + #[help(query_system::cycle_recursive_ty_alias_help1)] |
| 27 | + #[help(query_system::cycle_recursive_ty_alias_help2)] |
| 28 | + Ty, |
| 29 | + #[note(query_system::cycle_recursive_trait_alias)] |
| 30 | + Trait, |
| 31 | +} |
| 32 | + |
| 33 | +#[derive(SessionSubdiagnostic)] |
| 34 | +#[note(query_system::cycle_usage)] |
| 35 | +pub struct CycleUsage { |
| 36 | + #[primary_span] |
| 37 | + pub span: Span, |
| 38 | + pub usage: String, |
| 39 | +} |
| 40 | + |
| 41 | +#[derive(SessionDiagnostic)] |
| 42 | +#[diag(query_system::cycle, code = "E0391")] |
| 43 | +pub 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 | +} |
| 56 | + |
48 | 57 | #[derive(SessionDiagnostic)]
|
49 | 58 | #[diag(query_system::reentrant)]
|
50 | 59 | pub struct Reentrant;
|
|
0 commit comments