Skip to content

Commit 5c458ce

Browse files
committed
Rust: Add type inference test
1 parent f2e7dca commit 5c458ce

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,36 @@ mod from_default {
400400
x
401401
}
402402
}
403+
404+
mod trait_bound_impl_overlap {
405+
trait MyTrait<T> {
406+
fn f(&self) -> T;
407+
}
408+
409+
struct S<T>(T);
410+
411+
impl MyTrait<i32> for S<i32> {
412+
fn f(&self) -> i32 {
413+
0
414+
}
415+
}
416+
417+
impl MyTrait<i64> for S<i32> {
418+
fn f(&self) -> i64 {
419+
0
420+
}
421+
}
422+
423+
fn call_f<T1, T2: MyTrait<T1>>(x: T2) -> T1 {
424+
x.f() // $ target=f
425+
}
426+
427+
fn test() {
428+
let x = S(0);
429+
let y = call_f(x); // $ target=call_f type=y:i32 $ SPURIOUS: type=y:i64
430+
let z: i32 = y;
431+
432+
let x = S(0);
433+
let y = call_f::<i32, _>(x); // $ target=call_f type=y:i32
434+
}
435+
}

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,6 +4012,23 @@ inferCertainType
40124012
| overloading.rs:397:10:397:10 | b | | {EXTERNAL LOCATION} | bool |
40134013
| overloading.rs:397:25:401:5 | { ... } | | overloading.rs:372:5:372:14 | S1 |
40144014
| overloading.rs:398:20:398:20 | b | | {EXTERNAL LOCATION} | bool |
4015+
| overloading.rs:406:14:406:18 | SelfParam | | {EXTERNAL LOCATION} | & |
4016+
| overloading.rs:406:14:406:18 | SelfParam | TRef | overloading.rs:405:5:407:5 | Self [trait MyTrait] |
4017+
| overloading.rs:412:14:412:18 | SelfParam | | {EXTERNAL LOCATION} | & |
4018+
| overloading.rs:412:14:412:18 | SelfParam | TRef | overloading.rs:409:5:409:19 | S |
4019+
| overloading.rs:412:14:412:18 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
4020+
| overloading.rs:412:28:414:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
4021+
| overloading.rs:418:14:418:18 | SelfParam | | {EXTERNAL LOCATION} | & |
4022+
| overloading.rs:418:14:418:18 | SelfParam | TRef | overloading.rs:409:5:409:19 | S |
4023+
| overloading.rs:418:14:418:18 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
4024+
| overloading.rs:418:28:420:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
4025+
| overloading.rs:423:36:423:36 | x | | overloading.rs:423:19:423:33 | T2 |
4026+
| overloading.rs:423:49:425:5 | { ... } | | overloading.rs:423:15:423:16 | T1 |
4027+
| overloading.rs:424:9:424:9 | x | | overloading.rs:423:19:423:33 | T2 |
4028+
| overloading.rs:427:15:434:5 | { ... } | | {EXTERNAL LOCATION} | () |
4029+
| overloading.rs:430:13:430:13 | z | | {EXTERNAL LOCATION} | i32 |
4030+
| overloading.rs:433:13:433:13 | y | | {EXTERNAL LOCATION} | i32 |
4031+
| overloading.rs:433:17:433:35 | call_f::<...>(...) | | {EXTERNAL LOCATION} | i32 |
40154032
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
40164033
| pattern_matching.rs:13:26:133:1 | { ... } | T | {EXTERNAL LOCATION} | () |
40174034
| pattern_matching.rs:15:5:18:5 | if ... {...} | | {EXTERNAL LOCATION} | () |
@@ -12675,6 +12692,47 @@ inferType
1267512692
| overloading.rs:399:17:399:29 | ...::from(...) | | overloading.rs:372:5:372:14 | S1 |
1267612693
| overloading.rs:399:28:399:28 | s | | overloading.rs:364:5:365:13 | S |
1267712694
| overloading.rs:400:9:400:9 | x | | overloading.rs:372:5:372:14 | S1 |
12695+
| overloading.rs:406:14:406:18 | SelfParam | | {EXTERNAL LOCATION} | & |
12696+
| overloading.rs:406:14:406:18 | SelfParam | TRef | overloading.rs:405:5:407:5 | Self [trait MyTrait] |
12697+
| overloading.rs:412:14:412:18 | SelfParam | | {EXTERNAL LOCATION} | & |
12698+
| overloading.rs:412:14:412:18 | SelfParam | TRef | overloading.rs:409:5:409:19 | S |
12699+
| overloading.rs:412:14:412:18 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
12700+
| overloading.rs:412:28:414:9 | { ... } | | {EXTERNAL LOCATION} | i32 |
12701+
| overloading.rs:413:13:413:13 | 0 | | {EXTERNAL LOCATION} | i32 |
12702+
| overloading.rs:418:14:418:18 | SelfParam | | {EXTERNAL LOCATION} | & |
12703+
| overloading.rs:418:14:418:18 | SelfParam | TRef | overloading.rs:409:5:409:19 | S |
12704+
| overloading.rs:418:14:418:18 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
12705+
| overloading.rs:418:28:420:9 | { ... } | | {EXTERNAL LOCATION} | i64 |
12706+
| overloading.rs:419:13:419:13 | 0 | | {EXTERNAL LOCATION} | i32 |
12707+
| overloading.rs:419:13:419:13 | 0 | | {EXTERNAL LOCATION} | i64 |
12708+
| overloading.rs:423:36:423:36 | x | | overloading.rs:423:19:423:33 | T2 |
12709+
| overloading.rs:423:49:425:5 | { ... } | | overloading.rs:423:15:423:16 | T1 |
12710+
| overloading.rs:424:9:424:9 | x | | overloading.rs:423:19:423:33 | T2 |
12711+
| overloading.rs:424:9:424:13 | x.f() | | overloading.rs:423:15:423:16 | T1 |
12712+
| overloading.rs:427:15:434:5 | { ... } | | {EXTERNAL LOCATION} | () |
12713+
| overloading.rs:428:13:428:13 | x | | overloading.rs:409:5:409:19 | S |
12714+
| overloading.rs:428:13:428:13 | x | T | {EXTERNAL LOCATION} | i32 |
12715+
| overloading.rs:428:17:428:20 | S(...) | | overloading.rs:409:5:409:19 | S |
12716+
| overloading.rs:428:17:428:20 | S(...) | T | {EXTERNAL LOCATION} | i32 |
12717+
| overloading.rs:428:19:428:19 | 0 | | {EXTERNAL LOCATION} | i32 |
12718+
| overloading.rs:429:13:429:13 | y | | {EXTERNAL LOCATION} | i32 |
12719+
| overloading.rs:429:13:429:13 | y | | {EXTERNAL LOCATION} | i64 |
12720+
| overloading.rs:429:17:429:25 | call_f(...) | | {EXTERNAL LOCATION} | i32 |
12721+
| overloading.rs:429:17:429:25 | call_f(...) | | {EXTERNAL LOCATION} | i64 |
12722+
| overloading.rs:429:24:429:24 | x | | overloading.rs:409:5:409:19 | S |
12723+
| overloading.rs:429:24:429:24 | x | T | {EXTERNAL LOCATION} | i32 |
12724+
| overloading.rs:430:13:430:13 | z | | {EXTERNAL LOCATION} | i32 |
12725+
| overloading.rs:430:22:430:22 | y | | {EXTERNAL LOCATION} | i32 |
12726+
| overloading.rs:430:22:430:22 | y | | {EXTERNAL LOCATION} | i64 |
12727+
| overloading.rs:432:13:432:13 | x | | overloading.rs:409:5:409:19 | S |
12728+
| overloading.rs:432:13:432:13 | x | T | {EXTERNAL LOCATION} | i32 |
12729+
| overloading.rs:432:17:432:20 | S(...) | | overloading.rs:409:5:409:19 | S |
12730+
| overloading.rs:432:17:432:20 | S(...) | T | {EXTERNAL LOCATION} | i32 |
12731+
| overloading.rs:432:19:432:19 | 0 | | {EXTERNAL LOCATION} | i32 |
12732+
| overloading.rs:433:13:433:13 | y | | {EXTERNAL LOCATION} | i32 |
12733+
| overloading.rs:433:17:433:35 | call_f::<...>(...) | | {EXTERNAL LOCATION} | i32 |
12734+
| overloading.rs:433:34:433:34 | x | | overloading.rs:409:5:409:19 | S |
12735+
| overloading.rs:433:34:433:34 | x | T | {EXTERNAL LOCATION} | i32 |
1267812736
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
1267912737
| pattern_matching.rs:13:26:133:1 | { ... } | T | {EXTERNAL LOCATION} | () |
1268012738
| pattern_matching.rs:14:9:14:13 | value | | {EXTERNAL LOCATION} | Option |

0 commit comments

Comments
 (0)