about summary refs log tree commit diff
path: root/src
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
commit472ea06999ce6ecfb78554a74b14dec9dae97f38 (patch)
treeae7fb0fd5558fdbb7f50984c3fc55ea0e4ed88b2 /src
parent5ea71c1150a7ef7a35be240c0e0d40525a94afe0 (diff)
downloadrust-472ea06999ce6ecfb78554a74b14dec9dae97f38.tar.gz
rust-472ea06999ce6ecfb78554a74b14dec9dae97f38.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 'src')
-rw-r--r--src/errors.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/errors.rs b/src/errors.rs
index 766d90cf724..1b1ed0b411c 100644
--- a/src/errors.rs
+++ b/src/errors.rs
@@ -1,6 +1,6 @@
 use rustc_errors::{
-    DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic,
-    IntoDiagnosticArg,
+    DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
+    IntoDiagnosticArg, Level,
 };
 use rustc_macros::{Diagnostic, Subdiagnostic};
 use rustc_span::Span;
@@ -111,9 +111,13 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
 #[help(codegen_gcc_missing_features)]
 pub(crate) struct MissingFeatures;
 
-impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
-    fn into_diagnostic(self, dcx: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
-        let mut diag = dcx.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable);
+impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
+    fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
+        let mut diag = DiagnosticBuilder::new(
+            dcx,
+            level,
+            fluent::codegen_gcc_target_feature_disable_or_enable
+        );
         if let Some(span) = self.span {
             diag.set_span(span);
         };