Skip to content

Commit 24adf07

Browse files
committed
Reuse throw_machine_stop_str! macro.
1 parent 4901893 commit 24adf07

File tree

3 files changed

+24
-53
lines changed

3 files changed

+24
-53
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

+21-23
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,30 @@ const MAX_ALLOC_LIMIT: u64 = 1024;
3232

3333
/// Macro for machine-specific `InterpError` without allocation.
3434
/// (These will never be shown to the user, but they help diagnose ICEs.)
35-
macro_rules! throw_machine_stop_str {
36-
($($tt:tt)*) => {{
37-
// We make a new local type for it. The type itself does not carry any information,
38-
// but its vtable (for the `MachineStopType` trait) does.
39-
#[derive(Debug)]
40-
struct Zst;
41-
// Printing this type shows the desired string.
42-
impl std::fmt::Display for Zst {
43-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44-
write!(f, $($tt)*)
45-
}
35+
pub(crate) macro throw_machine_stop_str($($tt:tt)*) {{
36+
// We make a new local type for it. The type itself does not carry any information,
37+
// but its vtable (for the `MachineStopType` trait) does.
38+
#[derive(Debug)]
39+
struct Zst;
40+
// Printing this type shows the desired string.
41+
impl std::fmt::Display for Zst {
42+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43+
write!(f, $($tt)*)
4644
}
45+
}
4746

48-
impl rustc_middle::mir::interpret::MachineStopType for Zst {
49-
fn diagnostic_message(&self) -> rustc_errors::DiagnosticMessage {
50-
self.to_string().into()
51-
}
52-
53-
fn add_args(
54-
self: Box<Self>,
55-
_: &mut dyn FnMut(std::borrow::Cow<'static, str>, rustc_errors::DiagnosticArgValue<'static>),
56-
) {}
47+
impl rustc_middle::mir::interpret::MachineStopType for Zst {
48+
fn diagnostic_message(&self) -> rustc_errors::DiagnosticMessage {
49+
self.to_string().into()
5750
}
58-
throw_machine_stop!(Zst)
59-
}};
60-
}
51+
52+
fn add_args(
53+
self: Box<Self>,
54+
_: &mut dyn FnMut(std::borrow::Cow<'static, str>, rustc_errors::DiagnosticArgValue<'static>),
55+
) {}
56+
}
57+
throw_machine_stop!(Zst)
58+
}}
6159

6260
pub struct ConstProp;
6361

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+2-30
Original file line numberDiff line numberDiff line change
@@ -684,34 +684,6 @@ impl<'tcx> Visitor<'tcx> for OperandCollector<'tcx, '_, '_, '_> {
684684

685685
struct DummyMachine;
686686

687-
/// Macro for machine-specific `InterpError` without allocation.
688-
/// (These will never be shown to the user, but they help diagnose ICEs.)
689-
macro_rules! throw_machine_stop_str {
690-
($($tt:tt)*) => {{
691-
// We make a new local type for it. The type itself does not carry any information,
692-
// but its vtable (for the `MachineStopType` trait) does.
693-
#[derive(Debug)]
694-
struct Zst;
695-
// Printing this type shows the desired string.
696-
impl std::fmt::Display for Zst {
697-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
698-
write!(f, $($tt)*)
699-
}
700-
}
701-
impl rustc_middle::mir::interpret::MachineStopType for Zst {
702-
fn diagnostic_message(&self) -> rustc_errors::DiagnosticMessage {
703-
self.to_string().into()
704-
}
705-
706-
fn add_args(
707-
self: Box<Self>,
708-
_: &mut dyn FnMut(std::borrow::Cow<'static, str>, rustc_errors::DiagnosticArgValue<'static>),
709-
) {}
710-
}
711-
throw_machine_stop!(Zst)
712-
}};
713-
}
714-
715687
impl<'mir, 'tcx: 'mir> rustc_const_eval::interpret::Machine<'mir, 'tcx> for DummyMachine {
716688
rustc_const_eval::interpret::compile_time_machine!(<'mir, 'tcx>);
717689
type MemoryKind = !;
@@ -750,13 +722,13 @@ impl<'mir, 'tcx: 'mir> rustc_const_eval::interpret::Machine<'mir, 'tcx> for Dumm
750722
is_write: bool,
751723
) -> InterpResult<'tcx> {
752724
if is_write {
753-
throw_machine_stop_str!("can't write to global");
725+
crate::const_prop::throw_machine_stop_str!("can't write to global");
754726
}
755727

756728
// If the static allocation is mutable, then we can't const prop it as its content
757729
// might be different at runtime.
758730
if alloc.inner().mutability.is_mut() {
759-
throw_machine_stop_str!("can't access mutable globals in ConstProp");
731+
crate::const_prop::throw_machine_stop_str!("can't access mutable globals in ConstProp");
760732
}
761733

762734
Ok(())

compiler/rustc_mir_transform/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![deny(rustc::untranslatable_diagnostic)]
33
#![deny(rustc::diagnostic_outside_of_impl)]
44
#![feature(box_patterns)]
5+
#![feature(decl_macro)]
56
#![feature(is_sorted)]
67
#![feature(let_chains)]
78
#![feature(map_try_insert)]

0 commit comments

Comments
 (0)