summary refs log tree commit diff
path: root/compiler/rustc_const_eval/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
commite7724a2e319f112ee6a97999976d8225b009456e (patch)
tree7bbb277532a16068f41bb8703fa7087b87ef15f4 /compiler/rustc_const_eval/src
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_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/errors.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs
index adce1f5430f..eb9bf52676a 100644
--- a/compiler/rustc_const_eval/src/errors.rs
+++ b/compiler/rustc_const_eval/src/errors.rs
@@ -1,6 +1,6 @@
 use rustc_errors::{
     DiagCtxt, DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee,
-    IntoDiagnostic,
+    IntoDiagnostic, Level,
 };
 use rustc_hir::ConstContext;
 use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
@@ -875,7 +875,10 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
             | InvalidProgramInfo::AlreadyReported(_)
             | InvalidProgramInfo::ConstPropNonsense => {}
             InvalidProgramInfo::Layout(e) => {
-                let diag: DiagnosticBuilder<'_, ()> = e.into_diagnostic().into_diagnostic(dcx);
+                // The level doesn't matter, `diag` is consumed without it being used.
+                let dummy_level = Level::Bug;
+                let diag: DiagnosticBuilder<'_, ()> =
+                    e.into_diagnostic().into_diagnostic(dcx, dummy_level);
                 for (name, val) in diag.args() {
                     builder.set_arg(name.clone(), val.clone());
                 }