File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
rust/ql/lib/codeql/rust/elements/internal Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -31,5 +31,23 @@ module Impl {
3131 result = this .getVariantList ( ) .getAVariant ( ) and
3232 result .getName ( ) .getText ( ) = name
3333 }
34+
35+ /**
36+ * Holds if this is a field-less enum, that is, an enum where no constructors contain fields.
37+ *
38+ * See: https://doc.rust-lang.org/reference/items/enumerations.html#r-items.enum.fieldless
39+ */
40+ predicate isFieldless ( ) {
41+ forall ( Variant v | v = this .getVariantList ( ) .getAVariant ( ) | v .getNumberOfFields ( ) = 0 )
42+ }
43+
44+ /**
45+ * Holds if this is a unit-only enum, that is, an enum where all constructors are unit variants.
46+ *
47+ * See: https://doc.rust-lang.org/reference/items/enumerations.html#r-items.enum.unit-only
48+ */
49+ predicate isUnitOnly ( ) {
50+ forall ( Variant v | v = this .getVariantList ( ) .getAVariant ( ) | v .isUnit ( ) )
51+ }
3452 }
3553}
Original file line number Diff line number Diff line change @@ -36,6 +36,15 @@ module Impl {
3636 pragma [ nomagic]
3737 TupleField getTupleField ( int i ) { result = this .getFieldList ( ) .( TupleFieldList ) .getField ( i ) }
3838
39+ int getNumberOfFields ( ) {
40+ not this .hasFieldList ( ) and
41+ result = 0
42+ or
43+ result = this .getFieldList ( ) .( StructFieldList ) .getNumberOfFields ( )
44+ or
45+ result = this .getFieldList ( ) .( TupleFieldList ) .getNumberOfFields ( )
46+ }
47+
3948 /** Holds if this variant uses tuple fields. */
4049 pragma [ nomagic]
4150 predicate isTuple ( ) { this .getFieldList ( ) instanceof TupleFieldList }
You can’t perform that action at this time.
0 commit comments