Skip to content

Commit fceed89

Browse files
authored
[rust2cpg] typeFullName for record/tuple patterns. (#6221)
1 parent f1b3ed9 commit fceed89

5 files changed

Lines changed: 31 additions & 5 deletions

File tree

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ RUBYSRC2CPG_ASTGEN_VERSION = "0.59.6"
132132

133133
RUBYSRC2CPG_TYPE_STUBS_VERSION = "0.6.0"
134134

135-
RUST2CPG_ASTGEN_VERSION = "0.19.0"
135+
RUST2CPG_ASTGEN_VERSION = "0.19.1"
136136

137137
PHP_PARSER_VERSION = "4.15.10"
138138

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
rust2cpg {
2-
rust_ast_gen_version: "0.19.0"
2+
rust_ast_gen_version: "0.19.1"
33
}

joern-cli/frontends/rust2cpg/src/main/scala/io/joern/rust2cpg/astcreation/RustFullNames.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ trait RustFullNames { this: AstCreator =>
160160
case tuplePat: RustNodeSyntax.TuplePat =>
161161
val childTypes = tuplePat.pat.map(typeFullNameForPat)
162162
s"(${childTypes.mkString(", ")})"
163-
case _ => Defines.Any
163+
case recordPat: RustNodeSyntax.RecordPat => typeFullNameForPath(recordPat.path)
164+
case tupleStructPat: RustNodeSyntax.TupleStructPat => typeFullNameForPath(tupleStructPat.path)
165+
case _ => Defines.Any
164166
}
165167
}
166168
}

joern-cli/frontends/rust2cpg/src/test/scala/io/joern/rust2cpg/passes/ast/DeclarationTests.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,31 @@ class DeclarationTests extends Rust2CpgSuite(noSysRoot = true) {
11191119
endAssign.code shouldBe "end = <tmp>0.end"
11201120
}
11211121
}
1122+
1123+
"have correct field accesses" in {
1124+
inside(cpg.assignment.where(_.target.isIdentifier.nameExact("x")).source.l) { case (fieldAccess: Call) :: Nil =>
1125+
fieldAccess.name shouldBe Operators.fieldAccess
1126+
fieldAccess.typeFullName shouldBe "i32"
1127+
inside(fieldAccess.argument.sortBy(_.argumentIndex).l) {
1128+
case (startFieldAccess: Call) :: (field: FieldIdentifier) :: Nil =>
1129+
field.canonicalName shouldBe "x"
1130+
startFieldAccess.name shouldBe Operators.fieldAccess
1131+
startFieldAccess.code shouldBe "<tmp>0.start"
1132+
startFieldAccess.typeFullName shouldBe "rust2cpgtest::Point"
1133+
}
1134+
}
1135+
inside(cpg.assignment.where(_.target.isIdentifier.nameExact("y")).source.l) { case (fieldAccess: Call) :: Nil =>
1136+
fieldAccess.name shouldBe Operators.fieldAccess
1137+
fieldAccess.typeFullName shouldBe "i64"
1138+
inside(fieldAccess.argument.sortBy(_.argumentIndex).l) {
1139+
case (startFieldAccess: Call) :: (field: FieldIdentifier) :: Nil =>
1140+
field.canonicalName shouldBe "y"
1141+
startFieldAccess.name shouldBe Operators.fieldAccess
1142+
startFieldAccess.code shouldBe "<tmp>0.start"
1143+
startFieldAccess.typeFullName shouldBe "rust2cpgtest::Point"
1144+
}
1145+
}
1146+
}
11221147
}
11231148

11241149
"let with a record pattern in a tuple pattern" should {

joern-cli/frontends/rust2cpg/src/test/scala/io/joern/rust2cpg/passes/ast/ForTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ class ForTestsWithSysroot extends Rust2CpgSuite(noSysRoot = false) {
259259
"have correct locals" in {
260260
inside(cpg.whileBlock.astChildren.isBlock.astChildren.isLocal.l) { case tmp :: xLocal :: yLocal :: Nil =>
261261
tmp.name shouldBe "<tmp>1"
262-
// TODO(rust_ast_gen): typeFullName for patterns.
263-
pendingUntilFixed(tmp.typeFullName shouldBe "rust2cpgtest::Point")
262+
tmp.typeFullName shouldBe "rust2cpgtest::Point"
264263
xLocal.name shouldBe "x"
265264
xLocal.typeFullName shouldBe "i32"
266265
yLocal.name shouldBe "y"

0 commit comments

Comments
 (0)