-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rust: Add qhelp and example for the unused variable query.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE qhelp PUBLIC | ||
"-//Semmle//qhelp//EN" | ||
"qhelp.dtd"> | ||
<qhelp> | ||
|
||
<overview> | ||
<p>This rule finds variables that are never accessed. Unused variables should be removed to increase readability and avoid confusion.</p> | ||
</overview> | ||
|
||
<recommendation> | ||
<p>Remove any unused variables.</p> | ||
</recommendation> | ||
|
||
<example> | ||
<p>In the following example, there is an unused variable <code>average</code> that is never used:</p> | ||
<sample src="UnusedVariableBad.rs" /> | ||
<p>The problem can be fixed simply by removing the variable:</p> | ||
<sample src="UnusedVariableGood.rs" /> | ||
</example> | ||
|
||
<references> | ||
<li>GeeksforGeeks: <a href="https://www.geeksforgeeks.org/how-to-avoid-unused-variable-warning-in-rust/">How to avoid unused Variable warning in Rust?</a></li> | ||
</references> | ||
</qhelp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
fn get_sum(values:&[i32]) -> i32 { | ||
let mut sum = 0; | ||
let mut average; // BAD: unused variable | ||
|
||
for v in values { | ||
sum += v; | ||
} | ||
|
||
return sum; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn get_sum(values:&[i32]) -> i32 { | ||
let mut sum = 0; | ||
|
||
for v in values { | ||
sum += v; | ||
} | ||
|
||
return sum; | ||
} |