File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //@error-in-other-file: Unsat
2+ //@compile-flags: -Adead_code -C debug-assertions=off
3+
4+ // A is represented as Tuple<Int> in SMT-LIB2 format.
5+ struct A {
6+ x : i64 ,
7+ }
8+
9+ trait Double {
10+ // Support annotations in trait definitions
11+ #[ thrust:: predicate]
12+ fn is_double ( self , doubled : Self ) -> bool ;
13+
14+ // This annotations are applied to all implementors of the `Double` trait.
15+ #[ thrust:: requires( true ) ]
16+ #[ thrust:: ensures( is_double( * self , ^self ) ) ]
17+ fn double ( & mut self ) ;
18+ }
19+
20+ impl Double for A {
21+ // Write concrete definitions for predicates in `impl` blocks
22+ #[ thrust:: predicate]
23+ fn is_double ( self , doubled : Self ) -> bool {
24+ // (tuple_proj<Int>.0 self) is equivalent to self.x
25+ // self.x * 3 == doubled.x (this isn't actually doubled!) is written as following:
26+ "(=
27+ (* (tuple_proj<Int>.0 self) 3)
28+ (tuple_proj<Int>.0 doubled)
29+ )" ; true // This definition does not comply with annotations in trait!
30+ }
31+
32+ // Check if this method complies with annotations in
33+ // trait definition.
34+ fn double ( & mut self ) {
35+ self . x += self . x ;
36+ }
37+ }
38+
39+ fn main ( ) {
40+ let mut a = A { x : 3 } ;
41+ a. double ( ) ;
42+ assert ! ( a. x == 6 ) ;
43+ }
Original file line number Diff line number Diff line change 1+ //@check-pass
2+ //@compile-flags: -Adead_code -C debug-assertions=off
3+
4+ // A is represented as Tuple<Int> in SMT-LIB2 format.
5+ struct A {
6+ x : i64 ,
7+ }
8+
9+ trait Double {
10+ // Support annotations in trait definitions
11+ #[ thrust:: predicate]
12+ fn is_double ( self , doubled : Self ) -> bool ;
13+
14+ // This annotations are applied to all implementors of the `Double` trait.
15+ #[ thrust:: requires( true ) ]
16+ #[ thrust:: ensures( is_double( * self , ^self ) ) ]
17+ fn double ( & mut self ) ;
18+ }
19+
20+ impl Double for A {
21+ // Write concrete definitions for predicates in `impl` blocks
22+ #[ thrust:: predicate]
23+ fn is_double ( self , doubled : Self ) -> bool {
24+ // (tuple_proj<Int>.0 self) is equivalent to self.x
25+ // self.x * 2 == doubled.x is written as following:
26+ "(=
27+ (* (tuple_proj<Int>.0 self) 2)
28+ (tuple_proj<Int>.0 doubled)
29+ )" ; true
30+ }
31+
32+ // Check if this method complies with annotations in
33+ // trait definition.
34+ fn double ( & mut self ) {
35+ self . x += self . x ;
36+ }
37+ }
38+
39+ fn main ( ) {
40+ let mut a = A { x : 3 } ;
41+ a. double ( ) ;
42+ assert ! ( a. x == 6 ) ;
43+ }
You can’t perform that action at this time.
0 commit comments