Skip to content

Commit 980ed23

Browse files
authored
Merge pull request #18922 from paldepind/rust-model-generation-require-name
Rust: Exclude functions without canonical path from model generation
2 parents 45c4f3f + c89e648 commit 980ed23

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

rust/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ module ModelGeneratorInput implements ModelGeneratorInputSig<Location, RustDataF
2828
}
2929

3030
private predicate relevant(Function api) {
31-
// This excludes closures (these are not exported API endpoints) and
32-
// functions without a `pub` visiblity. A function can be `pub` without
33-
// ultimately being exported by a crate, so this is an overapproximation.
34-
api.hasVisibility()
35-
or
36-
// If a method implements a public trait it is exposed through the trait.
37-
// We overapproximate this by including all trait method implementations.
38-
exists(Impl impl | impl.hasTrait() and impl.getAssocItemList().getAssocItem(_) = api)
31+
// Only include functions that have a resolved path.
32+
api.hasCrateOrigin() and
33+
api.hasExtendedCanonicalPath() and
34+
(
35+
// This excludes closures (these are not exported API endpoints) and
36+
// functions without a `pub` visiblity. A function can be `pub` without
37+
// ultimately being exported by a crate, so this is an overapproximation.
38+
api.hasVisibility()
39+
or
40+
// If a method implements a public trait it is exposed through the trait.
41+
// We overapproximate this by including all trait method implementations.
42+
exists(Impl impl | impl.hasTrait() and impl.getAssocItemList().getAssocItem(_) = api)
43+
)
3944
}
4045

4146
predicate isUninterestingForDataFlowModels(Callable api) { none() }
@@ -169,12 +174,7 @@ module ModelGeneratorInput implements ModelGeneratorInputSig<Location, RustDataF
169174
}
170175

171176
string partialModelRow(Callable api, int i) {
172-
i = 0 and
173-
(
174-
result = api.(Function).getCrateOrigin()
175-
or
176-
not api.(Function).hasCrateOrigin() and result = ""
177-
) // crate
177+
i = 0 and result = api.(Function).getCrateOrigin() // crate
178178
or
179179
i = 1 and result = api.(Function).getExtendedCanonicalPath() // name
180180
}

0 commit comments

Comments
 (0)