mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: Add isFieldless and isUnitOnly to Enum
This commit is contained in:
@@ -31,5 +31,23 @@ module Impl {
|
||||
result = this.getVariantList().getAVariant() and
|
||||
result.getName().getText() = name
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if this is a field-less enum, that is, an enum where no constructors contain fields.
|
||||
*
|
||||
* See: https://doc.rust-lang.org/reference/items/enumerations.html#r-items.enum.fieldless
|
||||
*/
|
||||
predicate isFieldless() {
|
||||
forall(Variant v | v = this.getVariantList().getAVariant() | v.getNumberOfFields() = 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if this is a unit-only enum, that is, an enum where all constructors are unit variants.
|
||||
*
|
||||
* See: https://doc.rust-lang.org/reference/items/enumerations.html#r-items.enum.unit-only
|
||||
*/
|
||||
predicate isUnitOnly() {
|
||||
forall(Variant v | v = this.getVariantList().getAVariant() | v.isUnit())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,15 @@ module Impl {
|
||||
pragma[nomagic]
|
||||
TupleField getTupleField(int i) { result = this.getFieldList().(TupleFieldList).getField(i) }
|
||||
|
||||
int getNumberOfFields() {
|
||||
not this.hasFieldList() and
|
||||
result = 0
|
||||
or
|
||||
result = this.getFieldList().(StructFieldList).getNumberOfFields()
|
||||
or
|
||||
result = this.getFieldList().(TupleFieldList).getNumberOfFields()
|
||||
}
|
||||
|
||||
/** Holds if this variant uses tuple fields. */
|
||||
pragma[nomagic]
|
||||
predicate isTuple() { this.getFieldList() instanceof TupleFieldList }
|
||||
|
||||
Reference in New Issue
Block a user