Rust: Tweak existing isStruct predicates

This commit is contained in:
Simon Friis Vindum
2025-11-25 10:07:51 +01:00
parent daead038ab
commit b4ae58871a
4 changed files with 15 additions and 16 deletions

View File

@@ -46,12 +46,11 @@ module Impl {
pragma[nomagic]
predicate isTuple() { this.getFieldList() instanceof TupleFieldList }
/**
* Holds if this struct uses record fields.
*
* Empty structs are considered to use record fields.
*/
/** Holds if this struct uses struct fields. */
pragma[nomagic]
predicate isStruct() { not this.isTuple() }
predicate isStruct() { this.getFieldList() instanceof StructFieldList }
/** Holds if this struct does not have a field list. */
predicate isUnit() { not this.hasFieldList() }
}
}

View File

@@ -40,13 +40,13 @@ module Impl {
pragma[nomagic]
predicate isTuple() { this.getFieldList() instanceof TupleFieldList }
/**
* Holds if this variant uses struct fields.
*
* Empty variants are considered to use struct fields.
*/
/** Holds if this variant uses struct fields. */
pragma[nomagic]
predicate isStruct() { not this.isTuple() }
predicate isStruct() { this.getFieldList() instanceof StructFieldList }
/** Holds if this variant does not have a field list. */
pragma[nomagic]
predicate isUnit() { not this.hasFieldList() }
/** Gets the enum that this variant belongs to. */
Enum getEnum() { this = result.getVariantList().getAVariant() }

View File

@@ -659,7 +659,7 @@ private class VariantItemNode extends ParameterizableItemNode instanceof Variant
override string getName() { result = Variant.super.getName().getText() }
override Namespace getNamespace() {
if super.getFieldList() instanceof StructFieldList then result.isType() else result.isValue()
if super.isStruct() then result.isType() else result.isValue()
}
override TypeParam getTypeParam(int i) {
@@ -969,7 +969,7 @@ private class StructItemNode extends TypeItemNode, ParameterizableItemNode insta
override Namespace getNamespace() {
result.isType() // the struct itself
or
not super.getFieldList() instanceof StructFieldList and
not super.isStruct() and
result.isValue() // the constructor
}

View File

@@ -787,7 +787,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
}
private class StructDecl extends Declaration, Struct {
StructDecl() { this.isStruct() }
StructDecl() { this.isStruct() or this.isUnit() }
override TypeParam getATypeParam() { result = this.getGenericParamList().getATypeParam() }
@@ -804,7 +804,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
}
private class StructVariantDecl extends Declaration, Variant {
StructVariantDecl() { this.isStruct() }
StructVariantDecl() { this.isStruct() or this.isUnit() }
Enum getEnum() { result.getVariantList().getAVariant() = this }