@@ -22,28 +22,23 @@ use super::{
22
22
23
23
macro_rules! throw_validation_failure {
24
24
( $what: expr, $where: expr, $details: expr) => { {
25
- let where_ = path_format( & $where) ;
26
- let where_ = if where_. is_empty( ) {
27
- String :: new( )
28
- } else {
29
- format!( " at {}" , where_)
30
- } ;
31
- throw_unsup!( ValidationFailure ( format!(
32
- "encountered {}{}, but expected {}" ,
33
- $what, where_, $details,
34
- ) ) )
25
+ let mut msg = format!( "encountered {}" , $what) ;
26
+ let where_ = & $where;
27
+ if !where_. is_empty( ) {
28
+ msg. push_str( " at " ) ;
29
+ write_path( & mut msg, where_) ;
30
+ }
31
+ write!( & mut msg, ", but expected {}" , $details) . unwrap( ) ;
32
+ throw_unsup!( ValidationFailure ( msg) )
35
33
} } ;
36
34
( $what: expr, $where: expr) => { {
37
- let where_ = path_format( & $where) ;
38
- let where_ = if where_. is_empty( ) {
39
- String :: new( )
40
- } else {
41
- format!( " at {}" , where_)
42
- } ;
43
- throw_unsup!( ValidationFailure ( format!(
44
- "encountered {}{}" ,
45
- $what, where_,
46
- ) ) )
35
+ let mut msg = format!( "encountered {}" , $what) ;
36
+ let where_ = & $where;
37
+ if !where_. is_empty( ) {
38
+ msg. push_str( " at " ) ;
39
+ write_path( & mut msg, where_) ;
40
+ }
41
+ throw_unsup!( ValidationFailure ( msg) )
47
42
} } ;
48
43
}
49
44
@@ -113,10 +108,9 @@ impl<T: Copy + Eq + Hash + std::fmt::Debug, PATH: Default> RefTracking<T, PATH>
113
108
}
114
109
115
110
/// Format a path
116
- fn path_format ( path : & Vec < PathElem > ) -> String {
111
+ fn write_path ( out : & mut String , path : & Vec < PathElem > ) {
117
112
use self :: PathElem :: * ;
118
113
119
- let mut out = String :: new ( ) ;
120
114
for elem in path. iter ( ) {
121
115
match elem {
122
116
Field ( name) => write ! ( out, ".{}" , name) ,
@@ -135,7 +129,6 @@ fn path_format(path: &Vec<PathElem>) -> String {
135
129
DynDowncast => write ! ( out, ".<dyn-downcast>" ) ,
136
130
} . unwrap ( )
137
131
}
138
- out
139
132
}
140
133
141
134
// Test if a range that wraps at overflow contains `test`
0 commit comments