Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ module Impl {
or
result = this.getVariant().getStructField(name)
}

/** Gets the `i`th struct field of the instantiated struct or variant. */
StructField getNthStructField(int i) {
result = [this.getStruct().getNthStructField(i), this.getVariant().getNthStructField(i)]
}
}
}
6 changes: 6 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ module Impl {
/** Gets a record field, if any. */
StructField getAStructField() { result = this.getStructField(_) }

/** Gets the `i`th struct field, if any. */
pragma[nomagic]
StructField getNthStructField(int i) {
result = this.getFieldList().(StructFieldList).getField(i)
}

/** Gets the `i`th tuple field, if any. */
pragma[nomagic]
TupleField getTupleField(int i) { result = this.getFieldList().(TupleFieldList).getField(i) }
Expand Down
7 changes: 7 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/StructPatImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ module Impl {
)
}

/** Gets the `i`th struct field of the instantiated struct or variant. */
StructField getNthStructField(int i) {
exists(PathResolution::ItemNode item | item = this.getResolvedPath(_) |
result = [item.(Struct).getNthStructField(i), item.(Variant).getNthStructField(i)]
)
}

/** Gets the struct pattern for the field `name`. */
pragma[nomagic]
StructPatField getPatField(string name) {
Expand Down
6 changes: 6 additions & 0 deletions rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ module Impl {
result.getName().getText() = name
}

/** Gets the `i`th struct field, if any. */
pragma[nomagic]
StructField getNthStructField(int i) {
result = this.getFieldList().(StructFieldList).getField(i)
}

/** Gets the `i`th tuple field, if any. */
pragma[nomagic]
TupleField getTupleField(int i) { result = this.getFieldList().(TupleFieldList).getField(i) }
Expand Down
Loading
Loading