diff --git a/rust/ql/lib/codeql/rust/frameworks/stdlib/Builtins.qll b/rust/ql/lib/codeql/rust/frameworks/stdlib/Builtins.qll index 08208d09642..e87eb25279a 100644 --- a/rust/ql/lib/codeql/rust/frameworks/stdlib/Builtins.qll +++ b/rust/ql/lib/codeql/rust/frameworks/stdlib/Builtins.qll @@ -176,15 +176,18 @@ class RefMutType extends BuiltinType { override string getDisplayName() { result = "&mut" } } -/** The builtin pointer type `*const T`. */ -class PtrType extends BuiltinType { - PtrType() { this.getName() = "Ptr" } +/** A builtin raw pointer type `*const T` or `*mut T`. */ +abstract class PtrType extends BuiltinType { } + +/** The builtin raw pointer type `*const T`. */ +class PtrConstType extends PtrType { + PtrConstType() { this.getName() = "PtrConst" } override string getDisplayName() { result = "*const" } } -/** The builtin pointer type `*mut T`. */ -class PtrMutType extends BuiltinType { +/** The builtin raw pointer type `*mut T`. */ +class PtrMutType extends PtrType { PtrMutType() { this.getName() = "PtrMut" } override string getDisplayName() { result = "*mut" } diff --git a/rust/ql/lib/codeql/rust/internal/Type.qll b/rust/ql/lib/codeql/rust/internal/Type.qll index dd6a20eb070..af37fb567e5 100644 --- a/rust/ql/lib/codeql/rust/internal/Type.qll +++ b/rust/ql/lib/codeql/rust/internal/Type.qll @@ -339,10 +339,27 @@ class NeverType extends Type, TNeverType { override Location getLocation() { result instanceof EmptyLocation } } -class PtrType extends StructType { - PtrType() { this.getStruct() instanceof Builtins::PtrType } +abstract class PtrType extends StructType { + override Location getLocation() { result instanceof EmptyLocation } +} - override string toString() { result = "*" } +pragma[nomagic] +TypeParamTypeParameter getPtrTypeParameter() { + result = any(PtrType t).getPositionalTypeParameter(0) +} + +class PtrMutType extends PtrType { + PtrMutType() { this.getStruct() instanceof Builtins::PtrMutType } + + override string toString() { result = "*mut" } + + override Location getLocation() { result instanceof EmptyLocation } +} + +class PtrConstType extends PtrType { + PtrConstType() { this.getStruct() instanceof Builtins::PtrConstType } + + override string toString() { result = "*const" } override Location getLocation() { result instanceof EmptyLocation } } @@ -377,11 +394,6 @@ class UnknownType extends Type, TUnknownType { override Location getLocation() { result instanceof EmptyLocation } } -pragma[nomagic] -TypeParamTypeParameter getPtrTypeParameter() { - result = any(PtrType t).getPositionalTypeParameter(0) -} - /** A type parameter. */ abstract class TypeParameter extends Type { override TypeParameter getPositionalTypeParameter(int i) { none() } diff --git a/rust/ql/lib/codeql/rust/internal/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/TypeInference.qll index a21722d0e1f..149bf820510 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeInference.qll @@ -431,7 +431,10 @@ module CertainTypeInference { or result = inferLiteralType(n, path, true) or - result = inferRefNodeType(n) and + result = inferRefPatType(n) and + path.isEmpty() + or + result = inferRefExprType(n) and path.isEmpty() or result = inferLogicalOperationType(n, path) @@ -606,10 +609,14 @@ private predicate typeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePat strictcount(Expr e | bodyReturns(n1, e)) = 1 ) or - ( - n1 = n2.(RefExpr).getExpr() or - n1 = n2.(RefPat).getPat() - ) and + exists(RefExpr re | + n2 = re and + n1 = re.getExpr() and + prefix1.isEmpty() and + prefix2 = TypePath::singleton(inferRefExprType(re).getPositionalTypeParameter(0)) + ) + or + n1 = n2.(RefPat).getPat() and prefix1.isEmpty() and prefix2 = TypePath::singleton(getRefTypeParameter()) or @@ -709,9 +716,7 @@ private predicate lubCoercion(AstNode parent, AstNode child, TypePath prefix) { * of `n2` at `prefix2`, but type information should only propagate from `n1` to * `n2`. */ -private predicate typeEqualityNonSymmetric( - AstNode n1, TypePath prefix1, AstNode n2, TypePath prefix2 -) { +private predicate typeEqualityAsymmetric(AstNode n1, TypePath prefix1, AstNode n2, TypePath prefix2) { lubCoercion(n2, n1, prefix2) and prefix1.isEmpty() or @@ -723,6 +728,13 @@ private predicate typeEqualityNonSymmetric( not lubCoercion(mid, n1, _) and prefix1 = prefixMid.append(suffix) ) + or + // When `n2` is `*n1` propagate type information from a raw pointer type + // parameter at `n1`. The other direction is handled in + // `inferDereferencedExprPtrType`. + n1 = n2.(DerefExpr).getExpr() and + prefix1 = TypePath::singleton(getPtrTypeParameter()) and + prefix2.isEmpty() } pragma[nomagic] @@ -735,7 +747,7 @@ private Type inferTypeEquality(AstNode n, TypePath path) { or typeEquality(n2, prefix2, n, prefix1) or - typeEqualityNonSymmetric(n2, prefix2, n, prefix1) + typeEqualityAsymmetric(n2, prefix2, n, prefix1) ) } @@ -2952,16 +2964,21 @@ private Type inferFieldExprType(AstNode n, TypePath path) { ) } +/** Gets the root type of the reference expression `ref`. */ +pragma[nomagic] +private Type inferRefExprType(RefExpr ref) { + if ref.isRaw() + then + ref.isMut() and result instanceof PtrMutType + or + ref.isConst() and result instanceof PtrConstType + else result instanceof RefType +} + /** Gets the root type of the reference node `ref`. */ pragma[nomagic] -private Type inferRefNodeType(AstNode ref) { - ( - ref = any(IdentPat ip | ip.isRef()).getName() - or - ref instanceof RefExpr - or - ref instanceof RefPat - ) and +private Type inferRefPatType(AstNode ref) { + (ref = any(IdentPat ip | ip.isRef()).getName() or ref instanceof RefPat) and result instanceof RefType } @@ -3145,6 +3162,21 @@ private Type inferIndexExprType(IndexExpr ie, TypePath path) { ) } +/** + * Gets the inferred type of `n` at `path` when `n` occurs in a dereference + * expression `*n` and when `n` is known to have a raw pointer type. + * + * The other direction is handled in `typeEqualityAsymmetric`. + */ +private Type inferDereferencedExprPtrType(AstNode n, TypePath path) { + exists(DerefExpr de, PtrType type, TypePath suffix | + de.getExpr() = n and + type = inferType(de.getExpr()) and + result = inferType(de, suffix) and + path = TypePath::cons(type.getPositionalTypeParameter(0), suffix) + ) +} + /** * A matching configuration for resolving types of struct patterns * like `let Foo { bar } = ...`. @@ -3544,6 +3576,8 @@ private module Cached { or result = inferIndexExprType(n, path) or + result = inferDereferencedExprPtrType(n, path) + or result = inferForLoopExprType(n, path) or result = inferDynamicCallExprType(n, path) diff --git a/rust/ql/lib/codeql/rust/internal/TypeMention.qll b/rust/ql/lib/codeql/rust/internal/TypeMention.qll index a88f3e20a96..3e2ca811107 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeMention.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeMention.qll @@ -556,13 +556,18 @@ class NeverTypeReprMention extends TypeMention, NeverTypeRepr { } class PtrTypeReprMention extends TypeMention instanceof PtrTypeRepr { + private PtrType resolveRootType() { + super.isConst() and result instanceof PtrConstType + or + super.isMut() and result instanceof PtrMutType + } + override Type resolveTypeAt(TypePath path) { - path.isEmpty() and - result instanceof PtrType + path.isEmpty() and result = this.resolveRootType() or exists(TypePath suffix | result = super.getTypeRepr().(TypeMention).resolveTypeAt(suffix) and - path = TypePath::cons(getPtrTypeParameter(), suffix) + path = TypePath::cons(this.resolveRootType().getPositionalTypeParameter(0), suffix) ) } } diff --git a/rust/ql/test/library-tests/type-inference/raw_pointer.rs b/rust/ql/test/library-tests/type-inference/raw_pointer.rs index 4ae863632d9..82f6f1afe16 100644 --- a/rust/ql/test/library-tests/type-inference/raw_pointer.rs +++ b/rust/ql/test/library-tests/type-inference/raw_pointer.rs @@ -1,47 +1,47 @@ use std::ptr::null_mut; fn raw_pointer_const_deref(x: *const i32) -> i32 { - let _y = unsafe { *x }; // $ MISSING: type=_y:i32 + let _y = unsafe { *x }; // $ type=_y:i32 0 } fn raw_pointer_mut_deref(x: *mut bool) -> i32 { - let _y = unsafe { *x }; // $ MISSING: type=_y:bool + let _y = unsafe { *x }; // $ type=_y:bool 0 } fn raw_const_borrow() { let a: i64 = 10; - let x = &raw const a; // $ MISSING: type=x:TPtrConst.i64 + let x = &raw const a; // $ type=x:TPtrConst.i64 unsafe { - let _y = *x; // $ type=_y:i64 SPURIOUS: target=deref + let _y = *x; // $ type=_y:i64 } } fn raw_mut_borrow() { let mut a = 10i32; - let x = &raw mut a; // $ MISSING: type=x:TPtrMut.i32 + let x = &raw mut a; // $ type=x:TPtrMut.i32 unsafe { - let _y = *x; // $ type=_y:i32 SPURIOUS: target=deref + let _y = *x; // $ type=_y:i32 } } fn raw_mut_write(cond: bool) { let a = 10i32; // The type of `x` must be inferred from the write below. - let ptr_written = null_mut(); // $ target=null_mut MISSING: type=ptr_written:TPtrMut.i32 + let ptr_written = null_mut(); // $ target=null_mut type=ptr_written:TPtrMut.i32 if cond { unsafe { // NOTE: This write is undefined behavior because `x` is a null pointer. *ptr_written = a; - let _y = *ptr_written; // $ MISSING: type=_y:i32 + let _y = *ptr_written; // $ type=_y:i32 } } } fn raw_type_from_deref(cond: bool) { // The type of `x` must be inferred from the read below. - let ptr_read = null_mut(); // $ target=null_mut MISSING: type=ptr_read:TPtrMut.i64 + let ptr_read = null_mut(); // $ target=null_mut type=ptr_read:TPtrMut.i64 if cond { unsafe { // NOTE: This read is undefined behavior because `x` is a null pointer. diff --git a/rust/ql/test/library-tests/type-inference/type-inference.expected b/rust/ql/test/library-tests/type-inference/type-inference.expected index 0ef15c66fc2..0194b9e4643 100644 --- a/rust/ql/test/library-tests/type-inference/type-inference.expected +++ b/rust/ql/test/library-tests/type-inference/type-inference.expected @@ -2256,24 +2256,24 @@ inferCertainType | main.rs:1803:13:1803:13 | x | | {EXTERNAL LOCATION} | i32 | | main.rs:1803:17:1803:33 | ...::my_func(...) | | {EXTERNAL LOCATION} | i32 | | main.rs:1806:26:1806:30 | SelfParam | | {EXTERNAL LOCATION} | & | -| main.rs:1806:26:1806:30 | SelfParam | TRef | file://:0:0:0:0 | * | -| main.rs:1806:26:1806:30 | SelfParam | TRef.TPtr | main.rs:1805:14:1805:23 | T | +| main.rs:1806:26:1806:30 | SelfParam | TRef | file://:0:0:0:0 | *mut | +| main.rs:1806:26:1806:30 | SelfParam | TRef.TPtrMut | main.rs:1805:14:1805:23 | T | | main.rs:1806:39:1808:13 | { ... } | | {EXTERNAL LOCATION} | & | | main.rs:1806:39:1808:13 | { ... } | TRef | main.rs:1805:14:1805:23 | T | | main.rs:1807:26:1807:32 | &... | | {EXTERNAL LOCATION} | & | | main.rs:1807:29:1807:32 | self | | {EXTERNAL LOCATION} | & | -| main.rs:1807:29:1807:32 | self | TRef | file://:0:0:0:0 | * | -| main.rs:1807:29:1807:32 | self | TRef.TPtr | main.rs:1805:14:1805:23 | T | +| main.rs:1807:29:1807:32 | self | TRef | file://:0:0:0:0 | *mut | +| main.rs:1807:29:1807:32 | self | TRef.TPtrMut | main.rs:1805:14:1805:23 | T | | main.rs:1810:31:1812:13 | { ... } | | main.rs:1805:14:1805:23 | T | -| main.rs:1816:13:1816:13 | p | | file://:0:0:0:0 | * | -| main.rs:1816:13:1816:13 | p | TPtr | {EXTERNAL LOCATION} | i32 | +| main.rs:1816:13:1816:13 | p | | file://:0:0:0:0 | *mut | +| main.rs:1816:13:1816:13 | p | TPtrMut | {EXTERNAL LOCATION} | i32 | | main.rs:1816:27:1816:32 | &mut v | | {EXTERNAL LOCATION} | & | -| main.rs:1817:26:1817:26 | p | | file://:0:0:0:0 | * | -| main.rs:1817:26:1817:26 | p | TPtr | {EXTERNAL LOCATION} | i32 | +| main.rs:1817:26:1817:26 | p | | file://:0:0:0:0 | *mut | +| main.rs:1817:26:1817:26 | p | TPtrMut | {EXTERNAL LOCATION} | i32 | | main.rs:1818:26:1818:48 | ...::my_method(...) | | {EXTERNAL LOCATION} | & | | main.rs:1818:46:1818:47 | &p | | {EXTERNAL LOCATION} | & | -| main.rs:1818:47:1818:47 | p | | file://:0:0:0:0 | * | -| main.rs:1818:47:1818:47 | p | TPtr | {EXTERNAL LOCATION} | i32 | +| main.rs:1818:47:1818:47 | p | | file://:0:0:0:0 | *mut | +| main.rs:1818:47:1818:47 | p | TPtrMut | {EXTERNAL LOCATION} | i32 | | main.rs:1819:13:1819:13 | x | | {EXTERNAL LOCATION} | i32 | | main.rs:1819:17:1819:37 | ...::my_func(...) | | {EXTERNAL LOCATION} | i32 | | main.rs:1825:16:1837:5 | { ... } | | {EXTERNAL LOCATION} | () | @@ -4422,52 +4422,52 @@ inferCertainType | pattern_matching.rs:843:5:843:32 | patterns_in_let_statements(...) | | {EXTERNAL LOCATION} | () | | pattern_matching.rs:844:5:844:37 | patterns_in_function_parameters(...) | | {EXTERNAL LOCATION} | () | | pattern_matching.rs:845:5:845:30 | patterns_in_control_flow(...) | | {EXTERNAL LOCATION} | () | -| raw_pointer.rs:3:28:3:28 | x | | file://:0:0:0:0 | * | -| raw_pointer.rs:3:28:3:28 | x | TPtr | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:3:28:3:28 | x | | file://:0:0:0:0 | *const | +| raw_pointer.rs:3:28:3:28 | x | TPtrConst | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:3:50:6:1 | { ... } | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:4:24:4:24 | x | | file://:0:0:0:0 | * | -| raw_pointer.rs:4:24:4:24 | x | TPtr | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:8:26:8:26 | x | | file://:0:0:0:0 | * | -| raw_pointer.rs:8:26:8:26 | x | TPtr | {EXTERNAL LOCATION} | bool | +| raw_pointer.rs:4:24:4:24 | x | | file://:0:0:0:0 | *const | +| raw_pointer.rs:4:24:4:24 | x | TPtrConst | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:8:26:8:26 | x | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:8:26:8:26 | x | TPtrMut | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:8:47:11:1 | { ... } | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:9:24:9:24 | x | | file://:0:0:0:0 | * | -| raw_pointer.rs:9:24:9:24 | x | TPtr | {EXTERNAL LOCATION} | bool | +| raw_pointer.rs:9:24:9:24 | x | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:9:24:9:24 | x | TPtrMut | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:13:23:19:1 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:14:9:14:9 | a | | {EXTERNAL LOCATION} | i64 | -| raw_pointer.rs:15:9:15:9 | x | | {EXTERNAL LOCATION} | & | -| raw_pointer.rs:15:13:15:24 | &raw const a | | {EXTERNAL LOCATION} | & | +| raw_pointer.rs:15:9:15:9 | x | | file://:0:0:0:0 | *const | +| raw_pointer.rs:15:13:15:24 | &raw const a | | file://:0:0:0:0 | *const | | raw_pointer.rs:15:24:15:24 | a | | {EXTERNAL LOCATION} | i64 | | raw_pointer.rs:16:5:18:5 | { ... } | | {EXTERNAL LOCATION} | () | -| raw_pointer.rs:17:19:17:19 | x | | {EXTERNAL LOCATION} | & | +| raw_pointer.rs:17:19:17:19 | x | | file://:0:0:0:0 | *const | | raw_pointer.rs:21:21:27:1 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:22:13:22:13 | a | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:22:17:22:21 | 10i32 | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:23:9:23:9 | x | | {EXTERNAL LOCATION} | & | -| raw_pointer.rs:23:13:23:22 | &raw mut a | | {EXTERNAL LOCATION} | & | +| raw_pointer.rs:23:9:23:9 | x | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:23:13:23:22 | &raw mut a | | file://:0:0:0:0 | *mut | | raw_pointer.rs:23:22:23:22 | a | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:24:5:26:5 | { ... } | | {EXTERNAL LOCATION} | () | -| raw_pointer.rs:25:19:25:19 | x | | {EXTERNAL LOCATION} | & | +| raw_pointer.rs:25:19:25:19 | x | | file://:0:0:0:0 | *mut | | raw_pointer.rs:29:18:29:21 | cond | | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:29:30:40:1 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:30:9:30:9 | a | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:30:13:30:17 | 10i32 | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:32:9:32:19 | ptr_written | | file://:0:0:0:0 | * | -| raw_pointer.rs:32:23:32:32 | null_mut(...) | | file://:0:0:0:0 | * | +| raw_pointer.rs:32:9:32:19 | ptr_written | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:32:23:32:32 | null_mut(...) | | file://:0:0:0:0 | *mut | | raw_pointer.rs:33:5:39:5 | if cond {...} | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:33:8:33:11 | cond | | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:34:9:38:9 | { ... } | | {EXTERNAL LOCATION} | () | -| raw_pointer.rs:36:14:36:24 | ptr_written | | file://:0:0:0:0 | * | +| raw_pointer.rs:36:14:36:24 | ptr_written | | file://:0:0:0:0 | *mut | | raw_pointer.rs:36:28:36:28 | a | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:37:23:37:33 | ptr_written | | file://:0:0:0:0 | * | +| raw_pointer.rs:37:23:37:33 | ptr_written | | file://:0:0:0:0 | *mut | | raw_pointer.rs:42:24:42:27 | cond | | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:42:36:51:1 | { ... } | | {EXTERNAL LOCATION} | () | -| raw_pointer.rs:44:9:44:16 | ptr_read | | file://:0:0:0:0 | * | -| raw_pointer.rs:44:20:44:29 | null_mut(...) | | file://:0:0:0:0 | * | +| raw_pointer.rs:44:9:44:16 | ptr_read | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:44:20:44:29 | null_mut(...) | | file://:0:0:0:0 | *mut | | raw_pointer.rs:45:5:50:5 | if cond {...} | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:45:8:45:11 | cond | | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:46:9:49:9 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:48:17:48:18 | _y | | {EXTERNAL LOCATION} | i64 | -| raw_pointer.rs:48:28:48:35 | ptr_read | | file://:0:0:0:0 | * | +| raw_pointer.rs:48:28:48:35 | ptr_read | | file://:0:0:0:0 | *mut | | raw_pointer.rs:53:15:60:1 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:54:5:54:32 | raw_pointer_const_deref(...) | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:54:29:54:31 | &10 | | {EXTERNAL LOCATION} | & | @@ -8560,8 +8560,8 @@ inferType | main.rs:1803:13:1803:13 | x | | {EXTERNAL LOCATION} | i32 | | main.rs:1803:17:1803:33 | ...::my_func(...) | | {EXTERNAL LOCATION} | i32 | | main.rs:1806:26:1806:30 | SelfParam | | {EXTERNAL LOCATION} | & | -| main.rs:1806:26:1806:30 | SelfParam | TRef | file://:0:0:0:0 | * | -| main.rs:1806:26:1806:30 | SelfParam | TRef.TPtr | main.rs:1805:14:1805:23 | T | +| main.rs:1806:26:1806:30 | SelfParam | TRef | file://:0:0:0:0 | *mut | +| main.rs:1806:26:1806:30 | SelfParam | TRef.TPtrMut | main.rs:1805:14:1805:23 | T | | main.rs:1806:39:1808:13 | { ... } | | {EXTERNAL LOCATION} | & | | main.rs:1806:39:1808:13 | { ... } | TRef | main.rs:1805:14:1805:23 | T | | main.rs:1807:17:1807:34 | { ... } | | {EXTERNAL LOCATION} | & | @@ -8569,17 +8569,17 @@ inferType | main.rs:1807:26:1807:32 | &... | | {EXTERNAL LOCATION} | & | | main.rs:1807:26:1807:32 | &... | TRef | main.rs:1805:14:1805:23 | T | | main.rs:1807:27:1807:32 | * ... | | main.rs:1805:14:1805:23 | T | -| main.rs:1807:28:1807:32 | * ... | | file://:0:0:0:0 | * | -| main.rs:1807:28:1807:32 | * ... | TPtr | main.rs:1805:14:1805:23 | T | +| main.rs:1807:28:1807:32 | * ... | | file://:0:0:0:0 | *mut | +| main.rs:1807:28:1807:32 | * ... | TPtrMut | main.rs:1805:14:1805:23 | T | | main.rs:1807:29:1807:32 | self | | {EXTERNAL LOCATION} | & | -| main.rs:1807:29:1807:32 | self | TRef | file://:0:0:0:0 | * | -| main.rs:1807:29:1807:32 | self | TRef.TPtr | main.rs:1805:14:1805:23 | T | +| main.rs:1807:29:1807:32 | self | TRef | file://:0:0:0:0 | *mut | +| main.rs:1807:29:1807:32 | self | TRef.TPtrMut | main.rs:1805:14:1805:23 | T | | main.rs:1810:31:1812:13 | { ... } | | main.rs:1805:14:1805:23 | T | | main.rs:1811:17:1811:28 | ...::default(...) | | main.rs:1805:14:1805:23 | T | | main.rs:1815:17:1815:17 | v | | {EXTERNAL LOCATION} | i32 | | main.rs:1815:21:1815:22 | 42 | | {EXTERNAL LOCATION} | i32 | -| main.rs:1816:13:1816:13 | p | | file://:0:0:0:0 | * | -| main.rs:1816:13:1816:13 | p | TPtr | {EXTERNAL LOCATION} | i32 | +| main.rs:1816:13:1816:13 | p | | file://:0:0:0:0 | *mut | +| main.rs:1816:13:1816:13 | p | TPtrMut | {EXTERNAL LOCATION} | i32 | | main.rs:1816:27:1816:32 | &mut v | | {EXTERNAL LOCATION} | & | | main.rs:1816:27:1816:32 | &mut v | TRef | {EXTERNAL LOCATION} | i32 | | main.rs:1816:32:1816:32 | v | | {EXTERNAL LOCATION} | i32 | @@ -8587,8 +8587,8 @@ inferType | main.rs:1817:13:1817:13 | x | TRef | {EXTERNAL LOCATION} | i32 | | main.rs:1817:17:1817:40 | { ... } | | {EXTERNAL LOCATION} | & | | main.rs:1817:17:1817:40 | { ... } | TRef | {EXTERNAL LOCATION} | i32 | -| main.rs:1817:26:1817:26 | p | | file://:0:0:0:0 | * | -| main.rs:1817:26:1817:26 | p | TPtr | {EXTERNAL LOCATION} | i32 | +| main.rs:1817:26:1817:26 | p | | file://:0:0:0:0 | *mut | +| main.rs:1817:26:1817:26 | p | TPtrMut | {EXTERNAL LOCATION} | i32 | | main.rs:1817:26:1817:38 | p.my_method() | | {EXTERNAL LOCATION} | & | | main.rs:1817:26:1817:38 | p.my_method() | TRef | {EXTERNAL LOCATION} | i32 | | main.rs:1818:13:1818:13 | x | | {EXTERNAL LOCATION} | & | @@ -8598,10 +8598,10 @@ inferType | main.rs:1818:26:1818:48 | ...::my_method(...) | | {EXTERNAL LOCATION} | & | | main.rs:1818:26:1818:48 | ...::my_method(...) | TRef | {EXTERNAL LOCATION} | i32 | | main.rs:1818:46:1818:47 | &p | | {EXTERNAL LOCATION} | & | -| main.rs:1818:46:1818:47 | &p | TRef | file://:0:0:0:0 | * | -| main.rs:1818:46:1818:47 | &p | TRef.TPtr | {EXTERNAL LOCATION} | i32 | -| main.rs:1818:47:1818:47 | p | | file://:0:0:0:0 | * | -| main.rs:1818:47:1818:47 | p | TPtr | {EXTERNAL LOCATION} | i32 | +| main.rs:1818:46:1818:47 | &p | TRef | file://:0:0:0:0 | *mut | +| main.rs:1818:46:1818:47 | &p | TRef.TPtrMut | {EXTERNAL LOCATION} | i32 | +| main.rs:1818:47:1818:47 | p | | file://:0:0:0:0 | *mut | +| main.rs:1818:47:1818:47 | p | TPtrMut | {EXTERNAL LOCATION} | i32 | | main.rs:1819:13:1819:13 | x | | {EXTERNAL LOCATION} | i32 | | main.rs:1819:17:1819:37 | ...::my_func(...) | | {EXTERNAL LOCATION} | i32 | | main.rs:1825:16:1837:5 | { ... } | | {EXTERNAL LOCATION} | () | @@ -12815,71 +12815,86 @@ inferType | pattern_matching.rs:843:5:843:32 | patterns_in_let_statements(...) | | {EXTERNAL LOCATION} | () | | pattern_matching.rs:844:5:844:37 | patterns_in_function_parameters(...) | | {EXTERNAL LOCATION} | () | | pattern_matching.rs:845:5:845:30 | patterns_in_control_flow(...) | | {EXTERNAL LOCATION} | () | -| raw_pointer.rs:3:28:3:28 | x | | file://:0:0:0:0 | * | -| raw_pointer.rs:3:28:3:28 | x | TPtr | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:3:28:3:28 | x | | file://:0:0:0:0 | *const | +| raw_pointer.rs:3:28:3:28 | x | TPtrConst | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:3:50:6:1 | { ... } | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:4:24:4:24 | x | | file://:0:0:0:0 | * | -| raw_pointer.rs:4:24:4:24 | x | TPtr | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:4:9:4:10 | _y | | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:4:14:4:26 | { ... } | | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:4:23:4:24 | * ... | | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:4:24:4:24 | x | | file://:0:0:0:0 | *const | +| raw_pointer.rs:4:24:4:24 | x | TPtrConst | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:5:5:5:5 | 0 | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:8:26:8:26 | x | | file://:0:0:0:0 | * | -| raw_pointer.rs:8:26:8:26 | x | TPtr | {EXTERNAL LOCATION} | bool | +| raw_pointer.rs:8:26:8:26 | x | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:8:26:8:26 | x | TPtrMut | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:8:47:11:1 | { ... } | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:9:24:9:24 | x | | file://:0:0:0:0 | * | -| raw_pointer.rs:9:24:9:24 | x | TPtr | {EXTERNAL LOCATION} | bool | +| raw_pointer.rs:9:9:9:10 | _y | | {EXTERNAL LOCATION} | bool | +| raw_pointer.rs:9:14:9:26 | { ... } | | {EXTERNAL LOCATION} | bool | +| raw_pointer.rs:9:23:9:24 | * ... | | {EXTERNAL LOCATION} | bool | +| raw_pointer.rs:9:24:9:24 | x | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:9:24:9:24 | x | TPtrMut | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:10:5:10:5 | 0 | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:13:23:19:1 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:14:9:14:9 | a | | {EXTERNAL LOCATION} | i64 | | raw_pointer.rs:14:18:14:19 | 10 | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:14:18:14:19 | 10 | | {EXTERNAL LOCATION} | i64 | -| raw_pointer.rs:15:9:15:9 | x | | {EXTERNAL LOCATION} | & | -| raw_pointer.rs:15:9:15:9 | x | TRef | {EXTERNAL LOCATION} | i64 | -| raw_pointer.rs:15:13:15:24 | &raw const a | | {EXTERNAL LOCATION} | & | -| raw_pointer.rs:15:13:15:24 | &raw const a | TRef | {EXTERNAL LOCATION} | i64 | +| raw_pointer.rs:15:9:15:9 | x | | file://:0:0:0:0 | *const | +| raw_pointer.rs:15:9:15:9 | x | TPtrConst | {EXTERNAL LOCATION} | i64 | +| raw_pointer.rs:15:13:15:24 | &raw const a | | file://:0:0:0:0 | *const | +| raw_pointer.rs:15:13:15:24 | &raw const a | TPtrConst | {EXTERNAL LOCATION} | i64 | | raw_pointer.rs:15:24:15:24 | a | | {EXTERNAL LOCATION} | i64 | | raw_pointer.rs:16:5:18:5 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:17:13:17:14 | _y | | {EXTERNAL LOCATION} | i64 | | raw_pointer.rs:17:18:17:19 | * ... | | {EXTERNAL LOCATION} | i64 | -| raw_pointer.rs:17:19:17:19 | x | | {EXTERNAL LOCATION} | & | -| raw_pointer.rs:17:19:17:19 | x | TRef | {EXTERNAL LOCATION} | i64 | +| raw_pointer.rs:17:19:17:19 | x | | file://:0:0:0:0 | *const | +| raw_pointer.rs:17:19:17:19 | x | TPtrConst | {EXTERNAL LOCATION} | i64 | | raw_pointer.rs:21:21:27:1 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:22:13:22:13 | a | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:22:17:22:21 | 10i32 | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:23:9:23:9 | x | | {EXTERNAL LOCATION} | & | -| raw_pointer.rs:23:9:23:9 | x | TRef | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:23:13:23:22 | &raw mut a | | {EXTERNAL LOCATION} | & | -| raw_pointer.rs:23:13:23:22 | &raw mut a | TRef | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:23:9:23:9 | x | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:23:9:23:9 | x | TPtrMut | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:23:13:23:22 | &raw mut a | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:23:13:23:22 | &raw mut a | TPtrMut | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:23:22:23:22 | a | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:24:5:26:5 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:25:13:25:14 | _y | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:25:18:25:19 | * ... | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:25:19:25:19 | x | | {EXTERNAL LOCATION} | & | -| raw_pointer.rs:25:19:25:19 | x | TRef | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:25:19:25:19 | x | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:25:19:25:19 | x | TPtrMut | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:29:18:29:21 | cond | | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:29:30:40:1 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:30:9:30:9 | a | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:30:13:30:17 | 10i32 | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:32:9:32:19 | ptr_written | | file://:0:0:0:0 | * | -| raw_pointer.rs:32:23:32:32 | null_mut(...) | | file://:0:0:0:0 | * | +| raw_pointer.rs:32:9:32:19 | ptr_written | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:32:9:32:19 | ptr_written | TPtrMut | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:32:23:32:32 | null_mut(...) | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:32:23:32:32 | null_mut(...) | TPtrMut | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:33:5:39:5 | if cond {...} | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:33:8:33:11 | cond | | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:33:13:39:5 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:34:9:38:9 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:36:13:36:24 | * ... | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:36:13:36:28 | ... = ... | | {EXTERNAL LOCATION} | () | -| raw_pointer.rs:36:14:36:24 | ptr_written | | file://:0:0:0:0 | * | +| raw_pointer.rs:36:14:36:24 | ptr_written | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:36:14:36:24 | ptr_written | TPtrMut | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:36:28:36:28 | a | | {EXTERNAL LOCATION} | i32 | -| raw_pointer.rs:37:23:37:33 | ptr_written | | file://:0:0:0:0 | * | +| raw_pointer.rs:37:17:37:18 | _y | | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:37:22:37:33 | * ... | | {EXTERNAL LOCATION} | i32 | +| raw_pointer.rs:37:23:37:33 | ptr_written | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:37:23:37:33 | ptr_written | TPtrMut | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:42:24:42:27 | cond | | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:42:36:51:1 | { ... } | | {EXTERNAL LOCATION} | () | -| raw_pointer.rs:44:9:44:16 | ptr_read | | file://:0:0:0:0 | * | -| raw_pointer.rs:44:20:44:29 | null_mut(...) | | file://:0:0:0:0 | * | +| raw_pointer.rs:44:9:44:16 | ptr_read | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:44:9:44:16 | ptr_read | TPtrMut | {EXTERNAL LOCATION} | i64 | +| raw_pointer.rs:44:20:44:29 | null_mut(...) | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:44:20:44:29 | null_mut(...) | TPtrMut | {EXTERNAL LOCATION} | i64 | | raw_pointer.rs:45:5:50:5 | if cond {...} | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:45:8:45:11 | cond | | {EXTERNAL LOCATION} | bool | | raw_pointer.rs:45:13:50:5 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:46:9:49:9 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:48:17:48:18 | _y | | {EXTERNAL LOCATION} | i64 | | raw_pointer.rs:48:27:48:35 | * ... | | {EXTERNAL LOCATION} | i64 | -| raw_pointer.rs:48:28:48:35 | ptr_read | | file://:0:0:0:0 | * | +| raw_pointer.rs:48:28:48:35 | ptr_read | | file://:0:0:0:0 | *mut | +| raw_pointer.rs:48:28:48:35 | ptr_read | TPtrMut | {EXTERNAL LOCATION} | i64 | | raw_pointer.rs:53:15:60:1 | { ... } | | {EXTERNAL LOCATION} | () | | raw_pointer.rs:54:5:54:32 | raw_pointer_const_deref(...) | | {EXTERNAL LOCATION} | i32 | | raw_pointer.rs:54:29:54:31 | &10 | | {EXTERNAL LOCATION} | & | diff --git a/rust/tools/builtins/types.rs b/rust/tools/builtins/types.rs index fc0be525ab4..d3fd06b2168 100644 --- a/rust/tools/builtins/types.rs +++ b/rust/tools/builtins/types.rs @@ -28,7 +28,7 @@ struct Slice; struct Array; struct Ref; struct RefMut; -struct Ptr; +struct PtrConst; struct PtrMut; // tuples