Skip to content

Commit 55121d8

Browse files
committed
Rust: Add CFG tests for method definitions with self parameters
1 parent 6a3e34c commit 55121d8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

rust/ql/test/library-tests/controlflow/Cfg.expected

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,36 @@ edges
10441044
| test.rs:490:5:490:19 | ExprStmt | test.rs:490:5:490:10 | nested | |
10451045
| test.rs:490:12:490:17 | RefExpr | test.rs:490:5:490:18 | CallExpr | |
10461046
| test.rs:490:17:490:17 | x | test.rs:490:12:490:17 | RefExpr | |
1047+
| test.rs:502:5:504:5 | enter new | test.rs:502:12:502:12 | a | |
1048+
| test.rs:502:5:504:5 | exit new (normal) | test.rs:502:5:504:5 | exit new | |
1049+
| test.rs:502:12:502:12 | a | test.rs:502:12:502:17 | Param | match |
1050+
| test.rs:502:12:502:17 | Param | test.rs:503:23:503:23 | a | |
1051+
| test.rs:502:28:504:5 | BlockExpr | test.rs:502:5:504:5 | exit new (normal) | |
1052+
| test.rs:503:9:503:25 | RecordExpr | test.rs:502:28:504:5 | BlockExpr | |
1053+
| test.rs:503:23:503:23 | a | test.rs:503:9:503:25 | RecordExpr | |
1054+
| test.rs:506:5:508:5 | enter negated | test.rs:507:23:507:26 | self | |
1055+
| test.rs:506:5:508:5 | exit negated (normal) | test.rs:506:5:508:5 | exit negated | |
1056+
| test.rs:506:30:508:5 | BlockExpr | test.rs:506:5:508:5 | exit negated (normal) | |
1057+
| test.rs:507:9:507:30 | RecordExpr | test.rs:506:30:508:5 | BlockExpr | |
1058+
| test.rs:507:23:507:26 | self | test.rs:507:23:507:28 | FieldExpr | |
1059+
| test.rs:507:23:507:28 | FieldExpr | test.rs:507:9:507:30 | RecordExpr | |
1060+
| test.rs:510:5:512:5 | enter multifly_add | test.rs:510:32:510:32 | a | |
1061+
| test.rs:510:5:512:5 | exit multifly_add (normal) | test.rs:510:5:512:5 | exit multifly_add | |
1062+
| test.rs:510:32:510:32 | a | test.rs:510:32:510:37 | Param | match |
1063+
| test.rs:510:32:510:37 | Param | test.rs:510:40:510:40 | b | |
1064+
| test.rs:510:40:510:40 | b | test.rs:510:40:510:45 | Param | match |
1065+
| test.rs:510:40:510:45 | Param | test.rs:511:9:511:34 | ExprStmt | |
1066+
| test.rs:510:48:512:5 | BlockExpr | test.rs:510:5:512:5 | exit multifly_add (normal) | |
1067+
| test.rs:511:9:511:12 | self | test.rs:511:9:511:14 | FieldExpr | |
1068+
| test.rs:511:9:511:14 | FieldExpr | test.rs:511:19:511:22 | self | |
1069+
| test.rs:511:9:511:33 | ... = ... | test.rs:510:48:512:5 | BlockExpr | |
1070+
| test.rs:511:9:511:34 | ExprStmt | test.rs:511:9:511:12 | self | |
1071+
| test.rs:511:18:511:33 | ... + ... | test.rs:511:9:511:33 | ... = ... | |
1072+
| test.rs:511:19:511:22 | self | test.rs:511:19:511:24 | FieldExpr | |
1073+
| test.rs:511:19:511:24 | FieldExpr | test.rs:511:28:511:28 | a | |
1074+
| test.rs:511:19:511:28 | ... * ... | test.rs:511:33:511:33 | b | |
1075+
| test.rs:511:28:511:28 | a | test.rs:511:19:511:28 | ... * ... | |
1076+
| test.rs:511:33:511:33 | b | test.rs:511:18:511:33 | ... + ... | |
10471077
breakTarget
10481078
| test.rs:34:17:34:21 | BreakExpr | test.rs:28:9:40:9 | LoopExpr |
10491079
| test.rs:48:21:48:25 | BreakExpr | test.rs:46:13:53:13 | LoopExpr |

rust/ql/test/library-tests/controlflow/test.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,21 @@ fn test_nested_function2() {
493493
trait MyFrom<T> {
494494
fn my_from(x: T) -> Self;
495495
}
496+
497+
struct MyNumber {
498+
n: i64,
499+
}
500+
501+
impl MyNumber {
502+
fn new(a: i64) -> Self {
503+
MyNumber { n: a }
504+
}
505+
506+
fn negated(self) -> Self {
507+
MyNumber { n: self.n }
508+
}
509+
510+
fn multifly_add(&mut self, a: i64, b: i64) {
511+
self.n = (self.n * a) + b;
512+
}
513+
}

0 commit comments

Comments
 (0)