Skip to content

Commit 83d1f0e

Browse files
committed
Rust: More type inference tests
1 parent 7ad1c22 commit 83d1f0e

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
@@ -3845,6 +3845,29 @@ inferCertainType
38453845
| overloading.rs:150:9:150:24 | ...::m(...) | | {EXTERNAL LOCATION} | () |
38463846
| overloading.rs:150:15:150:23 | &... | | {EXTERNAL LOCATION} | & |
38473847
| overloading.rs:150:19:150:22 | true | | {EXTERNAL LOCATION} | bool |
3848+
| overloading.rs:156:14:156:17 | SelfParam | | overloading.rs:155:5:157:5 | Self [trait Trait1] |
3849+
| overloading.rs:156:20:156:20 | x | | overloading.rs:155:18:155:19 | T1 |
3850+
| overloading.rs:161:14:161:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
3851+
| overloading.rs:161:20:161:20 | x | | {EXTERNAL LOCATION} | i32 |
3852+
| overloading.rs:161:35:163:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
3853+
| overloading.rs:168:14:168:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
3854+
| overloading.rs:168:20:168:20 | x | | {EXTERNAL LOCATION} | i64 |
3855+
| overloading.rs:168:35:170:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
3856+
| overloading.rs:174:14:174:17 | SelfParam | | overloading.rs:173:5:175:5 | Self [trait Trait2] |
3857+
| overloading.rs:174:20:174:20 | x | | overloading.rs:173:18:173:19 | T1 |
3858+
| overloading.rs:179:14:179:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
3859+
| overloading.rs:179:20:179:20 | x | | {EXTERNAL LOCATION} | i32 |
3860+
| overloading.rs:179:35:181:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
3861+
| overloading.rs:186:14:186:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
3862+
| overloading.rs:186:20:186:20 | x | | {EXTERNAL LOCATION} | i32 |
3863+
| overloading.rs:186:35:188:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
3864+
| overloading.rs:191:12:198:5 | { ... } | | {EXTERNAL LOCATION} | () |
3865+
| overloading.rs:193:21:193:24 | 0i32 | | {EXTERNAL LOCATION} | i32 |
3866+
| overloading.rs:194:13:194:13 | z | | {EXTERNAL LOCATION} | i32 |
3867+
| overloading.rs:195:21:195:24 | 0i64 | | {EXTERNAL LOCATION} | i64 |
3868+
| overloading.rs:196:13:196:13 | z | | {EXTERNAL LOCATION} | i64 |
3869+
| overloading.rs:197:13:197:13 | z | | {EXTERNAL LOCATION} | i64 |
3870+
| overloading.rs:197:26:197:29 | 0i32 | | {EXTERNAL LOCATION} | i32 |
38483871
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
38493872
| pattern_matching.rs:13:26:133:1 | { ... } | T | {EXTERNAL LOCATION} | () |
38503873
| pattern_matching.rs:15:5:18:5 | if ... {...} | | {EXTERNAL LOCATION} | () |
@@ -12137,6 +12160,50 @@ inferType
1213712160
| overloading.rs:150:16:150:23 | S5(...) | | overloading.rs:111:5:112:22 | S5 |
1213812161
| overloading.rs:150:16:150:23 | S5(...) | T5 | {EXTERNAL LOCATION} | bool |
1213912162
| overloading.rs:150:19:150:22 | true | | {EXTERNAL LOCATION} | bool |
12163+
| overloading.rs:156:14:156:17 | SelfParam | | overloading.rs:155:5:157:5 | Self [trait Trait1] |
12164+
| overloading.rs:156:20:156:20 | x | | overloading.rs:155:18:155:19 | T1 |
12165+
| overloading.rs:161:14:161:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
12166+
| overloading.rs:161:20:161:20 | x | | {EXTERNAL LOCATION} | i32 |
12167+
| overloading.rs:161:35:163:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
12168+
| overloading.rs:162:13:162:13 | 0 | | {EXTERNAL LOCATION} | i32 |
12169+
| overloading.rs:168:14:168:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
12170+
| overloading.rs:168:20:168:20 | x | | {EXTERNAL LOCATION} | i64 |
12171+
| overloading.rs:168:35:170:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
12172+
| overloading.rs:169:13:169:13 | 0 | | {EXTERNAL LOCATION} | i32 |
12173+
| overloading.rs:169:13:169:13 | 0 | | {EXTERNAL LOCATION} | i64 |
12174+
| overloading.rs:174:14:174:17 | SelfParam | | overloading.rs:173:5:175:5 | Self [trait Trait2] |
12175+
| overloading.rs:174:20:174:20 | x | | overloading.rs:173:18:173:19 | T1 |
12176+
| overloading.rs:179:14:179:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
12177+
| overloading.rs:179:20:179:20 | x | | {EXTERNAL LOCATION} | i32 |
12178+
| overloading.rs:179:35:181:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
12179+
| overloading.rs:180:13:180:13 | 0 | | {EXTERNAL LOCATION} | i32 |
12180+
| overloading.rs:186:14:186:17 | SelfParam | | {EXTERNAL LOCATION} | i32 |
12181+
| overloading.rs:186:20:186:20 | x | | {EXTERNAL LOCATION} | i32 |
12182+
| overloading.rs:186:35:188:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
12183+
| overloading.rs:187:13:187:13 | 0 | | {EXTERNAL LOCATION} | i32 |
12184+
| overloading.rs:187:13:187:13 | 0 | | {EXTERNAL LOCATION} | i64 |
12185+
| overloading.rs:191:12:198:5 | { ... } | | {EXTERNAL LOCATION} | () |
12186+
| overloading.rs:192:13:192:13 | x | | {EXTERNAL LOCATION} | i32 |
12187+
| overloading.rs:192:17:192:17 | 0 | | {EXTERNAL LOCATION} | i32 |
12188+
| overloading.rs:193:13:193:13 | y | | {EXTERNAL LOCATION} | i32 |
12189+
| overloading.rs:193:17:193:17 | x | | {EXTERNAL LOCATION} | i32 |
12190+
| overloading.rs:193:17:193:25 | x.f(...) | | {EXTERNAL LOCATION} | i32 |
12191+
| overloading.rs:193:21:193:24 | 0i32 | | {EXTERNAL LOCATION} | i32 |
12192+
| overloading.rs:194:13:194:13 | z | | {EXTERNAL LOCATION} | i32 |
12193+
| overloading.rs:194:22:194:22 | x | | {EXTERNAL LOCATION} | i32 |
12194+
| overloading.rs:194:22:194:44 | x.f(...) | | {EXTERNAL LOCATION} | i32 |
12195+
| overloading.rs:195:13:195:13 | z | | {EXTERNAL LOCATION} | i64 |
12196+
| overloading.rs:195:17:195:17 | x | | {EXTERNAL LOCATION} | i32 |
12197+
| overloading.rs:195:17:195:25 | x.f(...) | | {EXTERNAL LOCATION} | i64 |
12198+
| overloading.rs:195:21:195:24 | 0i64 | | {EXTERNAL LOCATION} | i64 |
12199+
| overloading.rs:196:13:196:13 | z | | {EXTERNAL LOCATION} | i64 |
12200+
| overloading.rs:196:22:196:22 | x | | {EXTERNAL LOCATION} | i32 |
12201+
| overloading.rs:196:22:196:44 | x.f(...) | | {EXTERNAL LOCATION} | i64 |
12202+
| overloading.rs:197:13:197:13 | z | | {EXTERNAL LOCATION} | i64 |
12203+
| overloading.rs:197:22:197:22 | x | | {EXTERNAL LOCATION} | i32 |
12204+
| overloading.rs:197:22:197:30 | x.g(...) | | {EXTERNAL LOCATION} | i32 |
12205+
| overloading.rs:197:22:197:30 | x.g(...) | | {EXTERNAL LOCATION} | i64 |
12206+
| overloading.rs:197:26:197:29 | 0i32 | | {EXTERNAL LOCATION} | i32 |
1214012207
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
1214112208
| pattern_matching.rs:13:26:133:1 | { ... } | T | {EXTERNAL LOCATION} | () |
1214212209
| pattern_matching.rs:14:9:14:13 | value | | {EXTERNAL LOCATION} | Option |

0 commit comments

Comments
 (0)