Skip to content

Commit c14764e

Browse files
committed
more
1 parent 34d05a0 commit c14764e

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

rust/ql/lib/codeql/rust/elements/internal/TypeInference.qll

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,11 +775,28 @@ private Type resolveTargetTyped(AstNode n, TypePath path) {
775775
}
776776

777777
private module RecordFieldMatchingInput implements MatchingInputSig {
778-
class Decl extends Struct {
779-
// todo or variant
780-
TypeParameter getTypeParameter(int i) {
778+
abstract class Decl extends AstNode {
779+
abstract TypeParameter getTypeParameter(int i);
780+
781+
abstract RecordField getField(string name);
782+
}
783+
784+
private class StructDecl extends Decl, Struct {
785+
override TypeParameter getTypeParameter(int i) {
781786
result.getTypeParam() = this.getGenericParamList().getTypeParam(i)
782787
}
788+
789+
override RecordField getField(string name) { result = this.getRecordField(name) }
790+
}
791+
792+
private class VariantDecl extends Decl, Variant {
793+
Enum getEnum() { result.getVariantList().getAVariant() = this }
794+
795+
override TypeParameter getTypeParameter(int i) {
796+
result.getTypeParam() = this.getEnum().getGenericParamList().getTypeParam(i)
797+
}
798+
799+
override RecordField getField(string name) { result = this.getRecordField(name) }
783800
}
784801

785802
class Access extends RecordExpr {
@@ -834,7 +851,7 @@ private module RecordFieldMatchingInput implements MatchingInputSig {
834851
}
835852

836853
predicate parameterType(Decl decl, Pos pos, TypePath path, Type t) {
837-
exists(TypeRepr_ tp | tp = decl.getRecordField(pos).getTypeRepr() | t = tp.resolveTypeAt(path))
854+
exists(TypeRepr_ tp | tp = decl.getField(pos).getTypeRepr() | t = tp.resolveTypeAt(path))
838855
}
839856

840857
pragma[nomagic]

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ mod m6 {
227227

228228
pub fn f() {
229229
let x = MyEnum::C1(S1); // `MyEnum::C1(S1)` missing type at path 0
230-
let y = MyEnum::C2 { a: S2 }; // `MyEnum::C2 { a: S2 }` missing type
230+
let y = MyEnum::C2 { a: S2 }; // `MyEnum::C2 { a: S2 }` missing type at ""
231231

232232
println!("{:?}", x.m1()); // `x.m1` missing type
233233
println!("{:?}", y.m1()); // `y`, `y.m1` missing type

rust/ql/test/library-tests/type-inference/type-inference.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,11 @@
160160
| main.rs:229:17:229:26 | ...::C1 | | main.rs:208:5:212:5 | enum MyEnum |
161161
| main.rs:229:17:229:30 | ...::C1(...) | | main.rs:208:5:212:5 | enum MyEnum |
162162
| main.rs:229:28:229:29 | S1 | | main.rs:214:5:215:14 | struct S1 |
163+
| main.rs:230:13:230:13 | y | 0 | main.rs:216:5:217:14 | struct S2 |
164+
| main.rs:230:17:230:36 | ...::C2 {...} | 0 | main.rs:216:5:217:14 | struct S2 |
163165
| main.rs:230:33:230:34 | S2 | | main.rs:216:5:217:14 | struct S2 |
164166
| main.rs:232:26:232:26 | x | | main.rs:208:5:212:5 | enum MyEnum |
167+
| main.rs:233:26:233:26 | y | 0 | main.rs:216:5:217:14 | struct S2 |
165168
| main.rs:238:5:238:9 | ...::f | | main.rs:2:5:2:21 | struct Foo |
166169
| main.rs:238:5:238:11 | ...::f(...) | | main.rs:2:5:2:21 | struct Foo |
167170
| main.rs:239:5:239:9 | ...::g | | main.rs:2:5:2:21 | struct Foo |

0 commit comments

Comments
 (0)