File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed
rust/ql/src/queries/unusedentities Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE qhelp PUBLIC
2+ "-//Semmle//qhelp//EN"
3+ "qhelp.dtd">
4+ <qhelp >
5+
6+ <overview >
7+ <p >This rule finds code that is never reached. Unused code should be removed to increase readability and avoid confusion.</p >
8+ </overview >
9+
10+ <recommendation >
11+ <p >Remove any unreachable code.</p >
12+ </recommendation >
13+
14+ <example >
15+ <p >In the following example, the final <code >return</code > statement can never be reached:</p >
16+ <sample src =" UnreachableCodeBad.rs" />
17+ <p >The problem can be fixed simply by removing the unreachable code:</p >
18+ <sample src =" UnreachableCodeGood.rs" />
19+ </example >
20+
21+ <references >
22+ <li >Wikipedia: <a href =" https://en.wikipedia.org/wiki/Unreachable_code" >Unreachable code</a ></li >
23+ </references >
24+ </qhelp >
Original file line number Diff line number Diff line change 1+ fn fib ( input : u32 ) -> u32 {
2+ if ( input == 0 ) {
3+ return 0 ;
4+ } else if ( input == 1 ) {
5+ return 1 ;
6+ } else {
7+ return fib ( input - 1 ) + fib ( input - 2 ) ;
8+ }
9+
10+ return input; // BAD: this code is never reached
11+ }
Original file line number Diff line number Diff line change 1+ fn fib ( input : u32 ) -> u32 {
2+ if ( input == 0 ) {
3+ return 0 ;
4+ } else if ( input == 1 ) {
5+ return 1 ;
6+ } else {
7+ return fib ( input - 1 ) + fib ( input - 2 ) ;
8+ }
9+ }
You can’t perform that action at this time.
0 commit comments