Skip to content
Draft
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions rust/ql/lib/codeql/rust/internal/CachedStages.qll
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ module Stages {
predicate backref() {
1 = 1
or
exists(Type t)
(exists(Type t) implies any())
or
exists(inferType(_))
(exists(inferType(_)) implies any())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ module SatisfiesBlanketConstraint<

Type getTypeAt(TypePath path) {
result = at.getTypeAt(blanketPath.appendInverse(path)) and
not result = TNeverType() and
not result = TUnknownType()
not result instanceof PseudoType
}

string toString() { result = at.toString() + " [blanket at " + blanketPath.toString() + "]" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ module ArgIsInstantiationOf<ArgSig Arg, IsInstantiationOfInputSig<Arg, AssocFunc
private class ArgSubst extends ArgFinal {
Type getTypeAt(TypePath path) {
result = substituteLookupTraits0(this.getEnclosingItemNode(), super.getTypeAt(path)) and
not result = TNeverType() and
not result = TUnknownType()
not result instanceof PseudoType
}
}

Expand Down
37 changes: 24 additions & 13 deletions rust/ql/lib/codeql/rust/internal/typeinference/Type.qll
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ newtype TType =
TTrait(Trait t) or
TImplTraitType(ImplTraitTypeRepr impl) or
TDynTraitType(Trait t) { t = any(DynTraitTypeRepr dt).getTrait() } or
TNeverType() or
TUnknownType() or
TClosureParameterPseudoType(Param p) {
exists(ClosureExpr ce |
p = ce.getParam(_) and
not p.hasTypeRepr()
)
} or
TTypeParamTypeParameter(TypeParam t) or
TAssociatedTypeTypeParameter(Trait trait, AssocType typeAlias) {
getTraitAssocType(trait) = typeAlias
Expand Down Expand Up @@ -326,14 +331,6 @@ TypeParamTypeParameter getSliceTypeParameter() {
result = any(SliceType t).getPositionalTypeParameter(0)
}

class NeverType extends Type, TNeverType {
override TypeParameter getPositionalTypeParameter(int i) { none() }

override string toString() { result = "!" }

override Location getLocation() { result instanceof EmptyLocation }
}

abstract class PtrType extends StructType { }

pragma[nomagic]
Expand All @@ -355,6 +352,10 @@ class PtrConstType extends PtrType {
override string toString() { result = "*const" }
}

abstract class PseudoType extends Type {
override TypeParameter getPositionalTypeParameter(int i) { none() }
}

/**
* A special pseudo type used to indicate that the actual type may have to be
* inferred by propagating type information back into call arguments.
Expand All @@ -377,14 +378,24 @@ class PtrConstType extends PtrType {
* into call arguments (including method call receivers), in order to avoid
* combinatorial explosions.
*/
class UnknownType extends Type, TUnknownType {
override TypeParameter getPositionalTypeParameter(int i) { none() }

override string toString() { result = "(context typed)" }
class UnknownType extends PseudoType, TUnknownType {
override string toString() { result = "(unknown type)" }

override Location getLocation() { result instanceof EmptyLocation }
}

class ClosureParameterPseudoType extends PseudoType, TClosureParameterPseudoType {
private Param param;

ClosureParameterPseudoType() { this = TClosureParameterPseudoType(param) }

Param getParam() { result = param }

override string toString() { result = "(closure parameter " + param + ")" }

override Location getLocation() { result = param.getLocation() }
}

/** A type parameter. */
abstract class TypeParameter extends Type {
override TypeParameter getPositionalTypeParameter(int i) { none() }
Expand Down
Loading
Loading