Skip to content

Commit fd5d625

Browse files
committed
Rust: Avoid creating CFG scopes for trait signatures without implementations
1 parent b0cd44e commit fd5d625

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

rust/ql/lib/codeql/rust/controlflow/internal/Scope.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ abstract class CfgScope extends AstNode {
1212
}
1313

1414
final class FunctionScope extends CfgScope, Function {
15+
FunctionScope() {
16+
// A function without a body corresponds to a trait method signature and
17+
// should not have a CFG scope.
18+
this.hasBody()
19+
}
20+
1521
override predicate scopeFirst(AstNode node) {
1622
first(this.(FunctionTree).getFirstChildNode(), node)
1723
}

rust/ql/test/library-tests/controlflow/Cfg.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,6 @@ edges
796796
| test.rs:381:5:381:19 | ExprStmt | test.rs:381:5:381:10 | PathExpr | |
797797
| test.rs:381:12:381:17 | RefExpr | test.rs:381:5:381:18 | CallExpr | |
798798
| test.rs:381:17:381:17 | x | test.rs:381:12:381:17 | RefExpr | |
799-
| test.rs:385:5:385:29 | enter my_from | test.rs:385:16:385:16 | x | |
800-
| test.rs:385:16:385:16 | x | test.rs:385:16:385:19 | Param | match |
801799
breakTarget
802800
| test.rs:25:17:25:21 | BreakExpr | test.rs:19:9:31:9 | LoopExpr |
803801
| test.rs:39:21:39:25 | BreakExpr | test.rs:37:13:44:13 | LoopExpr |

0 commit comments

Comments
 (0)