@@ -25,23 +25,25 @@ use super::{
25
25
} ;
26
26
27
27
macro_rules! throw_validation_failure {
28
- ( $what: expr, $where: expr $( , $details : expr ) ?) => { {
28
+ ( $what: expr, $where: expr $( , $expected : expr ) ?) => { {
29
29
let mut msg = format!( "encountered {}" , $what) ;
30
30
let where_ = & $where;
31
31
if !where_. is_empty( ) {
32
32
msg. push_str( " at " ) ;
33
33
write_path( & mut msg, where_) ;
34
34
}
35
- $( write!( & mut msg, ", but expected {}" , $details ) . unwrap( ) ; ) ?
35
+ $( write!( & mut msg, ", but expected {}" , $expected ) . unwrap( ) ; ) ?
36
36
throw_ub!( ValidationFailure ( msg) )
37
37
} } ;
38
38
}
39
39
40
40
/// Returns a validation failure for any Err value of $e.
41
41
// FIXME: Replace all usages of try_validation! with try_validation_pat!.
42
42
macro_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
+ } )
45
47
} } ;
46
48
}
47
49
/// 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 {
54
56
/// // unchanged.
55
57
/// ```
56
58
macro_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 } ) ? $ ( , ) ? } ) => { {
58
60
match $e {
59
61
Ok ( x) => x,
60
62
// We catch the error and turn it into a validation failure. We are okay with
61
63
// 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 ) ?) ,
63
65
#[ allow( unreachable_patterns) ]
64
66
Err ( e) => Err :: <!, _>( e) ?,
65
67
}
@@ -493,12 +495,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
493
495
// We are conservative with undef for integers, but try to
494
496
// actually enforce the strict rules for raw pointers (mostly because
495
497
// 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
+ } ) ;
502
501
if place. layout . is_unsized ( ) {
503
502
self . check_wide_ptr_meta ( place. meta , place. layout ) ?;
504
503
}
0 commit comments