You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/basic-query-for-rust-code.rst
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
.. _basic-query-for-swift-code:
1
+
.. _basic-query-for-rust-code:
2
2
3
-
Basic query for Swift code
3
+
Basic query for Rust code
4
4
==========================
5
5
6
6
Learn to write and run a simple CodeQL query using Visual Studio Code with the CodeQL extension.
@@ -12,7 +12,7 @@ About the query
12
12
13
13
The query we're going to run performs a basic search of the code for ``if`` expressions that are redundant, in the sense that they have an empty ``then`` branch. For example, code such as:
14
14
15
-
.. code-block:: swift
15
+
.. code-block:: rust
16
16
17
17
if error {
18
18
// we should handle the error
@@ -29,20 +29,20 @@ Running a quick query
29
29
30
30
.. code-block:: ql
31
31
32
-
import swift
32
+
import rust
33
33
34
34
from IfStmt ifStmt
35
35
where ifStmt.getThen().(BraceStmt).getNumberOfElements() = 0
36
36
select ifStmt, "This 'if' statement is redundant."
| ``from IfStmt ifStmt`` | Defines the variables for the query. | We use: an ``IfStmt`` variable for ``if`` statements. |
61
61
|| Declarations are of the form: ||
@@ -81,7 +81,7 @@ Remove false positive results
81
81
82
82
Browsing the results of our basic query shows that it could be improved. Among the results you are likely to find examples of ``if`` statements with an ``else`` branch, where an empty ``then`` branch does serve a purpose. For example:
83
83
84
-
.. code-block:: swift
84
+
.. code-block:: rust
85
85
86
86
if (option == "-verbose") {
87
87
// nothing to do - handled earlier
@@ -114,17 +114,17 @@ To exclude ``if`` statements that have an ``else`` branch:
.. |result-col-1| replace:: The first column corresponds to the expression ``ifStmt`` and is linked to the location in the source code of the project where ``ifStmt`` occurs.
0 commit comments