Skip to content

Commit 88b202f

Browse files
committed
test
1 parent 676d0af commit 88b202f

2 files changed

Lines changed: 181 additions & 0 deletions

File tree

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,52 @@ mod from_default {
400400
x
401401
}
402402
}
403+
404+
mod inherent_before_trait {
405+
struct S<T>(T);
406+
407+
trait Trait {
408+
fn foo(&self);
409+
fn bar(&self);
410+
}
411+
412+
impl S<i32> {
413+
// S<i32>::foo
414+
fn foo(x: &Self) {}
415+
416+
// S<i32>::bar
417+
fn bar(&self) {}
418+
}
419+
420+
impl Trait for S<i32> {
421+
// <S<i32>_as_Trait>::foo
422+
fn foo(&self) {
423+
S::foo(self); // $ MISSING: target=S<i32>::foo
424+
S::<i32>::foo(self); // $ MISSING: target=S<i32>::foo
425+
self.foo() // $ target=<S<i32>_as_Trait>::foo
426+
}
427+
428+
// <S<i32>_as_Trait>::bar
429+
fn bar(&self) {
430+
S::bar(self); // $ target=S<i32>::bar
431+
S::<i32>::bar(self); // $ target=S<i32>::bar
432+
self.bar() // $ target=S<i32>::bar
433+
}
434+
}
435+
436+
impl Trait for S<i64> {
437+
// <S<i64>_as_Trait>::foo
438+
fn foo(&self) {
439+
// `S::foo(self);` is not valid
440+
S::<i64>::foo(self); // $ MISSING: target=<S<i64>_as_Trait>::foo
441+
self.foo() // $ target=<S<i64>_as_Trait>::foo
442+
}
443+
444+
// <S<i64>_as_Trait>::bar
445+
fn bar(&self) {
446+
// `S::bar(self);` is not valid
447+
S::<i64>::bar(self); // $ target=<S<i64>_as_Trait>::bar
448+
self.bar() // $ target=<S<i64>_as_Trait>::bar
449+
}
450+
}
451+
}

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

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,6 +4012,70 @@ 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:408:16:408:20 | SelfParam | | {EXTERNAL LOCATION} | & |
4016+
| overloading.rs:408:16:408:20 | SelfParam | TRef | overloading.rs:407:5:410:5 | Self [trait Trait] |
4017+
| overloading.rs:409:16:409:20 | SelfParam | | {EXTERNAL LOCATION} | & |
4018+
| overloading.rs:409:16:409:20 | SelfParam | TRef | overloading.rs:407:5:410:5 | Self [trait Trait] |
4019+
| overloading.rs:414:16:414:16 | x | | {EXTERNAL LOCATION} | & |
4020+
| overloading.rs:414:16:414:16 | x | TRef | overloading.rs:405:5:405:19 | S |
4021+
| overloading.rs:414:16:414:16 | x | TRef.T | {EXTERNAL LOCATION} | i32 |
4022+
| overloading.rs:414:26:414:27 | { ... } | | {EXTERNAL LOCATION} | () |
4023+
| overloading.rs:417:16:417:20 | SelfParam | | {EXTERNAL LOCATION} | & |
4024+
| overloading.rs:417:16:417:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
4025+
| overloading.rs:417:16:417:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
4026+
| overloading.rs:417:23:417:24 | { ... } | | {EXTERNAL LOCATION} | () |
4027+
| overloading.rs:422:16:422:20 | SelfParam | | {EXTERNAL LOCATION} | & |
4028+
| overloading.rs:422:16:422:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
4029+
| overloading.rs:422:16:422:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
4030+
| overloading.rs:422:23:426:9 | { ... } | | {EXTERNAL LOCATION} | () |
4031+
| overloading.rs:423:13:423:24 | ...::foo(...) | | {EXTERNAL LOCATION} | () |
4032+
| overloading.rs:423:20:423:23 | self | | {EXTERNAL LOCATION} | & |
4033+
| overloading.rs:423:20:423:23 | self | TRef | overloading.rs:405:5:405:19 | S |
4034+
| overloading.rs:423:20:423:23 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
4035+
| overloading.rs:424:13:424:31 | ...::foo(...) | | {EXTERNAL LOCATION} | () |
4036+
| overloading.rs:424:27:424:30 | self | | {EXTERNAL LOCATION} | & |
4037+
| overloading.rs:424:27:424:30 | self | TRef | overloading.rs:405:5:405:19 | S |
4038+
| overloading.rs:424:27:424:30 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
4039+
| overloading.rs:425:13:425:16 | self | | {EXTERNAL LOCATION} | & |
4040+
| overloading.rs:425:13:425:16 | self | TRef | overloading.rs:405:5:405:19 | S |
4041+
| overloading.rs:425:13:425:16 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
4042+
| overloading.rs:429:16:429:20 | SelfParam | | {EXTERNAL LOCATION} | & |
4043+
| overloading.rs:429:16:429:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
4044+
| overloading.rs:429:16:429:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
4045+
| overloading.rs:429:23:433:9 | { ... } | | {EXTERNAL LOCATION} | () |
4046+
| overloading.rs:430:13:430:24 | ...::bar(...) | | {EXTERNAL LOCATION} | () |
4047+
| overloading.rs:430:20:430:23 | self | | {EXTERNAL LOCATION} | & |
4048+
| overloading.rs:430:20:430:23 | self | TRef | overloading.rs:405:5:405:19 | S |
4049+
| overloading.rs:430:20:430:23 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
4050+
| overloading.rs:431:13:431:31 | ...::bar(...) | | {EXTERNAL LOCATION} | () |
4051+
| overloading.rs:431:27:431:30 | self | | {EXTERNAL LOCATION} | & |
4052+
| overloading.rs:431:27:431:30 | self | TRef | overloading.rs:405:5:405:19 | S |
4053+
| overloading.rs:431:27:431:30 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
4054+
| overloading.rs:432:13:432:16 | self | | {EXTERNAL LOCATION} | & |
4055+
| overloading.rs:432:13:432:16 | self | TRef | overloading.rs:405:5:405:19 | S |
4056+
| overloading.rs:432:13:432:16 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
4057+
| overloading.rs:438:16:438:20 | SelfParam | | {EXTERNAL LOCATION} | & |
4058+
| overloading.rs:438:16:438:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
4059+
| overloading.rs:438:16:438:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i64 |
4060+
| overloading.rs:438:23:442:9 | { ... } | | {EXTERNAL LOCATION} | () |
4061+
| overloading.rs:440:13:440:31 | ...::foo(...) | | {EXTERNAL LOCATION} | () |
4062+
| overloading.rs:440:27:440:30 | self | | {EXTERNAL LOCATION} | & |
4063+
| overloading.rs:440:27:440:30 | self | TRef | overloading.rs:405:5:405:19 | S |
4064+
| overloading.rs:440:27:440:30 | self | TRef.T | {EXTERNAL LOCATION} | i64 |
4065+
| overloading.rs:441:13:441:16 | self | | {EXTERNAL LOCATION} | & |
4066+
| overloading.rs:441:13:441:16 | self | TRef | overloading.rs:405:5:405:19 | S |
4067+
| overloading.rs:441:13:441:16 | self | TRef.T | {EXTERNAL LOCATION} | i64 |
4068+
| overloading.rs:445:16:445:20 | SelfParam | | {EXTERNAL LOCATION} | & |
4069+
| overloading.rs:445:16:445:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
4070+
| overloading.rs:445:16:445:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i64 |
4071+
| overloading.rs:445:23:449:9 | { ... } | | {EXTERNAL LOCATION} | () |
4072+
| overloading.rs:447:13:447:31 | ...::bar(...) | | {EXTERNAL LOCATION} | () |
4073+
| overloading.rs:447:27:447:30 | self | | {EXTERNAL LOCATION} | & |
4074+
| overloading.rs:447:27:447:30 | self | TRef | overloading.rs:405:5:405:19 | S |
4075+
| overloading.rs:447:27:447:30 | self | TRef.T | {EXTERNAL LOCATION} | i64 |
4076+
| overloading.rs:448:13:448:16 | self | | {EXTERNAL LOCATION} | & |
4077+
| overloading.rs:448:13:448:16 | self | TRef | overloading.rs:405:5:405:19 | S |
4078+
| overloading.rs:448:13:448:16 | self | TRef.T | {EXTERNAL LOCATION} | i64 |
40154079
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
40164080
| pattern_matching.rs:13:26:133:1 | { ... } | T | {EXTERNAL LOCATION} | () |
40174081
| pattern_matching.rs:15:5:18:5 | if ... {...} | | {EXTERNAL LOCATION} | () |
@@ -12686,6 +12750,74 @@ inferType
1268612750
| overloading.rs:399:17:399:29 | ...::from(...) | | overloading.rs:372:5:372:14 | S1 |
1268712751
| overloading.rs:399:28:399:28 | s | | overloading.rs:364:5:365:13 | S |
1268812752
| overloading.rs:400:9:400:9 | x | | overloading.rs:372:5:372:14 | S1 |
12753+
| overloading.rs:408:16:408:20 | SelfParam | | {EXTERNAL LOCATION} | & |
12754+
| overloading.rs:408:16:408:20 | SelfParam | TRef | overloading.rs:407:5:410:5 | Self [trait Trait] |
12755+
| overloading.rs:409:16:409:20 | SelfParam | | {EXTERNAL LOCATION} | & |
12756+
| overloading.rs:409:16:409:20 | SelfParam | TRef | overloading.rs:407:5:410:5 | Self [trait Trait] |
12757+
| overloading.rs:414:16:414:16 | x | | {EXTERNAL LOCATION} | & |
12758+
| overloading.rs:414:16:414:16 | x | TRef | overloading.rs:405:5:405:19 | S |
12759+
| overloading.rs:414:16:414:16 | x | TRef.T | {EXTERNAL LOCATION} | i32 |
12760+
| overloading.rs:414:26:414:27 | { ... } | | {EXTERNAL LOCATION} | () |
12761+
| overloading.rs:417:16:417:20 | SelfParam | | {EXTERNAL LOCATION} | & |
12762+
| overloading.rs:417:16:417:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
12763+
| overloading.rs:417:16:417:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
12764+
| overloading.rs:417:23:417:24 | { ... } | | {EXTERNAL LOCATION} | () |
12765+
| overloading.rs:422:16:422:20 | SelfParam | | {EXTERNAL LOCATION} | & |
12766+
| overloading.rs:422:16:422:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
12767+
| overloading.rs:422:16:422:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
12768+
| overloading.rs:422:23:426:9 | { ... } | | {EXTERNAL LOCATION} | () |
12769+
| overloading.rs:423:13:423:24 | ...::foo(...) | | {EXTERNAL LOCATION} | () |
12770+
| overloading.rs:423:20:423:23 | self | | {EXTERNAL LOCATION} | & |
12771+
| overloading.rs:423:20:423:23 | self | TRef | overloading.rs:405:5:405:19 | S |
12772+
| overloading.rs:423:20:423:23 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
12773+
| overloading.rs:424:13:424:31 | ...::foo(...) | | {EXTERNAL LOCATION} | () |
12774+
| overloading.rs:424:27:424:30 | self | | {EXTERNAL LOCATION} | & |
12775+
| overloading.rs:424:27:424:30 | self | TRef | overloading.rs:405:5:405:19 | S |
12776+
| overloading.rs:424:27:424:30 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
12777+
| overloading.rs:425:13:425:16 | self | | {EXTERNAL LOCATION} | & |
12778+
| overloading.rs:425:13:425:16 | self | TRef | overloading.rs:405:5:405:19 | S |
12779+
| overloading.rs:425:13:425:16 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
12780+
| overloading.rs:425:13:425:22 | self.foo() | | {EXTERNAL LOCATION} | () |
12781+
| overloading.rs:429:16:429:20 | SelfParam | | {EXTERNAL LOCATION} | & |
12782+
| overloading.rs:429:16:429:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
12783+
| overloading.rs:429:16:429:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i32 |
12784+
| overloading.rs:429:23:433:9 | { ... } | | {EXTERNAL LOCATION} | () |
12785+
| overloading.rs:430:13:430:24 | ...::bar(...) | | {EXTERNAL LOCATION} | () |
12786+
| overloading.rs:430:20:430:23 | self | | {EXTERNAL LOCATION} | & |
12787+
| overloading.rs:430:20:430:23 | self | TRef | overloading.rs:405:5:405:19 | S |
12788+
| overloading.rs:430:20:430:23 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
12789+
| overloading.rs:431:13:431:31 | ...::bar(...) | | {EXTERNAL LOCATION} | () |
12790+
| overloading.rs:431:27:431:30 | self | | {EXTERNAL LOCATION} | & |
12791+
| overloading.rs:431:27:431:30 | self | TRef | overloading.rs:405:5:405:19 | S |
12792+
| overloading.rs:431:27:431:30 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
12793+
| overloading.rs:432:13:432:16 | self | | {EXTERNAL LOCATION} | & |
12794+
| overloading.rs:432:13:432:16 | self | TRef | overloading.rs:405:5:405:19 | S |
12795+
| overloading.rs:432:13:432:16 | self | TRef.T | {EXTERNAL LOCATION} | i32 |
12796+
| overloading.rs:432:13:432:22 | self.bar() | | {EXTERNAL LOCATION} | () |
12797+
| overloading.rs:438:16:438:20 | SelfParam | | {EXTERNAL LOCATION} | & |
12798+
| overloading.rs:438:16:438:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
12799+
| overloading.rs:438:16:438:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i64 |
12800+
| overloading.rs:438:23:442:9 | { ... } | | {EXTERNAL LOCATION} | () |
12801+
| overloading.rs:440:13:440:31 | ...::foo(...) | | {EXTERNAL LOCATION} | () |
12802+
| overloading.rs:440:27:440:30 | self | | {EXTERNAL LOCATION} | & |
12803+
| overloading.rs:440:27:440:30 | self | TRef | overloading.rs:405:5:405:19 | S |
12804+
| overloading.rs:440:27:440:30 | self | TRef.T | {EXTERNAL LOCATION} | i64 |
12805+
| overloading.rs:441:13:441:16 | self | | {EXTERNAL LOCATION} | & |
12806+
| overloading.rs:441:13:441:16 | self | TRef | overloading.rs:405:5:405:19 | S |
12807+
| overloading.rs:441:13:441:16 | self | TRef.T | {EXTERNAL LOCATION} | i64 |
12808+
| overloading.rs:441:13:441:22 | self.foo() | | {EXTERNAL LOCATION} | () |
12809+
| overloading.rs:445:16:445:20 | SelfParam | | {EXTERNAL LOCATION} | & |
12810+
| overloading.rs:445:16:445:20 | SelfParam | TRef | overloading.rs:405:5:405:19 | S |
12811+
| overloading.rs:445:16:445:20 | SelfParam | TRef.T | {EXTERNAL LOCATION} | i64 |
12812+
| overloading.rs:445:23:449:9 | { ... } | | {EXTERNAL LOCATION} | () |
12813+
| overloading.rs:447:13:447:31 | ...::bar(...) | | {EXTERNAL LOCATION} | () |
12814+
| overloading.rs:447:27:447:30 | self | | {EXTERNAL LOCATION} | & |
12815+
| overloading.rs:447:27:447:30 | self | TRef | overloading.rs:405:5:405:19 | S |
12816+
| overloading.rs:447:27:447:30 | self | TRef.T | {EXTERNAL LOCATION} | i64 |
12817+
| overloading.rs:448:13:448:16 | self | | {EXTERNAL LOCATION} | & |
12818+
| overloading.rs:448:13:448:16 | self | TRef | overloading.rs:405:5:405:19 | S |
12819+
| overloading.rs:448:13:448:16 | self | TRef.T | {EXTERNAL LOCATION} | i64 |
12820+
| overloading.rs:448:13:448:22 | self.bar() | | {EXTERNAL LOCATION} | () |
1268912821
| pattern_matching.rs:13:26:133:1 | { ... } | | {EXTERNAL LOCATION} | Option |
1269012822
| pattern_matching.rs:13:26:133:1 | { ... } | T | {EXTERNAL LOCATION} | () |
1269112823
| pattern_matching.rs:14:9:14:13 | value | | {EXTERNAL LOCATION} | Option |

0 commit comments

Comments
 (0)