about summary refs log tree commit diff
path: root/compiler/rustc_monomorphize/src/errors.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-12-18 14:12:39 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2023-12-19 09:19:25 +1100
commite7724a2e319f112ee6a97999976d8225b009456e (patch)
tree7bbb277532a16068f41bb8703fa7087b87ef15f4 /compiler/rustc_monomorphize/src/errors.rs
parent31df50c8973aeb70fcf42b403239f4fc4712988c (diff)
downloadrust-e7724a2e319f112ee6a97999976d8225b009456e.tar.gz
rust-e7724a2e319f112ee6a97999976d8225b009456e.zip
Add `level` arg to `into_diagnostic`.
And make all hand-written `IntoDiagnostic` impls generic, by using
`DiagnosticBuilder::new(dcx, level, ...)` instead of e.g.
`dcx.struct_err(...)`.

This means the `create_*` functions are the source of the error level.
This change will let us remove `struct_diagnostic`.

Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`,
it's necessary to pass diagnostics tests now that it's used in
`into_diagnostic` functions.
Diffstat (limited to 'compiler/rustc_monomorphize/src/errors.rs')
-rw-r--r--compiler/rustc_monomorphize/src/errors.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs
index 247b2245583..592e71251b8 100644
--- a/compiler/rustc_monomorphize/src/errors.rs
+++ b/compiler/rustc_monomorphize/src/errors.rs
@@ -1,8 +1,7 @@
 use std::path::PathBuf;
 
 use crate::fluent_generated as fluent;
-use rustc_errors::ErrorGuaranteed;
-use rustc_errors::IntoDiagnostic;
+use rustc_errors::{DiagCtxt, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic, Level};
 use rustc_macros::{Diagnostic, LintDiagnostic};
 use rustc_span::{Span, Symbol};
 
@@ -47,13 +46,11 @@ pub struct UnusedGenericParamsHint {
     pub param_names: Vec<String>,
 }
 
-impl IntoDiagnostic<'_> for UnusedGenericParamsHint {
+impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for UnusedGenericParamsHint {
     #[track_caller]
-    fn into_diagnostic(
-        self,
-        dcx: &'_ rustc_errors::DiagCtxt,
-    ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
-        let mut diag = dcx.struct_err(fluent::monomorphize_unused_generic_params);
+    fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
+        let mut diag =
+            DiagnosticBuilder::new(dcx, level, 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,