Merge pull request #18656 from hvitved/rust/record-destruct-shorthand

Rust: Shorthand record pattern destructuring in data flow
This commit is contained in:
Tom Hvitved
2025-02-04 15:25:12 +01:00
committed by GitHub
4 changed files with 28 additions and 2 deletions

View File

@@ -261,11 +261,16 @@ final class RecordPatCfgNode extends Nodes::RecordPatCfgNode {
RecordPatCfgNode() { node = this.getRecordPat() }
/** Gets the record pattern for the field `field`. */
pragma[nomagic]
PatCfgNode getFieldPat(string field) {
exists(RecordPatField rpf |
rpf = node.getRecordPatFieldList().getAField() and
any(ChildMapping mapping).hasCfgChild(node, rpf.getPat(), this, result) and
any(ChildMapping mapping).hasCfgChild(node, rpf.getPat(), this, result)
|
field = rpf.getNameRef().getText()
or
not rpf.hasNameRef() and
field = result.(IdentPatCfgNode).getName().getText()
)
}
}

View File

@@ -639,6 +639,9 @@ readStep
| main.rs:151:9:151:28 | Point {...} | Point.x | main.rs:151:20:151:20 | a |
| main.rs:151:9:151:28 | Point {...} | Point.y | main.rs:151:26:151:26 | b |
| main.rs:183:9:186:9 | Point3D {...} | Point3D.plane | main.rs:184:20:184:33 | Point {...} |
| main.rs:183:9:186:9 | Point3D {...} | Point3D.z | main.rs:185:13:185:13 | z |
| main.rs:184:20:184:33 | Point {...} | Point.x | main.rs:184:28:184:28 | x |
| main.rs:184:20:184:33 | Point {...} | Point.y | main.rs:184:31:184:31 | y |
| main.rs:201:9:201:23 | ...::Some(...) | Some | main.rs:201:22:201:22 | n |
| main.rs:205:9:205:23 | ...::Some(...) | Some | main.rs:205:22:205:22 | n |
| main.rs:214:9:214:15 | Some(...) | Some | main.rs:214:14:214:14 | n |

View File

@@ -49,6 +49,14 @@ edges
| main.rs:148:12:148:21 | source(...) | main.rs:147:13:150:5 | Point {...} [Point.x] | provenance | |
| main.rs:151:9:151:28 | Point {...} [Point.x] | main.rs:151:20:151:20 | a | provenance | |
| main.rs:151:20:151:20 | a | main.rs:152:10:152:10 | a | provenance | |
| main.rs:175:9:175:9 | p [Point3D.plane, Point.y] | main.rs:182:11:182:11 | p [Point3D.plane, Point.y] | provenance | |
| main.rs:175:13:181:5 | Point3D {...} [Point3D.plane, Point.y] | main.rs:175:9:175:9 | p [Point3D.plane, Point.y] | provenance | |
| main.rs:176:16:179:9 | Point {...} [Point.y] | main.rs:175:13:181:5 | Point3D {...} [Point3D.plane, Point.y] | provenance | |
| main.rs:178:16:178:25 | source(...) | main.rs:176:16:179:9 | Point {...} [Point.y] | provenance | |
| main.rs:182:11:182:11 | p [Point3D.plane, Point.y] | main.rs:183:9:186:9 | Point3D {...} [Point3D.plane, Point.y] | provenance | |
| main.rs:183:9:186:9 | Point3D {...} [Point3D.plane, Point.y] | main.rs:184:20:184:33 | Point {...} [Point.y] | provenance | |
| main.rs:184:20:184:33 | Point {...} [Point.y] | main.rs:184:31:184:31 | y | provenance | |
| main.rs:184:31:184:31 | y | main.rs:188:18:188:18 | y | provenance | |
| main.rs:198:9:198:10 | s1 [Some] | main.rs:200:11:200:12 | s1 [Some] | provenance | |
| main.rs:198:14:198:37 | ...::Some(...) [Some] | main.rs:198:9:198:10 | s1 [Some] | provenance | |
| main.rs:198:27:198:36 | source(...) | main.rs:198:14:198:37 | ...::Some(...) [Some] | provenance | |
@@ -226,6 +234,15 @@ nodes
| main.rs:151:9:151:28 | Point {...} [Point.x] | semmle.label | Point {...} [Point.x] |
| main.rs:151:20:151:20 | a | semmle.label | a |
| main.rs:152:10:152:10 | a | semmle.label | a |
| main.rs:175:9:175:9 | p [Point3D.plane, Point.y] | semmle.label | p [Point3D.plane, Point.y] |
| main.rs:175:13:181:5 | Point3D {...} [Point3D.plane, Point.y] | semmle.label | Point3D {...} [Point3D.plane, Point.y] |
| main.rs:176:16:179:9 | Point {...} [Point.y] | semmle.label | Point {...} [Point.y] |
| main.rs:178:16:178:25 | source(...) | semmle.label | source(...) |
| main.rs:182:11:182:11 | p [Point3D.plane, Point.y] | semmle.label | p [Point3D.plane, Point.y] |
| main.rs:183:9:186:9 | Point3D {...} [Point3D.plane, Point.y] | semmle.label | Point3D {...} [Point3D.plane, Point.y] |
| main.rs:184:20:184:33 | Point {...} [Point.y] | semmle.label | Point {...} [Point.y] |
| main.rs:184:31:184:31 | y | semmle.label | y |
| main.rs:188:18:188:18 | y | semmle.label | y |
| main.rs:198:9:198:10 | s1 [Some] | semmle.label | s1 [Some] |
| main.rs:198:14:198:37 | ...::Some(...) [Some] | semmle.label | ...::Some(...) [Some] |
| main.rs:198:27:198:36 | source(...) | semmle.label | source(...) |
@@ -384,6 +401,7 @@ testFailures
| main.rs:113:10:113:12 | a.0 | main.rs:111:11:111:20 | source(...) | main.rs:113:10:113:12 | a.0 | $@ | main.rs:111:11:111:20 | source(...) | source(...) |
| main.rs:121:10:121:15 | ... .1 | main.rs:118:17:118:26 | source(...) | main.rs:121:10:121:15 | ... .1 | $@ | main.rs:118:17:118:26 | source(...) | source(...) |
| main.rs:152:10:152:10 | a | main.rs:148:12:148:21 | source(...) | main.rs:152:10:152:10 | a | $@ | main.rs:148:12:148:21 | source(...) | source(...) |
| main.rs:188:18:188:18 | y | main.rs:178:16:178:25 | source(...) | main.rs:188:18:188:18 | y | $@ | main.rs:178:16:178:25 | source(...) | source(...) |
| main.rs:201:33:201:33 | n | main.rs:198:27:198:36 | source(...) | main.rs:201:33:201:33 | n | $@ | main.rs:198:27:198:36 | source(...) | source(...) |
| main.rs:214:25:214:25 | n | main.rs:211:19:211:28 | source(...) | main.rs:214:25:214:25 | n | $@ | main.rs:211:19:211:28 | source(...) | source(...) |
| main.rs:225:10:225:20 | s1.unwrap(...) | main.rs:224:19:224:28 | source(...) | main.rs:225:10:225:20 | s1.unwrap(...) | $@ | main.rs:224:19:224:28 | source(...) | source(...) |

View File

@@ -185,7 +185,7 @@ fn struct_nested_match() {
z,
} => {
sink(x);
sink(y); // MISSING: hasValueFlow=93
sink(y); // $ hasValueFlow=93
sink(z);
}
}