Skip to content

Commit 11bd334

Browse files
committed
Rust: Use TypeItem in path resolution
1 parent d7acb75 commit 11bd334

File tree

1 file changed

+10
-66
lines changed

1 file changed

+10
-66
lines changed

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

Lines changed: 10 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,14 @@ private class ConstItemNode extends AssocItemNode instanceof Const {
629629
override TypeParam getTypeParam(int i) { none() }
630630
}
631631

632-
private class EnumItemNode extends TypeItemNode instanceof Enum {
633-
override string getName() { result = Enum.super.getName().getText() }
632+
private class TypeItemTypeItemNode extends TypeItemNode instanceof TypeItem {
633+
override string getName() { result = TypeItem.super.getName().getText() }
634634

635635
override Namespace getNamespace() { result.isType() }
636636

637-
override Visibility getVisibility() { result = Enum.super.getVisibility() }
637+
override Visibility getVisibility() { result = TypeItem.super.getVisibility() }
638638

639-
override Attr getAnAttr() { result = Enum.super.getAnAttr() }
639+
override Attr getAnAttr() { result = TypeItem.super.getAnAttr() }
640640

641641
override TypeParam getTypeParam(int i) { result = super.getGenericParamList().getTypeParam(i) }
642642

@@ -982,50 +982,26 @@ private class ImplItemNodeImpl extends ImplItemNode {
982982
TraitItemNodeImpl resolveTraitTyCand() { result = resolvePathCand(this.getTraitPath()) }
983983
}
984984

985-
private class StructItemNode extends TypeItemNode, ParameterizableItemNode instanceof Struct {
986-
override string getName() { result = Struct.super.getName().getText() }
987-
985+
private class StructItemNode extends TypeItemTypeItemNode, ParameterizableItemNode instanceof Struct
986+
{
988987
override Namespace getNamespace() {
989988
result.isType() // the struct itself
990989
or
991990
not super.isStruct() and
992991
result.isValue() // the constructor
993992
}
994993

995-
override Visibility getVisibility() { result = Struct.super.getVisibility() }
996-
997-
override Attr getAnAttr() { result = Struct.super.getAnAttr() }
998-
999994
override int getArity() { result = super.getFieldList().(TupleFieldList).getNumberOfFields() }
1000995

1001-
override TypeParam getTypeParam(int i) { result = super.getGenericParamList().getTypeParam(i) }
1002-
1003-
override predicate hasCanonicalPath(Crate c) { this.hasCanonicalPathPrefix(c) }
1004-
1005-
bindingset[c]
1006-
private string getCanonicalPathPart(Crate c, int i) {
1007-
i = 0 and
1008-
result = this.getCanonicalPathPrefix(c)
1009-
or
1010-
i = 1 and
1011-
result = "::"
1012-
or
1013-
i = 2 and
1014-
result = this.getName()
1015-
}
1016-
1017996
language[monotonicAggregates]
1018997
override string getCanonicalPath(Crate c) {
1019998
this.hasCanonicalPath(c) and
1020999
(
1021-
this =
1022-
any(Builtins::BuiltinType t |
1023-
not t.hasVisibility() and
1024-
result = t.getDisplayName()
1025-
)
1000+
not super.hasVisibility() and
1001+
result = this.(Builtins::BuiltinType).getDisplayName()
10261002
or
1027-
not this = any(Builtins::BuiltinType t | not t.hasVisibility()) and
1028-
result = strictconcat(int i | i in [0 .. 2] | this.getCanonicalPathPart(c, i) order by i)
1003+
(super.hasVisibility() or not this instanceof Builtins::BuiltinType) and
1004+
result = TypeItemTypeItemNode.super.getCanonicalPath(c)
10291005
)
10301006
}
10311007
}
@@ -1122,38 +1098,6 @@ private class TypeAliasItemNodeImpl extends TypeAliasItemNode instanceof TypeAli
11221098
}
11231099
}
11241100

1125-
private class UnionItemNode extends TypeItemNode instanceof Union {
1126-
override string getName() { result = Union.super.getName().getText() }
1127-
1128-
override Namespace getNamespace() { result.isType() }
1129-
1130-
override Visibility getVisibility() { result = Union.super.getVisibility() }
1131-
1132-
override Attr getAnAttr() { result = Union.super.getAnAttr() }
1133-
1134-
override TypeParam getTypeParam(int i) { result = super.getGenericParamList().getTypeParam(i) }
1135-
1136-
override predicate hasCanonicalPath(Crate c) { this.hasCanonicalPathPrefix(c) }
1137-
1138-
bindingset[c]
1139-
private string getCanonicalPathPart(Crate c, int i) {
1140-
i = 0 and
1141-
result = this.getCanonicalPathPrefix(c)
1142-
or
1143-
i = 1 and
1144-
result = "::"
1145-
or
1146-
i = 2 and
1147-
result = this.getName()
1148-
}
1149-
1150-
language[monotonicAggregates]
1151-
override string getCanonicalPath(Crate c) {
1152-
this.hasCanonicalPath(c) and
1153-
result = strictconcat(int i | i in [0 .. 2] | this.getCanonicalPathPart(c, i) order by i)
1154-
}
1155-
}
1156-
11571101
private class UseItemNode extends ItemNode instanceof Use {
11581102
override string getName() { result = "(use)" }
11591103

0 commit comments

Comments
 (0)