@@ -24,43 +24,25 @@ use super::{
24
24
} ;
25
25
26
26
macro_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 ) ?) => { {
38
28
let mut msg = format!( "encountered {}" , $what) ;
39
29
let where_ = & $where;
40
30
if !where_. is_empty( ) {
41
31
msg. push_str( " at " ) ;
42
32
write_path( & mut msg, where_) ;
43
33
}
34
+ $( write!( & mut msg, ", but expected {}" , $details) . unwrap( ) ; ) ?
44
35
throw_ub!( ValidationFailure ( msg) )
45
36
} } ;
46
37
}
47
38
48
39
macro_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 ) ?) => { {
59
41
match $e {
60
42
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 ) ? ) ,
64
46
}
65
47
} } ;
66
48
}
0 commit comments