Skip to content

Commit 51db2c0

Browse files
committed
Rust: More type inference tests
1 parent 2e5b7f8 commit 51db2c0

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
multipleResolvedTargets
22
| main.rs:2720:13:2720:17 | x.f() |
3+
| overloading.rs:197:22:197:30 | x.g(...) |

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,50 @@ pub mod impl_overlap {
150150
S5::m(&S5(true)); // $ target=MyTrait1::m
151151
}
152152
}
153+
154+
mod impl_overlap2 {
155+
trait Trait1<T1> {
156+
fn f(self, x: T1) -> T1;
157+
}
158+
159+
impl Trait1<i32> for i32 {
160+
// f1
161+
fn f(self, x: i32) -> i32 {
162+
0
163+
}
164+
}
165+
166+
impl Trait1<i64> for i32 {
167+
// f2
168+
fn f(self, x: i64) -> i64 {
169+
0
170+
}
171+
}
172+
173+
trait Trait2<T1, T2> {
174+
fn g(self, x: T1) -> T2;
175+
}
176+
177+
impl Trait2<i32, i32> for i32 {
178+
// g3
179+
fn g(self, x: i32) -> i32 {
180+
0
181+
}
182+
}
183+
184+
impl Trait2<i32, i64> for i32 {
185+
// g4
186+
fn g(self, x: i32) -> i64 {
187+
0
188+
}
189+
}
190+
191+
fn f() {
192+
let x = 0;
193+
let y = x.f(0i32); // $ target=f1
194+
let z: i32 = x.f(Default::default()); // $ MISSING: target=f1 target=default
195+
let z = x.f(0i64); // $ target=f2
196+
let z: i64 = x.f(Default::default()); // $ MISSING: target=f2 target=default
197+
let z: i64 = x.g(0i32); // $ target=g4 $ SPURIOUS: target=g3
198+
}
199+
}

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,6 +3769,29 @@ inferCertainType
37693769
| overloading.rs:150:9:150:24 | ...::m(...) | | {EXTERNAL LOCATION} | () |
37703770
| overloading.rs:150:15:150:23 | &... | | {EXTERNAL LOCATION} | & |
37713771
| overloading.rs:150:19:150:22 | true | | {EXTERNAL LOCATION} | bool |
3772+
| overloading.rs:156:14:156:17 | SelfParam | | overloading.rs:155:5:157:5 | Self [trait Trait1] |
3773+
| overloading.rs:156:20:156:20 | x | | overloading.rs:155:18:155:19 | T1 |
3774+
| overloading.rs:161:14:161:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
3775+
| overloading.rs:161:20:161:20 | x | | {EXTERNAL LOCATION} | i32 |
3776+
| overloading.rs:161:35:163:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
3777+
| overloading.rs:168:14:168:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
3778+
| overloading.rs:168:20:168:20 | x | | {EXTERNAL LOCATION} | i64 |
3779+
| overloading.rs:168:35:170:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
3780+
| overloading.rs:174:14:174:17 | SelfParam | | overloading.rs:173:5:175:5 | Self [trait Trait2] |
3781+
| overloading.rs:174:20:174:20 | x | | overloading.rs:173:18:173:19 | T1 |
3782+
| overloading.rs:179:14:179:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
3783+
| overloading.rs:179:20:179:20 | x | | {EXTERNAL LOCATION} | i32 |
3784+
| overloading.rs:179:35:181:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
3785+
| overloading.rs:186:14:186:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
3786+
| overloading.rs:186:20:186:20 | x | | {EXTERNAL LOCATION} | i32 |
3787+
| overloading.rs:186:35:188:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
3788+
| overloading.rs:191:12:198:5 | { ... } | | {EXTERNAL LOCATION} | () |
3789+
| overloading.rs:193:21:193:24 | 0i32 | | {EXTERNAL LOCATION} | i32 |
3790+
| overloading.rs:194:13:194:13 | z | | {EXTERNAL LOCATION} | i32 |
3791+
| overloading.rs:195:21:195:24 | 0i64 | | {EXTERNAL LOCATION} | i64 |
3792+
| overloading.rs:196:13:196:13 | z | | {EXTERNAL LOCATION} | i64 |
3793+
| overloading.rs:197:13:197:13 | z | | {EXTERNAL LOCATION} | i64 |
3794+
| overloading.rs:197:26:197:29 | 0i32 | | {EXTERNAL LOCATION} | i32 |
37723795
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
37733796
| pattern_matching.rs:13:26:133:1 | { ... } | T | {EXTERNAL LOCATION} | () |
37743797
| pattern_matching.rs:15:5:18:5 | if ... {...} | | {EXTERNAL LOCATION} | () |
@@ -11933,6 +11956,50 @@ inferType
1193311956
| overloading.rs:150:16:150:23 | S5(...) | | overloading.rs:111:5:112:22 | S5 |
1193411957
| overloading.rs:150:16:150:23 | S5(...) | T5 | {EXTERNAL LOCATION} | bool |
1193511958
| overloading.rs:150:19:150:22 | true | | {EXTERNAL LOCATION} | bool |
11959+
| overloading.rs:156:14:156:17 | SelfParam | | overloading.rs:155:5:157:5 | Self [trait Trait1] |
11960+
| overloading.rs:156:20:156:20 | x | | overloading.rs:155:18:155:19 | T1 |
11961+
| overloading.rs:161:14:161:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
11962+
| overloading.rs:161:20:161:20 | x | | {EXTERNAL LOCATION} | i32 |
11963+
| overloading.rs:161:35:163:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
11964+
| overloading.rs:162:13:162:13 | 0 | | {EXTERNAL LOCATION} | i32 |
11965+
| overloading.rs:168:14:168:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
11966+
| overloading.rs:168:20:168:20 | x | | {EXTERNAL LOCATION} | i64 |
11967+
| overloading.rs:168:35:170:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
11968+
| overloading.rs:169:13:169:13 | 0 | | {EXTERNAL LOCATION} | i32 |
11969+
| overloading.rs:169:13:169:13 | 0 | | {EXTERNAL LOCATION} | i64 |
11970+
| overloading.rs:174:14:174:17 | SelfParam | | overloading.rs:173:5:175:5 | Self [trait Trait2] |
11971+
| overloading.rs:174:20:174:20 | x | | overloading.rs:173:18:173:19 | T1 |
11972+
| overloading.rs:179:14:179:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
11973+
| overloading.rs:179:20:179:20 | x | | {EXTERNAL LOCATION} | i32 |
11974+
| overloading.rs:179:35:181:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
11975+
| overloading.rs:180:13:180:13 | 0 | | {EXTERNAL LOCATION} | i32 |
11976+
| overloading.rs:186:14:186:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
11977+
| overloading.rs:186:20:186:20 | x | | {EXTERNAL LOCATION} | i32 |
11978+
| overloading.rs:186:35:188:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
11979+
| overloading.rs:187:13:187:13 | 0 | | {EXTERNAL LOCATION} | i32 |
11980+
| overloading.rs:187:13:187:13 | 0 | | {EXTERNAL LOCATION} | i64 |
11981+
| overloading.rs:191:12:198:5 | { ... } | | {EXTERNAL LOCATION} | () |
11982+
| overloading.rs:192:13:192:13 | x | | {EXTERNAL LOCATION} | i32 |
11983+
| overloading.rs:192:17:192:17 | 0 | | {EXTERNAL LOCATION} | i32 |
11984+
| overloading.rs:193:13:193:13 | y | | {EXTERNAL LOCATION} | i32 |
11985+
| overloading.rs:193:17:193:17 | x | | {EXTERNAL LOCATION} | i32 |
11986+
| overloading.rs:193:17:193:25 | x.f(...) | | {EXTERNAL LOCATION} | i32 |
11987+
| overloading.rs:193:21:193:24 | 0i32 | | {EXTERNAL LOCATION} | i32 |
11988+
| overloading.rs:194:13:194:13 | z | | {EXTERNAL LOCATION} | i32 |
11989+
| overloading.rs:194:22:194:22 | x | | {EXTERNAL LOCATION} | i32 |
11990+
| overloading.rs:194:22:194:44 | x.f(...) | | {EXTERNAL LOCATION} | i32 |
11991+
| overloading.rs:195:13:195:13 | z | | {EXTERNAL LOCATION} | i64 |
11992+
| overloading.rs:195:17:195:17 | x | | {EXTERNAL LOCATION} | i32 |
11993+
| overloading.rs:195:17:195:25 | x.f(...) | | {EXTERNAL LOCATION} | i64 |
11994+
| overloading.rs:195:21:195:24 | 0i64 | | {EXTERNAL LOCATION} | i64 |
11995+
| overloading.rs:196:13:196:13 | z | | {EXTERNAL LOCATION} | i64 |
11996+
| overloading.rs:196:22:196:22 | x | | {EXTERNAL LOCATION} | i32 |
11997+
| overloading.rs:196:22:196:44 | x.f(...) | | {EXTERNAL LOCATION} | i64 |
11998+
| overloading.rs:197:13:197:13 | z | | {EXTERNAL LOCATION} | i64 |
11999+
| overloading.rs:197:22:197:22 | x | | {EXTERNAL LOCATION} | i32 |
12000+
| overloading.rs:197:22:197:30 | x.g(...) | | {EXTERNAL LOCATION} | i32 |
12001+
| overloading.rs:197:22:197:30 | x.g(...) | | {EXTERNAL LOCATION} | i64 |
12002+
| overloading.rs:197:26:197:29 | 0i32 | | {EXTERNAL LOCATION} | i32 |
1193612003
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
1193712004
| pattern_matching.rs:13:26:133:1 | { ... } | T | {EXTERNAL LOCATION} | () |
1193812005
| pattern_matching.rs:14:9:14:13 | value | | {EXTERNAL LOCATION} | Option |

0 commit comments

Comments
 (0)