Skip to content

Commit d79aa07

Browse files
committed
Rust: Clean up the UnusedValue examples.
1 parent 463a125 commit d79aa07

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

rust/ql/src/queries/unusedentities/UnusedValue.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<example>
1515
<p>In the following example, there is a variable <code>average</code> that is initialized to <code>0</code>, but that value is never used:</p>
1616
<sample src="UnusedValueBad.rs" />
17-
<p>The problem can be fixed by removing the value and the variable that contains it:</p>
17+
<p>The problem can be fixed by removing the unused value:</p>
1818
<sample src="UnusedValueGood.rs" />
1919
</example>
2020

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
fn get_average(values:&[i32]) -> i32 {
1+
fn get_average(values:&[i32]) -> f64 {
22
let mut sum = 0;
3-
let mut average = 0; // BAD: unused value
3+
let mut average = 0.0; // BAD: unused value
44

55
for v in values {
66
sum += v;
77
}
88

9-
average = sum / values.len();
9+
average = sum as f64 / values.len() as f64;
1010
return average;
1111
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
fn get_sum(values:&[i32]) -> i32 {
1+
fn get_average(values:&[i32]) -> f64 {
22
let mut sum = 0;
3+
let average;
34

45
for v in values {
56
sum += v;
67
}
78

8-
return sum;
9+
average = sum as f64 / values.len() as f64;
10+
return average;
911
}

0 commit comments

Comments
 (0)