]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_monomorphize/src/errors.rs
Auto merge of #105127 - Sp00ph:const_new, r=dtolnay
[rust.git] / compiler / rustc_monomorphize / src / errors.rs
1 use std::path::PathBuf;
2
3 use rustc_errors::ErrorGuaranteed;
4 use rustc_errors::IntoDiagnostic;
5 use rustc_macros::{Diagnostic, LintDiagnostic};
6 use rustc_span::Span;
7
8 #[derive(Diagnostic)]
9 #[diag(monomorphize_recursion_limit)]
10 pub struct RecursionLimit {
11     #[primary_span]
12     pub span: Span,
13     pub shrunk: String,
14     #[note]
15     pub def_span: Span,
16     pub def_path_str: String,
17     #[note(monomorphize_written_to_path)]
18     pub was_written: Option<()>,
19     pub path: PathBuf,
20 }
21
22 #[derive(Diagnostic)]
23 #[diag(monomorphize_type_length_limit)]
24 #[help(monomorphize_consider_type_length_limit)]
25 pub struct TypeLengthLimit {
26     #[primary_span]
27     pub span: Span,
28     pub shrunk: String,
29     #[note(monomorphize_written_to_path)]
30     pub was_written: Option<()>,
31     pub path: PathBuf,
32     pub type_length: usize,
33 }
34
35 pub struct UnusedGenericParams {
36     pub span: Span,
37     pub param_spans: Vec<Span>,
38     pub param_names: Vec<String>,
39 }
40
41 impl IntoDiagnostic<'_> for UnusedGenericParams {
42     #[track_caller]
43     fn into_diagnostic(
44         self,
45         handler: &'_ rustc_errors::Handler,
46     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
47         let mut diag = handler.struct_err(rustc_errors::fluent::monomorphize_unused_generic_params);
48         diag.set_span(self.span);
49         for (span, name) in self.param_spans.into_iter().zip(self.param_names) {
50             // FIXME: I can figure out how to do a label with a fluent string with a fixed message,
51             // or a label with a dynamic value in a hard-coded string, but I haven't figured out
52             // how to combine the two. ðŸ˜¢
53             diag.span_label(span, format!("generic parameter `{}` is unused", name));
54         }
55         diag
56     }
57 }
58
59 #[derive(LintDiagnostic)]
60 #[diag(monomorphize_large_assignments)]
61 #[note]
62 pub struct LargeAssignmentsLint {
63     #[label]
64     pub span: Span,
65     pub size: u64,
66     pub limit: u64,
67 }
68
69 #[derive(Diagnostic)]
70 #[diag(monomorphize_unknown_partition_strategy)]
71 pub struct UnknownPartitionStrategy;
72
73 #[derive(Diagnostic)]
74 #[diag(monomorphize_symbol_already_defined)]
75 pub struct SymbolAlreadyDefined {
76     #[primary_span]
77     pub span: Option<Span>,
78     pub symbol: String,
79 }
80
81 #[derive(Diagnostic)]
82 #[diag(monomorphize_couldnt_dump_mono_stats)]
83 pub struct CouldntDumpMonoStats {
84     pub error: String,
85 }