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
25 changes: 25 additions & 0 deletions rust/ql/lib/codeql/rust/internal/Type.qll
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ newtype TType =
TSliceType() or
TNeverType() or
TPtrType() or
TContextType() or
TTupleTypeParameter(int arity, int i) { exists(TTuple(arity)) and i in [0 .. arity - 1] } or
TTypeParamTypeParameter(TypeParam t) or
TAssociatedTypeTypeParameter(TypeAlias t) { any(TraitItemNode trait).getAnAssocItem() = t } or
Expand Down Expand Up @@ -371,6 +372,30 @@ class PtrType extends Type, TPtrType {
override Location getLocation() { result instanceof EmptyLocation }
}

/**
* A special pseudo type used to indicate that the actual type may have to be
* inferred from a context.
*
* For example, a call like `Default::default()` is assigned this type, which
* means that the actual type is to be inferred from the context in which the call
* occurs.
*
* Context types are not restricted to root types, for example in a call like
* `Vec::new()` we assign this type at the type path corresponding to the type
* parameter of `Vec`.
*
* Context types are used to restrict when type information is allowed to flow
* into call arguments (including method call receivers), in order to avoid
* combinatorial explosions.
*/
class ContextType extends Type, TContextType {
override TypeParameter getPositionalTypeParameter(int i) { none() }

override string toString() { result = "(context typed)" }

override Location getLocation() { result instanceof EmptyLocation }
}

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