Skip to content

Commit 5d2f4a1

Browse files
committed
fix diagnostic message
1 parent 74a6803 commit 5d2f4a1

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

compiler/rustc_const_eval/src/errors.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fmt;
2-
31
use rustc_errors::{
42
DiagnosticArgValue, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, Handler,
53
IntoDiagnostic,
@@ -409,24 +407,6 @@ pub struct UndefinedBehavior {
409407
pub raw_bytes: RawBytesNote,
410408
}
411409

412-
pub struct DebugExt<T>(T);
413-
414-
impl<T: ReportErrorExt> fmt::Debug for DebugExt<T> {
415-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
416-
let s = ty::tls::with(|tcx| {
417-
let mut builder = tcx.sess.struct_allow("");
418-
let handler = &tcx.sess.parse_sess.span_diagnostic;
419-
let message = self.0.diagnostic_message();
420-
self.0.add_args(handler, &mut builder);
421-
let s = handler.eagerly_translate_to_string(message, builder.args());
422-
builder.cancel();
423-
s
424-
});
425-
426-
f.write_str(&s)
427-
}
428-
}
429-
430410
pub trait ReportErrorExt {
431411
/// Returns the diagnostic message for this error.
432412
fn diagnostic_message(&self) -> DiagnosticMessage;
@@ -436,11 +416,19 @@ pub trait ReportErrorExt {
436416
builder: &mut DiagnosticBuilder<'_, G>,
437417
);
438418

439-
fn debug(self) -> DebugExt<Self>
419+
fn debug(self) -> String
440420
where
441421
Self: Sized,
442422
{
443-
DebugExt(self)
423+
ty::tls::with(move |tcx| {
424+
let mut builder = tcx.sess.struct_allow(DiagnosticMessage::Str(String::new()));
425+
let handler = &tcx.sess.parse_sess.span_diagnostic;
426+
let message = self.diagnostic_message();
427+
self.add_args(handler, &mut builder);
428+
let s = handler.eagerly_translate_to_string(message, builder.args());
429+
builder.cancel();
430+
s
431+
})
444432
}
445433
}
446434

compiler/rustc_mir_transform/src/const_prop.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use either::Right;
55

66
use rustc_const_eval::const_eval::CheckAlignment;
7+
use rustc_const_eval::ReportErrorExt;
78
use rustc_data_structures::fx::FxHashSet;
89
use rustc_hir::def::DefKind;
910
use rustc_index::bit_set::BitSet;
@@ -378,7 +379,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
378379
op
379380
}
380381
Err(e) => {
381-
trace!("get_const failed: {:?}", e.debug());
382+
trace!("get_const failed: {:?}", e.into_kind().debug());
382383
return None;
383384
}
384385
};

compiler/rustc_mir_transform/src/const_prop_lint.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_const_eval::interpret::Immediate;
99
use rustc_const_eval::interpret::{
1010
self, InterpCx, InterpResult, LocalValue, MemoryKind, OpTy, Scalar, StackPopCleanup,
1111
};
12+
use rustc_const_eval::ReportErrorExt;
1213
use rustc_hir::def::DefKind;
1314
use rustc_hir::HirId;
1415
use rustc_index::bit_set::BitSet;
@@ -232,7 +233,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
232233
op
233234
}
234235
Err(e) => {
235-
trace!("get_const failed: {:?}", e.debug());
236+
trace!("get_const failed: {:?}", e.into_kind().debug());
236237
return None;
237238
}
238239
};

0 commit comments

Comments
 (0)