@@ -24,43 +24,25 @@ use super::{
2424} ;
2525
2626macro_rules! throw_validation_failure {
27- ( $what: expr, $where: expr, $details: expr) => { {
28- let mut msg = format!( "encountered {}" , $what) ;
29- let where_ = & $where;
30- if !where_. is_empty( ) {
31- msg. push_str( " at " ) ;
32- write_path( & mut msg, where_) ;
33- }
34- write!( & mut msg, ", but expected {}" , $details) . unwrap( ) ;
35- throw_ub!( ValidationFailure ( msg) )
36- } } ;
37- ( $what: expr, $where: expr) => { {
27+ ( $what: expr, $where: expr $( , $details: expr ) ?) => { {
3828 let mut msg = format!( "encountered {}" , $what) ;
3929 let where_ = & $where;
4030 if !where_. is_empty( ) {
4131 msg. push_str( " at " ) ;
4232 write_path( & mut msg, where_) ;
4333 }
34+ $( write!( & mut msg, ", but expected {}" , $details) . unwrap( ) ; ) ?
4435 throw_ub!( ValidationFailure ( msg) )
4536 } } ;
4637}
4738
4839macro_rules! try_validation {
49- ( $e: expr, $what: expr, $where: expr, $details: expr) => { {
50- match $e {
51- Ok ( x) => x,
52- // We re-throw the error, so we are okay with allocation:
53- // this can only slow down builds that fail anyway.
54- Err ( _) => throw_validation_failure!( $what, $where, $details) ,
55- }
56- } } ;
57-
58- ( $e: expr, $what: expr, $where: expr) => { {
40+ ( $e: expr, $what: expr, $where: expr $( , $details: expr ) ?) => { {
5941 match $e {
6042 Ok ( x) => x,
61- // We re-throw the error, so we are okay with allocation:
62- // this can only slow down builds that fail anyway.
63- Err ( _) => throw_validation_failure!( $what, $where) ,
43+ // We catch the error and turn it into a validation failure. We are okay with
44+ // allocation here as this can only slow down builds that fail anyway.
45+ Err ( _) => throw_validation_failure!( $what, $where $ ( , $details ) ? ) ,
6446 }
6547 } } ;
6648}
0 commit comments