diff options
| author | Nathan Stocks <cleancut@github.com> | 2022-08-18 15:51:47 -0600 |
|---|---|---|
| committer | Nathan Stocks <cleancut@github.com> | 2022-08-25 11:06:32 -0600 |
| commit | 137f20c11265ea70e3ed3ed7798662b9abfbaad2 (patch) | |
| tree | e9e9323ebecadd0740083c3169c97fbd9dc6f65b /compiler/rustc_monomorphize/src/errors.rs | |
| parent | 4d45b0745ab227feb9000bc15713ade4b99241ea (diff) | |
| download | rust-137f20c11265ea70e3ed3ed7798662b9abfbaad2.tar.gz rust-137f20c11265ea70e3ed3ed7798662b9abfbaad2.zip | |
rebased: convert rustc_monomorphize errors to SessionDiagnostic
Diffstat (limited to 'compiler/rustc_monomorphize/src/errors.rs')
| -rw-r--r-- | compiler/rustc_monomorphize/src/errors.rs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs new file mode 100644 index 00000000000..62ebac97136 --- /dev/null +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -0,0 +1,81 @@ +use std::path::PathBuf; + +use rustc_errors::ErrorGuaranteed; +use rustc_macros::{LintDiagnostic, SessionDiagnostic}; +use rustc_session::SessionDiagnostic; +// use rustc_session::SessionDiagnostic; +use rustc_span::Span; + +#[derive(SessionDiagnostic)] +#[diag(monomorphize::recursion_limit)] +pub struct RecursionLimit { + #[primary_span] + pub span: Span, + pub shrunk: String, + #[note] + pub def_span: Span, + pub def_path_str: String, + #[note(monomorphize::written_to_path)] + pub was_written: Option<()>, + pub path: PathBuf, +} + +#[derive(SessionDiagnostic)] +#[diag(monomorphize::type_length_limit)] +#[help(monomorphize::consider_type_length_limit)] +pub struct TypeLengthLimit { + #[primary_span] + pub span: Span, + pub shrunk: String, + #[note(monomorphize::written_to_path)] + pub was_written: Option<()>, + pub path: PathBuf, + pub type_length: usize, +} + +#[derive(SessionDiagnostic)] +#[diag(monomorphize::fatal_error)] +pub struct FatalError { + pub error_message: String, +} + +#[derive(SessionDiagnostic)] +#[diag(monomorphize::fatal_error)] +pub struct SpanFatalError { + #[primary_span] + pub span: Span, + pub error_message: String, +} + +pub struct UnusedGenericParams { + pub span: Span, + pub param_spans: Vec<Span>, + pub param_names: Vec<String>, +} + +impl SessionDiagnostic<'_> for UnusedGenericParams { + fn into_diagnostic( + self, + sess: &'_ rustc_session::parse::ParseSess, + ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { + let mut diag = sess.struct_err(rustc_errors::fluent::monomorphize::unused_generic_params); + diag.set_span(self.span); + for (span, name) in self.param_spans.into_iter().zip(self.param_names) { + // FIXME: I can figure out how to do a label with a fluent string with a fixed message, + // or a label with a dynamic value in a hard-coded string, but I haven't figured out + // how to combine the two. 😢 + diag.span_label(span, format!("generic parameter `{}` is unused", name)); + } + diag + } +} + +#[derive(LintDiagnostic)] +#[diag(monomorphize::large_assignments)] +#[note] +pub struct LargeAssignmentsLint { + #[label] + pub span: Span, + pub size: u64, + pub limit: u64, +} |
