Skip to content

Commit 472ea06

Browse files
committed
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.
1 parent 5ea71c1 commit 472ea06

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/errors.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_errors::{
2-
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic,
3-
IntoDiagnosticArg,
2+
DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, EmissionGuarantee, IntoDiagnostic,
3+
IntoDiagnosticArg, Level,
44
};
55
use rustc_macros::{Diagnostic, Subdiagnostic};
66
use rustc_span::Span;
@@ -111,9 +111,13 @@ pub(crate) struct TargetFeatureDisableOrEnable<'a> {
111111
#[help(codegen_gcc_missing_features)]
112112
pub(crate) struct MissingFeatures;
113113

114-
impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
115-
fn into_diagnostic(self, dcx: &'_ DiagCtxt) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
116-
let mut diag = dcx.struct_err(fluent::codegen_gcc_target_feature_disable_or_enable);
114+
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for TargetFeatureDisableOrEnable<'_> {
115+
fn into_diagnostic(self, dcx: &'_ DiagCtxt, level: Level) -> DiagnosticBuilder<'_, G> {
116+
let mut diag = DiagnosticBuilder::new(
117+
dcx,
118+
level,
119+
fluent::codegen_gcc_target_feature_disable_or_enable
120+
);
117121
if let Some(span) = self.span {
118122
diag.set_span(span);
119123
};

0 commit comments

Comments
 (0)