Skip to content

Commit b4ae588

Browse files
committed
Rust: Tweak existing isStruct predicates
1 parent daead03 commit b4ae588

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

rust/ql/lib/codeql/rust/elements/internal/StructImpl.qll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ module Impl {
4646
pragma[nomagic]
4747
predicate isTuple() { this.getFieldList() instanceof TupleFieldList }
4848

49-
/**
50-
* Holds if this struct uses record fields.
51-
*
52-
* Empty structs are considered to use record fields.
53-
*/
49+
/** Holds if this struct uses struct fields. */
5450
pragma[nomagic]
55-
predicate isStruct() { not this.isTuple() }
51+
predicate isStruct() { this.getFieldList() instanceof StructFieldList }
52+
53+
/** Holds if this struct does not have a field list. */
54+
predicate isUnit() { not this.hasFieldList() }
5655
}
5756
}

rust/ql/lib/codeql/rust/elements/internal/VariantImpl.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ module Impl {
4040
pragma[nomagic]
4141
predicate isTuple() { this.getFieldList() instanceof TupleFieldList }
4242

43-
/**
44-
* Holds if this variant uses struct fields.
45-
*
46-
* Empty variants are considered to use struct fields.
47-
*/
43+
/** Holds if this variant uses struct fields. */
4844
pragma[nomagic]
49-
predicate isStruct() { not this.isTuple() }
45+
predicate isStruct() { this.getFieldList() instanceof StructFieldList }
46+
47+
/** Holds if this variant does not have a field list. */
48+
pragma[nomagic]
49+
predicate isUnit() { not this.hasFieldList() }
5050

5151
/** Gets the enum that this variant belongs to. */
5252
Enum getEnum() { this = result.getVariantList().getAVariant() }

rust/ql/lib/codeql/rust/internal/PathResolution.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ private class VariantItemNode extends ParameterizableItemNode instanceof Variant
659659
override string getName() { result = Variant.super.getName().getText() }
660660

661661
override Namespace getNamespace() {
662-
if super.getFieldList() instanceof StructFieldList then result.isType() else result.isValue()
662+
if super.isStruct() then result.isType() else result.isValue()
663663
}
664664

665665
override TypeParam getTypeParam(int i) {
@@ -969,7 +969,7 @@ private class StructItemNode extends TypeItemNode, ParameterizableItemNode insta
969969
override Namespace getNamespace() {
970970
result.isType() // the struct itself
971971
or
972-
not super.getFieldList() instanceof StructFieldList and
972+
not super.isStruct() and
973973
result.isValue() // the constructor
974974
}
975975

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
787787
}
788788

789789
private class StructDecl extends Declaration, Struct {
790-
StructDecl() { this.isStruct() }
790+
StructDecl() { this.isStruct() or this.isUnit() }
791791

792792
override TypeParam getATypeParam() { result = this.getGenericParamList().getATypeParam() }
793793

@@ -804,7 +804,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
804804
}
805805

806806
private class StructVariantDecl extends Declaration, Variant {
807-
StructVariantDecl() { this.isStruct() }
807+
StructVariantDecl() { this.isStruct() or this.isUnit() }
808808

809809
Enum getEnum() { result.getVariantList().getAVariant() = this }
810810

0 commit comments

Comments
 (0)