Auto merge of #111677 - fee1-dead-contrib:rustc_const_eval-translatable, r=oli-obk,RalfJung
Use translatable diagnostics in `rustc_const_eval` This PR: * adds a `no_span` parameter to `note` / `help` attributes when using `Subdiagnostic` to allow adding notes/helps without using a span * has minor tweaks and changes to error messages
This commit is contained in:
commit
33c3d10128
93 changed files with 2385 additions and 1128 deletions
|
@ -4,6 +4,7 @@
|
|||
use either::Right;
|
||||
|
||||
use rustc_const_eval::const_eval::CheckAlignment;
|
||||
use rustc_const_eval::ReportErrorExt;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
|
@ -37,6 +38,7 @@ macro_rules! throw_machine_stop_str {
|
|||
($($tt:tt)*) => {{
|
||||
// We make a new local type for it. The type itself does not carry any information,
|
||||
// but its vtable (for the `MachineStopType` trait) does.
|
||||
#[derive(Debug)]
|
||||
struct Zst;
|
||||
// Printing this type shows the desired string.
|
||||
impl std::fmt::Display for Zst {
|
||||
|
@ -44,7 +46,17 @@ macro_rules! throw_machine_stop_str {
|
|||
write!(f, $($tt)*)
|
||||
}
|
||||
}
|
||||
impl rustc_middle::mir::interpret::MachineStopType for Zst {}
|
||||
|
||||
impl rustc_middle::mir::interpret::MachineStopType for Zst {
|
||||
fn diagnostic_message(&self) -> rustc_errors::DiagnosticMessage {
|
||||
self.to_string().into()
|
||||
}
|
||||
|
||||
fn add_args(
|
||||
self: Box<Self>,
|
||||
_: &mut dyn FnMut(std::borrow::Cow<'static, str>, rustc_errors::DiagnosticArgValue<'static>),
|
||||
) {}
|
||||
}
|
||||
throw_machine_stop!(Zst)
|
||||
}};
|
||||
}
|
||||
|
@ -374,7 +386,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
op
|
||||
}
|
||||
Err(e) => {
|
||||
trace!("get_const failed: {}", e);
|
||||
trace!("get_const failed: {:?}", e.into_kind().debug());
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -9,6 +9,7 @@ use rustc_const_eval::interpret::Immediate;
|
|||
use rustc_const_eval::interpret::{
|
||||
self, InterpCx, InterpResult, LocalValue, MemoryKind, OpTy, Scalar, StackPopCleanup,
|
||||
};
|
||||
use rustc_const_eval::ReportErrorExt;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
|
@ -232,7 +233,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
op
|
||||
}
|
||||
Err(e) => {
|
||||
trace!("get_const failed: {}", e);
|
||||
trace!("get_const failed: {:?}", e.into_kind().debug());
|
||||
return None;
|
||||
}
|
||||
};
|
||||
|
@ -272,8 +273,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
// dedicated error variants should be introduced instead.
|
||||
assert!(
|
||||
!error.kind().formatted_string(),
|
||||
"const-prop encountered formatting error: {}",
|
||||
error
|
||||
"const-prop encountered formatting error: {error:?}",
|
||||
);
|
||||
None
|
||||
}
|
||||
|
|
|
@ -163,7 +163,14 @@ impl<'a, P: std::fmt::Debug> DecorateLint<'a, ()> for AssertLint<P> {
|
|||
self,
|
||||
diag: &'b mut DiagnosticBuilder<'a, ()>,
|
||||
) -> &'b mut DiagnosticBuilder<'a, ()> {
|
||||
diag.span_label(self.span(), format!("{:?}", self.panic()));
|
||||
let span = self.span();
|
||||
let assert_kind = self.panic();
|
||||
let message = assert_kind.diagnostic_message();
|
||||
assert_kind.add_args(&mut |name, value| {
|
||||
diag.set_arg(name, value);
|
||||
});
|
||||
diag.span_label(span, message);
|
||||
|
||||
diag
|
||||
}
|
||||
|
||||
|
@ -191,7 +198,7 @@ impl<P> AssertLint<P> {
|
|||
AssertLint::ArithmeticOverflow(sp, _) | AssertLint::UnconditionalPanic(sp, _) => *sp,
|
||||
}
|
||||
}
|
||||
pub fn panic(&self) -> &AssertKind<P> {
|
||||
pub fn panic(self) -> AssertKind<P> {
|
||||
match self {
|
||||
AssertLint::ArithmeticOverflow(_, p) | AssertLint::UnconditionalPanic(_, p) => p,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue