diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2023-05-29 06:40:15 +0000 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2023-06-01 14:45:19 +0000 |
| commit | f6c2bc5c24fd08200c0e4438d981ca58dc71f488 (patch) | |
| tree | 18f715c15b28696d34e4afb3c4939bf851b65242 /compiler/rustc_const_eval/src/errors.rs | |
| parent | f964b46451f3a323f312a7035e25180060044335 (diff) | |
| download | rust-f6c2bc5c24fd08200c0e4438d981ca58dc71f488.tar.gz rust-f6c2bc5c24fd08200c0e4438d981ca58dc71f488.zip | |
fix diagnostic message
Diffstat (limited to 'compiler/rustc_const_eval/src/errors.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/errors.rs | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index c83f6cf13e0..eed3091d481 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -1,5 +1,3 @@ -use std::fmt; - use rustc_errors::{ DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, Handler, IntoDiagnostic, @@ -427,24 +425,6 @@ pub struct UndefinedBehavior { pub raw_bytes: RawBytesNote, } -pub struct DebugExt<T>(T); - -impl<T: ReportErrorExt> fmt::Debug for DebugExt<T> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let s = ty::tls::with(|tcx| { - let mut builder = tcx.sess.struct_allow(""); - let handler = &tcx.sess.parse_sess.span_diagnostic; - let message = self.0.diagnostic_message(); - self.0.add_args(handler, &mut builder); - let s = handler.eagerly_translate_to_string(message, builder.args()); - builder.cancel(); - s - }); - - f.write_str(&s) - } -} - pub trait ReportErrorExt { /// Returns the diagnostic message for this error. fn diagnostic_message(&self) -> DiagnosticMessage; @@ -454,11 +434,19 @@ pub trait ReportErrorExt { builder: &mut DiagnosticBuilder<'_, G>, ); - fn debug(self) -> DebugExt<Self> + fn debug(self) -> String where Self: Sized, { - DebugExt(self) + ty::tls::with(move |tcx| { + let mut builder = tcx.sess.struct_allow(DiagnosticMessage::Str(String::new().into())); + let handler = &tcx.sess.parse_sess.span_diagnostic; + let message = self.diagnostic_message(); + self.add_args(handler, &mut builder); + let s = handler.eagerly_translate_to_string(message, builder.args()); + builder.cancel(); + s + }) } } @@ -481,7 +469,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> { use crate::fluent_generated::*; use UndefinedBehaviorInfo::*; match self { - Ub(msg) => (&**msg).into(), + Ub(msg) => msg.clone().into(), Unreachable => const_eval_unreachable, BoundsCheckFailed { .. } => const_eval_bounds_check_failed, DivisionByZero => const_eval_division_by_zero, |
