Skip to content

Commit 2d5aecf

Browse files
committed
Rust: Restrict type propagation into arguments
1 parent e97c6b3 commit 2d5aecf

File tree

11 files changed

+245
-607
lines changed

11 files changed

+245
-607
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ newtype TType =
5151
TSliceType() or
5252
TNeverType() or
5353
TPtrType() or
54+
TContextType() or
5455
TTupleTypeParameter(int arity, int i) { exists(TTuple(arity)) and i in [0 .. arity - 1] } or
5556
TTypeParamTypeParameter(TypeParam t) or
5657
TAssociatedTypeTypeParameter(TypeAlias t) { any(TraitItemNode trait).getAnAssocItem() = t } or
@@ -371,6 +372,30 @@ class PtrType extends Type, TPtrType {
371372
override Location getLocation() { result instanceof EmptyLocation }
372373
}
373374

375+
/**
376+
* A special pseudo type used to indicate that the actual type may have to be
377+
* inferred from a context.
378+
*
379+
* For example, a call like `Default::default()` is assigned this type, which
380+
* means that the actual type is to be inferred from the context in which the call
381+
* occurs.
382+
*
383+
* Context types are not restricted to root types, for example in a call like
384+
* `Vec::new()` we assign this type at the type path corresponding to the type
385+
* parameter of `Vec`.
386+
*
387+
* Context types are used to restrict when type information is allowed to flow
388+
* into call arguments (including method call receivers), in order to avoid
389+
* combinatorial explosions.
390+
*/
391+
class ContextType extends Type, TContextType {
392+
override TypeParameter getPositionalTypeParameter(int i) { none() }
393+
394+
override string toString() { result = "(context typed)" }
395+
396+
override Location getLocation() { result instanceof EmptyLocation }
397+
}
398+
374399
/** A type parameter. */
375400
abstract class TypeParameter extends Type {
376401
override TypeParameter getPositionalTypeParameter(int i) { none() }

0 commit comments

Comments
 (0)