@@ -34,18 +34,28 @@ pub mod process;
34
34
/// assert!(a + b == c, "The sum of {} and {} is {}", a, b, c);
35
35
/// ```
36
36
/// the assert message will be:
37
- /// "The sum of {} and {} is {}", 1, 1, 2
37
+ /// "The sum of {} and {} is {}", a, b, c
38
38
#[ macro_export]
39
39
macro_rules! assert {
40
40
( $cond: expr $( , ) ?) => {
41
41
kani:: assert( $cond, concat!( "assertion failed: " , stringify!( $cond) ) ) ;
42
42
} ;
43
43
( $cond: expr, $( $arg: tt) +) => {
44
- // Note that by stringifying the arguments to the custom message, any
45
- // compile-time checks on those arguments (e.g. checking that the symbol
46
- // is defined and that it implements the Display trait) are bypassed:
47
- // https://github.com/model-checking/kani/issues/803
48
44
kani:: assert( $cond, concat!( stringify!( $( $arg) +) ) ) ;
45
+ // Process the arguments of the assert inside an unreachable block. This
46
+ // is to make sure errors in the arguments (e.g. an unknown variable or
47
+ // an argument that does not implement the Display or Debug traits) are
48
+ // reported, without creating any overhead on verification performance
49
+ // that may arise from processing strings involved in the arguments.
50
+ // Note that this approach is only correct with the "abort" panic
51
+ // strategy, but is unsound with the "unwind" panic strategy which
52
+ // requires evaluating the arguments (because they might have side
53
+ // effects). This is fine until we add support for the "unwind" panic
54
+ // strategy, which is tracked in
55
+ // https://github.com/model-checking/kani/issues/692
56
+ if false {
57
+ let _ = format_args!( $( $arg) +) ;
58
+ }
49
59
} ;
50
60
}
51
61
@@ -100,7 +110,7 @@ macro_rules! debug_assert_ne {
100
110
( $( $x: tt) * ) => ( { $crate:: assert_ne!( $( $x) * ) ; } )
101
111
}
102
112
103
- // Override the print macros to skip all the formatting functionality (which
113
+ // Override the print macros to skip all the printing functionality (which
104
114
// is not relevant for verification)
105
115
#[ macro_export]
106
116
macro_rules! print {
0 commit comments