Skip to content

Commit 8a1136d

Browse files
author
Paolo Tranquilli
committed
Merge branch 'main' into redsun82/rust-less-canonical-paths
2 parents ebe38bc + 06b1d8e commit 8a1136d

File tree

7 files changed

+413
-415
lines changed

7 files changed

+413
-415
lines changed

rust/ql/lib/codeql/rust/dataflow/FlowSummary.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private module Summaries {
1313
UnwrapSummary() { this = "lang:core::_::<crate::option::Option>::unwrap" }
1414

1515
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
16-
input = "Argument[self].Variant[crate::std::option::Option::Some(0)]" and
16+
input = "Argument[self].Variant[crate::option::Option::Some(0)]" and
1717
output = "ReturnValue" and
1818
preservesValue = true
1919
}

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,7 @@ module RustDataFlow implements InputSig<Location> {
788788
(
789789
LocalFlow::localFlowStepCommon(nodeFrom, nodeTo)
790790
or
791-
exists(SsaImpl::DefinitionExt def, boolean isUseStep |
792-
SsaFlow::localFlowStep(def, nodeFrom, nodeTo, isUseStep)
793-
|
791+
exists(boolean isUseStep | SsaFlow::localFlowStep(_, nodeFrom, nodeTo, isUseStep) |
794792
isUseStep = false
795793
or
796794
isUseStep = true and
@@ -823,19 +821,9 @@ module RustDataFlow implements InputSig<Location> {
823821
/** Holds if path `p` resolves to variant `v`. */
824822
private predicate pathResolveToVariantCanonicalPath(PathAstNode p, VariantCanonicalPath v) {
825823
exists(CrateOriginOption crate, string path, string name |
826-
// TODO: this is bad, but will be solved by moving to semantic paths away from strings
827824
resolveExtendedCanonicalPath(p, crate, path + "::" + name) and
828825
v = MkVariantCanonicalPath(crate, path, name)
829826
)
830-
or
831-
// TODO: Remove once library types are extracted
832-
exists(Path path |
833-
path = p.getPath() and
834-
not path.hasQualifier() and
835-
v =
836-
MkVariantCanonicalPath(_, ["crate::std::option::Option", "crate::std::result::Result"],
837-
path.getPart().getNameRef().getText())
838-
)
839827
}
840828

841829
/** Holds if `p` destructs an enum variant `v`. */
@@ -1101,20 +1089,22 @@ private module Cached {
11011089
cached
11021090
newtype TReturnKind = TNormalReturnKind()
11031091

1092+
private CrateOriginOption langCoreCrate() { result.asSome() = "lang:core" }
1093+
11041094
cached
11051095
newtype TVariantCanonicalPath =
11061096
MkVariantCanonicalPath(CrateOriginOption crate, string path, string name) {
11071097
variantHasExtendedCanonicalPath(_, _, crate, path, name)
11081098
or
11091099
// TODO: Remove once library types are extracted
1110-
crate.isNone() and
1111-
path = "crate::std::option::Option" and
1112-
name = "Some"
1113-
or
1114-
// TODO: Remove once library types are extracted
1115-
crate.isNone() and
1116-
path = "crate::std::result::Result" and
1117-
name = ["Ok", "Err"]
1100+
crate = langCoreCrate() and
1101+
(
1102+
path = "crate::option::Option" and
1103+
name = "Some"
1104+
or
1105+
path = "crate::result::Result" and
1106+
name = ["Ok", "Err"]
1107+
)
11181108
}
11191109

11201110
cached
@@ -1129,11 +1119,11 @@ private module Cached {
11291119
pos in [0 .. v.getVariant().getFieldList().(TupleFieldList).getNumberOfFields() - 1]
11301120
or
11311121
// TODO: Remove once library types are extracted
1132-
v = MkVariantCanonicalPath(_, "crate::std::option::Option", "Some") and
1122+
v = MkVariantCanonicalPath(langCoreCrate(), "crate::option::Option", "Some") and
11331123
pos = 0
11341124
or
11351125
// TODO: Remove once library types are extracted
1136-
v = MkVariantCanonicalPath(_, "crate::std::result::Result", ["Ok", "Err"]) and
1126+
v = MkVariantCanonicalPath(langCoreCrate(), "crate::result::Result", ["Ok", "Err"]) and
11371127
pos = 0
11381128
} or
11391129
TVariantFieldContent(VariantCanonicalPath v, string field) {

0 commit comments

Comments
 (0)