@@ -25,23 +25,25 @@ use super::{
2525} ;
2626
2727macro_rules! throw_validation_failure {
28- ( $what: expr, $where: expr $( , $details : expr ) ?) => { {
28+ ( $what: expr, $where: expr $( , $expected : expr ) ?) => { {
2929 let mut msg = format!( "encountered {}" , $what) ;
3030 let where_ = & $where;
3131 if !where_. is_empty( ) {
3232 msg. push_str( " at " ) ;
3333 write_path( & mut msg, where_) ;
3434 }
35- $( write!( & mut msg, ", but expected {}" , $details ) . unwrap( ) ; ) ?
35+ $( write!( & mut msg, ", but expected {}" , $expected ) . unwrap( ) ; ) ?
3636 throw_ub!( ValidationFailure ( msg) )
3737 } } ;
3838}
3939
4040/// Returns a validation failure for any Err value of $e.
4141// FIXME: Replace all usages of try_validation! with try_validation_pat!.
4242macro_rules! try_validation {
43- ( $e: expr, $what: expr, $where: expr $( , $details: expr ) ?) => { {
44- try_validation_pat!( $e, _, $what, $where $( , $details ) ?)
43+ ( $e: expr, $what: expr, $where: expr $( , $expected: expr ) ?) => { {
44+ try_validation_pat!( $e, $where, {
45+ _ => { $what } $( expected { $expected } ) ?,
46+ } )
4547 } } ;
4648}
4749/// Like try_validation, but will throw a validation error if any of the patterns in $p are
@@ -54,12 +56,12 @@ macro_rules! try_validation {
5456/// // unchanged.
5557/// ```
5658macro_rules! try_validation_pat {
57- ( $e: expr, $( $p: pat ) |* , $what: expr , $where : expr $( , $details : expr ) ? ) => { {
59+ ( $e: expr, $where : expr , { $ ( $p: pat ) |* => { $what: tt } $( expected { $expected : expr } ) ? $ ( , ) ? } ) => { {
5860 match $e {
5961 Ok ( x) => x,
6062 // We catch the error and turn it into a validation failure. We are okay with
6163 // allocation here as this can only slow down builds that fail anyway.
62- $( Err ( InterpErrorInfo { kind: $p, .. } ) ) |* => throw_validation_failure!( $what, $where $( , $details ) ?) ,
64+ $( Err ( InterpErrorInfo { kind: $p, .. } ) ) |* => throw_validation_failure!( $what, $where $( , $expected ) ?) ,
6365 #[ allow( unreachable_patterns) ]
6466 Err ( e) => Err :: <!, _>( e) ?,
6567 }
@@ -493,12 +495,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
493495 // We are conservative with undef for integers, but try to
494496 // actually enforce the strict rules for raw pointers (mostly because
495497 // that lets us re-use `ref_to_mplace`).
496- let place = try_validation_pat ! (
497- self . ecx. ref_to_mplace( self . ecx. read_immediate( value) ?) ,
498- err_ub!( InvalidUndefBytes ( ..) ) ,
499- "uninitialized raw pointer" ,
500- self . path
501- ) ;
498+ let place = try_validation_pat ! ( self . ecx. ref_to_mplace( self . ecx. read_immediate( value) ?) , self . path, {
499+ err_ub!( InvalidUndefBytes ( ..) ) => { "uninitialized raw pointer" } ,
500+ } ) ;
502501 if place. layout . is_unsized ( ) {
503502 self . check_wide_ptr_meta ( place. meta , place. layout ) ?;
504503 }
0 commit comments