1
Fork 0

Use translatable diagnostics in rustc_const_eval

This commit is contained in:
Deadbeef 2023-05-17 10:30:14 +00:00
parent 642c92e630
commit 4f83717cf7
93 changed files with 2375 additions and 1123 deletions

View file

@ -37,6 +37,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 +45,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)
}};
}
@ -367,7 +378,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
op
}
Err(e) => {
trace!("get_const failed: {}", e);
trace!("get_const failed: {e:?}");
return None;
}
};

View file

@ -232,7 +232,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
op
}
Err(e) => {
trace!("get_const failed: {}", e);
trace!("get_const failed: {e:?}");
return None;
}
};
@ -272,8 +272,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
}

View file

@ -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,
}