blob: 495a73490a21714219301dacd64224299299c18a [file] [log] [blame]
Chris Wailes2f380c12022-11-09 13:04:22 -08001use std::path::PathBuf;
2
Chris Wailes5c0824a2023-04-24 16:30:59 -07003use crate::fluent_generated as fluent;
Chris Wailes2f380c12022-11-09 13:04:22 -08004use rustc_errors::ErrorGuaranteed;
Chariseef7ad1c42023-01-30 22:46:42 +00005use rustc_errors::IntoDiagnostic;
6use rustc_macros::{Diagnostic, LintDiagnostic};
Chris Wailes2f380c12022-11-09 13:04:22 -08007use rustc_span::Span;
8
Chariseef7ad1c42023-01-30 22:46:42 +00009#[derive(Diagnostic)]
10#[diag(monomorphize_recursion_limit)]
Chris Wailes2f380c12022-11-09 13:04:22 -080011pub struct RecursionLimit {
12 #[primary_span]
13 pub span: Span,
14 pub shrunk: String,
15 #[note]
16 pub def_span: Span,
17 pub def_path_str: String,
Chariseef7ad1c42023-01-30 22:46:42 +000018 #[note(monomorphize_written_to_path)]
Chris Wailes2f380c12022-11-09 13:04:22 -080019 pub was_written: Option<()>,
20 pub path: PathBuf,
21}
22
Chariseef7ad1c42023-01-30 22:46:42 +000023#[derive(Diagnostic)]
24#[diag(monomorphize_type_length_limit)]
25#[help(monomorphize_consider_type_length_limit)]
Chris Wailes2f380c12022-11-09 13:04:22 -080026pub struct TypeLengthLimit {
27 #[primary_span]
28 pub span: Span,
29 pub shrunk: String,
Chariseef7ad1c42023-01-30 22:46:42 +000030 #[note(monomorphize_written_to_path)]
Chris Wailes2f380c12022-11-09 13:04:22 -080031 pub was_written: Option<()>,
32 pub path: PathBuf,
33 pub type_length: usize,
34}
35
Chariseed720b3f2023-03-09 17:35:07 +000036pub struct UnusedGenericParamsHint {
Chris Wailes2f380c12022-11-09 13:04:22 -080037 pub span: Span,
38 pub param_spans: Vec<Span>,
39 pub param_names: Vec<String>,
40}
41
Chariseed720b3f2023-03-09 17:35:07 +000042impl IntoDiagnostic<'_> for UnusedGenericParamsHint {
Chris Wailes977026a2023-02-13 09:13:10 -080043 #[track_caller]
Chris Wailes2f380c12022-11-09 13:04:22 -080044 fn into_diagnostic(
45 self,
46 handler: &'_ rustc_errors::Handler,
47 ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
Chris Wailes5c0824a2023-04-24 16:30:59 -070048 let mut diag = handler.struct_err(fluent::monomorphize_unused_generic_params);
Chris Wailes2f380c12022-11-09 13:04:22 -080049 diag.set_span(self.span);
50 for (span, name) in self.param_spans.into_iter().zip(self.param_names) {
51 // FIXME: I can figure out how to do a label with a fluent string with a fixed message,
52 // or a label with a dynamic value in a hard-coded string, but I haven't figured out
53 // how to combine the two. 😢
Chariseed720b3f2023-03-09 17:35:07 +000054 diag.span_label(span, format!("generic parameter `{name}` is unused"));
Chris Wailes2f380c12022-11-09 13:04:22 -080055 }
56 diag
57 }
58}
59
60#[derive(LintDiagnostic)]
Chariseef7ad1c42023-01-30 22:46:42 +000061#[diag(monomorphize_large_assignments)]
Chris Wailes2f380c12022-11-09 13:04:22 -080062#[note]
63pub struct LargeAssignmentsLint {
64 #[label]
65 pub span: Span,
66 pub size: u64,
67 pub limit: u64,
68}
69
Chariseef7ad1c42023-01-30 22:46:42 +000070#[derive(Diagnostic)]
71#[diag(monomorphize_unknown_partition_strategy)]
Chris Wailes2f380c12022-11-09 13:04:22 -080072pub struct UnknownPartitionStrategy;
73
Chariseef7ad1c42023-01-30 22:46:42 +000074#[derive(Diagnostic)]
75#[diag(monomorphize_symbol_already_defined)]
Chris Wailes2f380c12022-11-09 13:04:22 -080076pub struct SymbolAlreadyDefined {
77 #[primary_span]
78 pub span: Option<Span>,
79 pub symbol: String,
80}
Chariseed720b3f2023-03-09 17:35:07 +000081
82#[derive(Diagnostic)]
83#[diag(monomorphize_couldnt_dump_mono_stats)]
84pub struct CouldntDumpMonoStats {
85 pub error: String,
86}
Chris Wailes5c0824a2023-04-24 16:30:59 -070087
88#[derive(Diagnostic)]
89#[diag(monomorphize_encountered_error_while_instantiating)]
90pub struct EncounteredErrorWhileInstantiating {
91 #[primary_span]
92 pub span: Span,
93 pub formatted_item: String,
94}
95
96#[derive(Diagnostic)]
97#[diag(monomorphize_unknown_cgu_collection_mode)]
98pub struct UnknownCguCollectionMode<'a> {
99 pub mode: &'a str,
100}