Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 1 | use std::path::PathBuf; |
| 2 | |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 3 | use crate::fluent_generated as fluent; |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 4 | use rustc_errors::ErrorGuaranteed; |
Charisee | f7ad1c4 | 2023-01-30 22:46:42 +0000 | [diff] [blame] | 5 | use rustc_errors::IntoDiagnostic; |
| 6 | use rustc_macros::{Diagnostic, LintDiagnostic}; |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 7 | use rustc_span::Span; |
| 8 | |
Charisee | f7ad1c4 | 2023-01-30 22:46:42 +0000 | [diff] [blame] | 9 | #[derive(Diagnostic)] |
| 10 | #[diag(monomorphize_recursion_limit)] |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 11 | pub 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, |
Charisee | f7ad1c4 | 2023-01-30 22:46:42 +0000 | [diff] [blame] | 18 | #[note(monomorphize_written_to_path)] |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 19 | pub was_written: Option<()>, |
| 20 | pub path: PathBuf, |
| 21 | } |
| 22 | |
Charisee | f7ad1c4 | 2023-01-30 22:46:42 +0000 | [diff] [blame] | 23 | #[derive(Diagnostic)] |
| 24 | #[diag(monomorphize_type_length_limit)] |
| 25 | #[help(monomorphize_consider_type_length_limit)] |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 26 | pub struct TypeLengthLimit { |
| 27 | #[primary_span] |
| 28 | pub span: Span, |
| 29 | pub shrunk: String, |
Charisee | f7ad1c4 | 2023-01-30 22:46:42 +0000 | [diff] [blame] | 30 | #[note(monomorphize_written_to_path)] |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 31 | pub was_written: Option<()>, |
| 32 | pub path: PathBuf, |
| 33 | pub type_length: usize, |
| 34 | } |
| 35 | |
Charisee | d720b3f | 2023-03-09 17:35:07 +0000 | [diff] [blame] | 36 | pub struct UnusedGenericParamsHint { |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 37 | pub span: Span, |
| 38 | pub param_spans: Vec<Span>, |
| 39 | pub param_names: Vec<String>, |
| 40 | } |
| 41 | |
Charisee | d720b3f | 2023-03-09 17:35:07 +0000 | [diff] [blame] | 42 | impl IntoDiagnostic<'_> for UnusedGenericParamsHint { |
Chris Wailes | 977026a | 2023-02-13 09:13:10 -0800 | [diff] [blame] | 43 | #[track_caller] |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 44 | fn into_diagnostic( |
| 45 | self, |
| 46 | handler: &'_ rustc_errors::Handler, |
| 47 | ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 48 | let mut diag = handler.struct_err(fluent::monomorphize_unused_generic_params); |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 49 | 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. 😢 |
Charisee | d720b3f | 2023-03-09 17:35:07 +0000 | [diff] [blame] | 54 | diag.span_label(span, format!("generic parameter `{name}` is unused")); |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 55 | } |
| 56 | diag |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | #[derive(LintDiagnostic)] |
Charisee | f7ad1c4 | 2023-01-30 22:46:42 +0000 | [diff] [blame] | 61 | #[diag(monomorphize_large_assignments)] |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 62 | #[note] |
| 63 | pub struct LargeAssignmentsLint { |
| 64 | #[label] |
| 65 | pub span: Span, |
| 66 | pub size: u64, |
| 67 | pub limit: u64, |
| 68 | } |
| 69 | |
Charisee | f7ad1c4 | 2023-01-30 22:46:42 +0000 | [diff] [blame] | 70 | #[derive(Diagnostic)] |
| 71 | #[diag(monomorphize_unknown_partition_strategy)] |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 72 | pub struct UnknownPartitionStrategy; |
| 73 | |
Charisee | f7ad1c4 | 2023-01-30 22:46:42 +0000 | [diff] [blame] | 74 | #[derive(Diagnostic)] |
| 75 | #[diag(monomorphize_symbol_already_defined)] |
Chris Wailes | 2f380c1 | 2022-11-09 13:04:22 -0800 | [diff] [blame] | 76 | pub struct SymbolAlreadyDefined { |
| 77 | #[primary_span] |
| 78 | pub span: Option<Span>, |
| 79 | pub symbol: String, |
| 80 | } |
Charisee | d720b3f | 2023-03-09 17:35:07 +0000 | [diff] [blame] | 81 | |
| 82 | #[derive(Diagnostic)] |
| 83 | #[diag(monomorphize_couldnt_dump_mono_stats)] |
| 84 | pub struct CouldntDumpMonoStats { |
| 85 | pub error: String, |
| 86 | } |
Chris Wailes | 5c0824a | 2023-04-24 16:30:59 -0700 | [diff] [blame] | 87 | |
| 88 | #[derive(Diagnostic)] |
| 89 | #[diag(monomorphize_encountered_error_while_instantiating)] |
| 90 | pub 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)] |
| 98 | pub struct UnknownCguCollectionMode<'a> { |
| 99 | pub mode: &'a str, |
| 100 | } |