Skip to content

Commit 51ae7c6

Browse files
committed
Rust: Reorganize pointers tests and add additional tests
1 parent cc5179a commit 51ae7c6

File tree

3 files changed

+398
-247
lines changed

3 files changed

+398
-247
lines changed

rust/ql/test/library-tests/dataflow/global/main.rs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ struct MyFlag {
6464
}
6565

6666
impl MyFlag {
67-
fn data_in(&self, n: i64) {
67+
fn data_in(self, n: i64) {
6868
sink(n); // $ hasValueFlow=1 hasValueFlow=8
6969
}
7070

71-
fn get_data(&self) -> i64 {
71+
fn get_data(self) -> i64 {
7272
if self.flag {
7373
0
7474
} else {
7575
source(2)
7676
}
7777
}
7878

79-
fn data_through(&self, n: i64) -> i64 {
79+
fn data_through(self, n: i64) -> i64 {
8080
if self.flag {
8181
0
8282
} else {
@@ -107,13 +107,13 @@ fn data_through_method() {
107107
fn data_in_to_method_called_as_function() {
108108
let mn = MyFlag { flag: true };
109109
let a = source(8);
110-
MyFlag::data_in(&mn, a);
110+
MyFlag::data_in(mn, a);
111111
}
112112

113113
fn data_through_method_called_as_function() {
114114
let mn = MyFlag { flag: true };
115115
let a = source(12);
116-
let b = MyFlag::data_through(&mn, a);
116+
let b = MyFlag::data_through(mn, a);
117117
sink(b); // $ hasValueFlow=12
118118
}
119119

@@ -223,29 +223,6 @@ fn test_async_await() {
223223
futures::executor::block_on(test_async_await_async_part());
224224
}
225225

226-
// Flow out of mutable parameters.
227-
228-
fn set_int(n: &mut i64, c: i64) {
229-
*n = c;
230-
}
231-
232-
fn mutates_argument_1() {
233-
// Passing an already borrowed value to a function and then reading from the same borrow.
234-
let mut n = 0;
235-
let m = &mut n;
236-
sink(*m);
237-
set_int(m, source(37));
238-
sink(*m); // $ hasValueFlow=37
239-
}
240-
241-
fn mutates_argument_2() {
242-
// Borrowing at the call and then reading from the unborrowed variable.
243-
let mut n = 0;
244-
sink(n);
245-
set_int(&mut n, source(88));
246-
sink(n); // $ MISSING: hasValueFlow=88
247-
}
248-
249226
fn main() {
250227
data_out_of_call();
251228
data_in_to_call();
@@ -258,6 +235,4 @@ fn main() {
258235

259236
test_operator_overloading();
260237
test_async_await();
261-
mutates_argument_1();
262-
mutates_argument_2();
263238
}

0 commit comments

Comments
 (0)