@@ -188,8 +188,9 @@ impl<'tcx> From<InterpError<'tcx>> for InterpErrorInfo<'tcx> {
188188}
189189
190190/// Error information for when the program we executed turned out not to actually be a valid
191- /// program. This cannot happen in stand-alone Miri, but it can happen during CTFE/ConstProp
192- /// where we work on generic code or execution does not have all information available.
191+ /// program. This cannot happen in stand-alone Miri (except for layout errors that are only detect
192+ /// during monomorphization), but it can happen during CTFE/ConstProp where we work on generic code
193+ /// or execution does not have all information available.
193194#[ derive( Debug ) ]
194195pub enum InvalidProgramInfo < ' tcx > {
195196 /// Resolution can fail if we are in a too generic context.
@@ -507,7 +508,7 @@ pub enum ValidationErrorKind<'tcx> {
507508/// Miri engine, e.g., CTFE does not support dereferencing pointers at integral addresses.
508509#[ derive( Debug ) ]
509510pub enum UnsupportedOpInfo {
510- /// Free-form case. Only for errors that are never caught!
511+ /// Free-form case. Only for errors that are never caught! Used by Miri.
511512 // FIXME still use translatable diagnostics
512513 Unsupported ( String ) ,
513514 /// Unsized local variables.
@@ -592,3 +593,117 @@ impl InterpError<'_> {
592593 )
593594 }
594595}
596+
597+ // Macros for constructing / throwing `InterpError`
598+ #[ macro_export]
599+ macro_rules! err_unsup {
600+ ( $( $tt: tt) * ) => {
601+ $crate:: mir:: interpret:: InterpError :: Unsupported (
602+ $crate:: mir:: interpret:: UnsupportedOpInfo :: $( $tt) *
603+ )
604+ } ;
605+ }
606+
607+ #[ macro_export]
608+ macro_rules! err_unsup_format {
609+ ( $( $tt: tt) * ) => { $crate:: err_unsup!( Unsupported ( format!( $( $tt) * ) ) ) } ;
610+ }
611+
612+ #[ macro_export]
613+ macro_rules! err_inval {
614+ ( $( $tt: tt) * ) => {
615+ $crate:: mir:: interpret:: InterpError :: InvalidProgram (
616+ $crate:: mir:: interpret:: InvalidProgramInfo :: $( $tt) *
617+ )
618+ } ;
619+ }
620+
621+ #[ macro_export]
622+ macro_rules! err_ub {
623+ ( $( $tt: tt) * ) => {
624+ $crate:: mir:: interpret:: InterpError :: UndefinedBehavior (
625+ $crate:: mir:: interpret:: UndefinedBehaviorInfo :: $( $tt) *
626+ )
627+ } ;
628+ }
629+
630+ #[ macro_export]
631+ macro_rules! err_ub_format {
632+ ( $( $tt: tt) * ) => { $crate:: err_ub!( Ub ( format!( $( $tt) * ) ) ) } ;
633+ }
634+
635+ #[ macro_export]
636+ macro_rules! err_ub_custom {
637+ ( $msg: expr $( , $( $name: ident = $value: expr) ,* $( , ) ?) ?) => { {
638+ $(
639+ let ( $( $name, ) * ) = ( $( $value, ) * ) ;
640+ ) ?
641+ $crate:: err_ub!( Custom (
642+ $crate:: error:: CustomSubdiagnostic {
643+ msg: || $msg,
644+ add_args: Box :: new( move |mut set_arg| {
645+ $( $(
646+ set_arg( stringify!( $name) . into( ) , rustc_errors:: IntoDiagArg :: into_diag_arg( $name) ) ;
647+ ) * ) ?
648+ } )
649+ }
650+ ) )
651+ } } ;
652+ }
653+
654+ #[ macro_export]
655+ macro_rules! err_exhaust {
656+ ( $( $tt: tt) * ) => {
657+ $crate:: mir:: interpret:: InterpError :: ResourceExhaustion (
658+ $crate:: mir:: interpret:: ResourceExhaustionInfo :: $( $tt) *
659+ )
660+ } ;
661+ }
662+
663+ #[ macro_export]
664+ macro_rules! err_machine_stop {
665+ ( $( $tt: tt) * ) => {
666+ $crate:: mir:: interpret:: InterpError :: MachineStop ( Box :: new( $( $tt) * ) )
667+ } ;
668+ }
669+
670+ // In the `throw_*` macros, avoid `return` to make them work with `try {}`.
671+ #[ macro_export]
672+ macro_rules! throw_unsup {
673+ ( $( $tt: tt) * ) => { do yeet $crate:: err_unsup!( $( $tt) * ) } ;
674+ }
675+
676+ #[ macro_export]
677+ macro_rules! throw_unsup_format {
678+ ( $( $tt: tt) * ) => { do yeet $crate:: err_unsup_format!( $( $tt) * ) } ;
679+ }
680+
681+ #[ macro_export]
682+ macro_rules! throw_inval {
683+ ( $( $tt: tt) * ) => { do yeet $crate:: err_inval!( $( $tt) * ) } ;
684+ }
685+
686+ #[ macro_export]
687+ macro_rules! throw_ub {
688+ ( $( $tt: tt) * ) => { do yeet $crate:: err_ub!( $( $tt) * ) } ;
689+ }
690+
691+ #[ macro_export]
692+ macro_rules! throw_ub_format {
693+ ( $( $tt: tt) * ) => { do yeet $crate:: err_ub_format!( $( $tt) * ) } ;
694+ }
695+
696+ #[ macro_export]
697+ macro_rules! throw_ub_custom {
698+ ( $( $tt: tt) * ) => { do yeet $crate:: err_ub_custom!( $( $tt) * ) } ;
699+ }
700+
701+ #[ macro_export]
702+ macro_rules! throw_exhaust {
703+ ( $( $tt: tt) * ) => { do yeet $crate:: err_exhaust!( $( $tt) * ) } ;
704+ }
705+
706+ #[ macro_export]
707+ macro_rules! throw_machine_stop {
708+ ( $( $tt: tt) * ) => { do yeet $crate:: err_machine_stop!( $( $tt) * ) } ;
709+ }
0 commit comments