]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_monomorphize/src/errors.rs
Skip chained OpaqueCast when building captures.
[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 #[derive(Diagnostic)]
36 #[diag(monomorphize::requires_lang_item)]
37 pub struct RequiresLangItem {
38     pub lang_item: String,
39 }
40
41 pub struct UnusedGenericParams {
42     pub span: Span,
43     pub param_spans: Vec<Span>,
44     pub param_names: Vec<String>,
45 }
46
47 impl IntoDiagnostic<'_> for UnusedGenericParams {
48     fn into_diagnostic(
49         self,
50         handler: &'_ rustc_errors::Handler,
51     ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
52         let mut diag =
53             handler.struct_err(rustc_errors::fluent::monomorphize::unused_generic_params);
54         diag.set_span(self.span);
55         for (span, name) in self.param_spans.into_iter().zip(self.param_names) {
56             // FIXME: I can figure out how to do a label with a fluent string with a fixed message,
57             // or a label with a dynamic value in a hard-coded string, but I haven't figured out
58             // how to combine the two. ðŸ˜¢
59             diag.span_label(span, format!("generic parameter `{}` is unused", name));
60         }
61         diag
62     }
63 }
64
65 #[derive(LintDiagnostic)]
66 #[diag(monomorphize::large_assignments)]
67 #[note]
68 pub struct LargeAssignmentsLint {
69     #[label]
70     pub span: Span,
71     pub size: u64,
72     pub limit: u64,
73 }
74
75 #[derive(Diagnostic)]
76 #[diag(monomorphize::unknown_partition_strategy)]
77 pub struct UnknownPartitionStrategy;
78
79 #[derive(Diagnostic)]
80 #[diag(monomorphize::symbol_already_defined)]
81 pub struct SymbolAlreadyDefined {
82     #[primary_span]
83     pub span: Option<Span>,
84     pub symbol: String,
85 }