Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 10 additions & 66 deletions rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
Expand Up @@ -629,14 +629,14 @@ private class ConstItemNode extends AssocItemNode instanceof Const {
override TypeParam getTypeParam(int i) { none() }
}

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

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

override Visibility getVisibility() { result = Enum.super.getVisibility() }
override Visibility getVisibility() { result = TypeItem.super.getVisibility() }

override Attr getAnAttr() { result = Enum.super.getAnAttr() }
override Attr getAnAttr() { result = TypeItem.super.getAnAttr() }

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

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

private class StructItemNode extends TypeItemNode, ParameterizableItemNode instanceof Struct {
override string getName() { result = Struct.super.getName().getText() }

private class StructItemNode extends TypeItemTypeItemNode, ParameterizableItemNode instanceof Struct
{
override Namespace getNamespace() {
result.isType() // the struct itself
or
not super.isStruct() and
result.isValue() // the constructor
}

override Visibility getVisibility() { result = Struct.super.getVisibility() }

override Attr getAnAttr() { result = Struct.super.getAnAttr() }

override int getArity() { result = super.getFieldList().(TupleFieldList).getNumberOfFields() }

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

override predicate hasCanonicalPath(Crate c) { this.hasCanonicalPathPrefix(c) }

bindingset[c]
private string getCanonicalPathPart(Crate c, int i) {
i = 0 and
result = this.getCanonicalPathPrefix(c)
or
i = 1 and
result = "::"
or
i = 2 and
result = this.getName()
}

language[monotonicAggregates]
override string getCanonicalPath(Crate c) {
this.hasCanonicalPath(c) and
(
this =
any(Builtins::BuiltinType t |
not t.hasVisibility() and
result = t.getDisplayName()
)
not super.hasVisibility() and
result = this.(Builtins::BuiltinType).getDisplayName()
or
not this = any(Builtins::BuiltinType t | not t.hasVisibility()) and
result = strictconcat(int i | i in [0 .. 2] | this.getCanonicalPathPart(c, i) order by i)
(super.hasVisibility() or not this instanceof Builtins::BuiltinType) and
result = TypeItemTypeItemNode.super.getCanonicalPath(c)
)
}
}
Expand Down Expand Up @@ -1122,38 +1098,6 @@ private class TypeAliasItemNodeImpl extends TypeAliasItemNode instanceof TypeAli
}
}

private class UnionItemNode extends TypeItemNode instanceof Union {
override string getName() { result = Union.super.getName().getText() }

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

override Visibility getVisibility() { result = Union.super.getVisibility() }

override Attr getAnAttr() { result = Union.super.getAnAttr() }

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

override predicate hasCanonicalPath(Crate c) { this.hasCanonicalPathPrefix(c) }

bindingset[c]
private string getCanonicalPathPart(Crate c, int i) {
i = 0 and
result = this.getCanonicalPathPrefix(c)
or
i = 1 and
result = "::"
or
i = 2 and
result = this.getName()
}

language[monotonicAggregates]
override string getCanonicalPath(Crate c) {
this.hasCanonicalPath(c) and
result = strictconcat(int i | i in [0 .. 2] | this.getCanonicalPathPart(c, i) order by i)
}
}

private class UseItemNode extends ItemNode instanceof Use {
override string getName() { result = "(use)" }

Expand Down
Loading