mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Rust: Tweak existing isStruct predicates
This commit is contained in:
@@ -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() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() }
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user